nginx + virtualenv + uwsgi + django + mysql + supervisor 部署项目

一、安装Python3

二、安装MariaDB,并授权远程

grant all privileges on *.* to root@'%' identified by'mysql密码';
flush privileges;

三、导出数据库

mysqldump --databases -uroot -p crmproject > MyCRM.dump

四、使用xftp或者winSCP传入项目和数据库

五、导入数据库

mysql -uroot -p < /opt/MyCRM.dump

六、修改项目的settings.py文件

ALLOWED_HOSTS = ['*']
STATIC_ROOT = '/opt/static' 数据库的连接配置

七、在虚拟环境里安装安装uwsgi

pip3 install uwsgi

八、使用uwsgi启动项目

方式1:直接输入命令启动

uwsgi --http :8000 --module CRMProject.wsgi

# --module 指定项目文件夹路径

方式2:使用ini配置文件启动

vim uwsgi.ini

'''
配置文件如下 [uwsgi]
# Django-related settings # the base directory (full path)
# 项目的绝对路径
chdir = /opt/CRMProject # Django's wsgi file
# 项目中根据chdir找到wsgi.py文件
module = CRMProject.wsgi # the virtualenv (full path)
# 虚拟环境的绝对路径
home = /root/Envs/MyCRM # process-related settings
# master
# 主进程
master = true # maximum number of worker processes
# 子进程数
processes = 1 # the socket (use the full path to be safe
#使用nginx反向代理,填写socket连接
socket = 0.0.0.0:8000 # 直接使用uwsgi运行http服务,使用http连接
#http = 0.0.0.0:8000
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true # 热启动时间设置
py-autoreload=1 '''
# 将每1秒检查python模块更改并最终重新启动实例
uwsgi --ini uwsgi.ini

现阶段能通过IP:8000访问项目,但是目的是通过80端口访问

九、修改nginx配置

vim nginx/conf/nginx.conf

'''配置如下'''
server {
listen 80;
server_name 192.168.11.59; location / {
include uwsgi_params;
uwsgi_pass 0.0.0.0:8000;
}
location /static {
alias /opt/static;
}
}
# 收集配置文件(在项目的虚拟环境下)
python3 manage.py collectstatic

重启nginx,此时启动nginx和通过uwsgi启动项目即能正常访问

十、使用supervisor管理

1.安装

###  使用python2环境安装
### 使用python2环境安装
### 使用python2环境安装 yum install python-setuptools
easy_install supervisor

2.通过命令生成supervisor的生成配置文件

echo_supervisord_conf > /etc/supervisor.conf

3.修改配置文件

# 在文件末尾添加

[program:crm]
command=/root/Envs/MyCRM/bin/uwsgi --ini /opt/CRMProject/uwsgi.ini
stopasgroup=true
killasgroup=true # program 指定项目名称
# command 启动程序的命令,一定要绝对路径
#stopasgroup=false 默认为false,进程被杀死时,是否向这个进程组发送stop信号,包括子进程
#killasgroup=false 默认为false,向进程组发送kill信号,包括子进程

4.启动supervisor

supervisord -c /etc/supervisor.conf

5.使用supervisor启动和管理项目

方式1:通过交互式启动

[root@localhost opt]# supervisorctl -c /etc/supervisor.conf
crm RUNNING pid 3752, uptime 0:40:52
supervisor> start/stop/restart/status 项目名
start/stop/restart/status all

方式2:通过参数直接启动

supervisorctl -c /etc/supervisor.conf start all

最新文章

  1. js获取可视区域高度
  2. 关于QImage提取单色通道方法(vector)
  3. SSIS Design4: 处理外键
  4. linux中文件(档案)和目录的RWX权限意义
  5. winform修改、打开窗体、构造函数传值
  6. CSS学习总结(三)
  7. freeswitch 1.4
  8. 傅里叶变换 fft_generic halcon
  9. linux c 验证登录密码
  10. preventDefault()、stopPropagation()、return false 之间的区别
  11. Java项目中基于Hibernate分页总结
  12. SVN 使用的简单整理
  13. 【Spring源码分析】AOP源码解析(下篇)
  14. 删数方案数(regex)
  15. 数据包接收系列 — NAPI的原理和实现
  16. Ubuntu忘记密码后强制修改密码
  17. filter 过滤器的基本使用
  18. 使用docker搭建数据分析环境
  19. The.Glory.of.Innovation 创新之路2科学基石
  20. kbmMW 5.08.10试用报告

热门文章

  1. [LeetCode] 245. Shortest Word Distance III 最短单词距离 III
  2. [LeetCode] 680. Valid Palindrome II 验证回文字符串 II
  3. 托马斯&#183;贝叶斯 (Thomas Bayes)
  4. java开发异常Exception集锦
  5. win10安装网络适配器
  6. 九、Spring中使用@Value和@PropertySource为属性赋值
  7. Synchronized实现原理及和Lock的区别
  8. 《Mysql - 自增主键为何不是连续的?》
  9. PMBOK(第六版) PMP备考知识总汇!
  10. Jenkins+Git+Maven+Tomcat详细安装步骤