django2.2.4项目 部署 centos7.3 环境, tomcat与nginx相互切换

更新一篇如何将 django2.2.4项目 部署 centos7.3 环境的博客

大致细节参考这篇文章,过程中会遇到以下问题
将django部署到服务器详细过程

uwsgi -x 命令报错, 在没有安装,相关依赖包时会报错,
nginx 配置文件出错会报错

启动项目前进入虚拟环境

[root@iZips92kqeqhgjZ ~]# cd /data/env/pyweb/bin
[root@iZips92kqeqhgjZ bin]# source activate
(pyweb) [root@iZips92kqeqhgjZ bin]# 

出现pyweb 说明加载 python虚拟环境成功。

修改setting
修改ALLOWED_HOSTS,[’*’],可以让任何IP访问
进入django项目目录

编写uwsgi 配置文件,并激活

   cd /data/wwwroot/Logistics
      vi /data/wwwroot/Logistics/Logistics.xml
      uwsgi -x Logistics.xml

编写nginx配置文件

cd /usr/local/nginx/conf/
vi nginx.conf

测试nginx配置文件,并启动nginx,以及停止与重新启动

(pyweb) [root@iZips92kqeqhgjZ conf]# cd /usr/local/nginx/sbin
#退出
(pyweb) [root@iZips92kqeqhgjZ sbin]# ./nginx -s quit
#检测配置文件语法,以及是否成功
(pyweb) [root@iZips92kqeqhgjZ sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
#正常启动不会有任何提示
(pyweb) [root@iZips92kqeqhgjZ sbin]# ./nginx

#重启,当项目文件更新时,需要重新启动nginx 以及 uwsgi
#重新生效 项目的 xml配置文件

(pyweb) [root@iZips92kqeqhgjZ sbin]#   cd /data/wwwroot/Logistics
(pyweb) [root@iZips92kqeqhgjZ Logistics]#      uwsgi -x Logistics.xml
[uWSGI] parsing config file Logistics.xml
(pyweb) [root@iZips92kqeqhgjZ conf]# cd /usr/local/nginx/sbin
(pyweb) [root@iZips92kqeqhgjZ sbin]# ./nginx -s reload

关于数据库迁移

#导出Mysql,django为你的数据库
mysqldump -uroot -ppassword django_1>django_1.sql
#把django.sql上传到服务器,在服务器里用下面命令导入
mysql -uroot -p;
create database django_1;
use dajngo_1;
source your Path\django_1.sql

停止tomcat与启动tomcat
停止与启动nginx

(pyweb) [root@iZips92kqeqhgjZ home]# sh /home/tomcat/apache-tomcat-9.0.21/bin/shutdown.sh
[root@iZips92kqeqhgjZ home]# sh /home/tomcat/apache-tomcat-9.0.21/bin/startup.sh
#启动nginx
(pyweb) [root@iZips92kqeqhgjZ home]# /usr/local/nginx/sbin/nginx
(pyweb) [root@iZips92kqeqhgjZ home]# /usr/local/nginx/sbin/nginx -s quit

#更新项目资源

   #查看Uwsgi进程
(pyweb) [root@iZips92kqeqhgjZ bin]# ps -ef|grep uwsgi 
root      4201     1  0 Sep01 ?        00:00:03 uwsgi -x Logistics.xml
root      4217  4201  0 Sep01 ?        00:00:13 uwsgi -x Logistics.xml
    #用kill方法把uwsgi进程杀死,然后启动uwsgi
(pyweb) [root@iZips92kqeqhgjZ bin]# killall -9 uwsgi
    #启动方法
        (pyweb) [root@iZips92kqeqhgjZ home]# uwsgi -x /data/wwwroot/Logistics/Logistics.xml
        (pyweb) [root@iZips92kqeqhgjZ home]# /usr/local/nginx/sbin/nginx  -s reload
        killall -9 uwsgi
        uwsgi -x /data/wwwroot/Logistics/Logistics.xml
        /usr/local/nginx/sbin/nginx  -s reload
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yuemake999

请我喝茶呗

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值