django项目部署上线完整教程(ContenOS)

django项目上线完整教程

  • django项目上线完整教程(ContenOS)
    • 1、安装python
    • 2、安装mysql
    • 3、安装pip
    • 4、安装mysqlclient(连接器)
    • 5、安装uwsgi
    • 6、安装NGINX
    • 7、查看nginx和uwsgi进程(判断是否打开)
    • 8、开启或关闭nginx和uwsgi

django项目上线完整教程(ContenOS)

大家好!在这里给大家交流一下本人在ContenOS上部署django项目上线完整教程(ContenOS)!避开所有得坑,小编用这个20分钟就可以从0上线一个django项目,如果大家在上线时遇到任何问题,小编走过很多得坑了,欢迎交流,我会尽力帮助大家。

1、安装python

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测试,成功

2、安装mysql

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

3、安装pip

升级pip

python3.6 -m pip install --upgrade pip

安装django

python3.6 -m pip install django

4、安装mysqlclient(连接器)

python3.6 -m pip install mysqlclient

5、安装uwsgi

python3.6 -m pip install uwsgi

提示Successfully installed uwsgi-2.0.17成功

ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi

6、安装NGINX

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

7、查看nginx和uwsgi进程(判断是否打开)

check nginx process

ps -aux|grep nginx

check uwsgi process

ps -aux|grep uwsgi

8、开启或关闭nginx和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

就这样了,都看到这里了,点赞关注走一走吧,谢谢大家!

你可能感兴趣的:(centos,python,django,mysql)