Centos部署项目

前端之家收集整理的这篇文章主要介绍了Centos部署项目前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Nginx + virtualenv + uwsgi + django + MysqL + supervisor 部署项目

一、安装Python3

二、安装MariaDB,并授权远程

grant all privileges on *.* to [email protected]% identified byMysqL密码; 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:通过交互式启动

[[email protected] 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

猜你在找的CentOS相关文章