大家好!在这里给大家交流一下本人在ContenOS上部署django项目上线完整教程(ContenOS)!避开所有得坑,小编用这个20分钟就可以从0上线一个django项目,如果大家在上线时遇到任何问题,小编走过很多得坑了,欢迎交流,我会尽力帮助大家。
wget https://www.python.org/ftp/python/3.6.7/Python-3.6.7.tgz
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel
readline-devel tk-devel gcc make
tar xf Python-3.6.7.tgz
cd Python-3.6.7
./configure --prefix=/usr/local/python3/
make && make install
ln -s /usr/local/python3/bin/python3 /usr/bin/python3.6
输入python3.6 -V测试,成功
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-server
检查mysql是否安装成功。
rpm -qa | grep mysql
启动 mysql 服务 。
systemctl start mysqld.service #启动 mysql
systemctl restart mysqld.service #重启 mysql
systemctl stop mysqld.service #停止 mysql
systemctl enable mysqld.service #设置 mysql 开机启动
设置密码
mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD(“your password”) where User=‘root’;
mysql> flush privileges;
设置远程主机登录
GRANT ALL PRIVILEGES ON . TO root@’%’ IDENTIFIED BY ‘your password’ WITH GRANT OPTION;
mysql> GRANT ALL PRIVILEGES ON . TO ‘your username’@’%’ IDENTIFIED BY ‘your password’;
执行以下命令,为root 用户添加远程登录的能力。
mysql> GRANT ALL PRIVILEGES ON . TO root@"%" IDENTIFIED BY “your password”;
添加MySQL用户
mysql>useradd -g qi qi
升级pip
python3.6 -m pip install --upgrade pip
安装django
python3.6 -m pip install django
python3.6 -m pip install mysqlclient
python3.6 -m pip install uwsgi
提示Successfully installed uwsgi-2.0.17成功
ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi
yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
wget http://nginx.org/download/nginx-1.14.0.tar.gz
tar -zxvf nginx-1.14.0.tar.gz
cd到文件路径
简单安装
./configure --prefix=/usr/local/nginx
安装可能用到的依赖包
./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/tem/nginx/client --http-proxy-temp-path=/var/tem/nginx/proxy --http-fastcgi-temp-path=/var/tem/nginx/fcgi --with-http_stub_status_module
make && make install
启动
nginx -c /usr/local/nginx/conf/nginx.conf
如果出现[emerg] getpwnam(“nginx”) failed 错误 执行
useradd -s /sbin/nologin -M nginx
id nginx
如果出现 [emerg] mkdir() “/var/temp/nginx/client” failed (2: No such file or directory) 错误 执行
sudo mkdir -p /var/tem/nginx/client
如果您正在运行防火墙,请运行以下命令以允许HTTP和HTTPS通信:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
输入:
localhost
check nginx process
ps -aux|grep nginx
check uwsgi process
ps -aux|grep uwsgi
start uwsgi
uwsgi --ini /项目路径/uwsgi.ini
start nginx
/usr/local/nginx/sbin/nginx
restart nginx
/usr/local/nginx/sbin/nginx -s reload
stop nginx
/usr/local/nginx/sbin/nginx -s stop
中断nginx进程
pkill -9 nginx
中断uwsgi进程
killall -9 uwsgi
就这样了,都看到这里了,点赞关注走一走吧,谢谢大家!