page contents

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

项目部署

1、安装python

wget https://www.python.org/ftp/python/3.7.10/Python-3.7.10.tgz


yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel


readline-devel tk-devel gcc make


tar xf Python-3.7.10.tgz


cd Python-3.7.10

./configure --prefix=/usr/local/python3/


make && make install


ln -s /usr/local/python3/bin/python3 /usr/bin/python3.7


输入python3.7 -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.7 -m pip install --upgrade pip


安装django


python3.7 -m pip install django


4、安装mysqlclient(连接器)

python3.7 -m pip install mysqlclient


5、安装uwsgi

python3.7 -m pip install uwsgi


提示Successfully installed uwsgi 成功


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.18.0.tar.gz


tar -zxvf nginx-1.18.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

  • 发表于 2021-03-23 19:28
  • 阅读 ( 856 )
  • 分类:Python开发

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论

作家榜 »

  1. 轩辕小不懂 2403 文章
  2. 小柒 1470 文章
  3. Pack 1135 文章
  4. Nen 576 文章
  5. 王昭君 209 文章
  6. 文双 71 文章
  7. 小威 64 文章
  8. Cara 36 文章