1.安装git,并下载项目源码
pip install git
git clone 项目ssh地址
2.启动虚拟环境
cd imooc_env // imooc_end在家目录下 即~/imooc_env
source bin/activate
3.进入项目文件夹
cd /data/www/orderAll // cd进入自己的项目文件夹
4.安装项目所需库
pip install -r requirements.txt
5.启动单进程
export ops_config=local或production
python manager.py runserver
6.开启uwsgi实现多进程
关闭单进程runserver
ps -ef |grep python
kill -9 进程id
详情查看https://www.jianshu.com/p/d27f86dc7331
安装uwsgi requirements.txt已标注uwsgi可忽略
pip install uwsgi
配置uwsgi文件
[uwsgi]
#源码目录
chdir=/data/www/orderAll
#python 虚拟环境
home=/root/imooc_env
module=manager
callable=app
master=true
#进程数
processes=4
#host及端口
http=0.0.0.0:8999
#需先创建logs文件夹 mkdir /data/www/logs
socket=/data/www/logs/order.sock
buffer-size=65535
pidfile=/data/www/logs/order.pid
chmod-socket=777
logfile-chmod=644
daemonize=/data/www/logs/order.log
static-map = /static=/data/www/orderAll/web/static
开启
uwsgi --ini uwsgi.ini
查看是否启动进程
[root@VM_0_14_centos orderAll]# ps -ef |grep uwsgi
root 3925 3560 0 16:56 pts/3 00:00:00 grep --color=auto uwsgi
root 32129 1 0 16:18 ? 00:00:00 uwsgi --ini uwsgi.ini
root 32131 32129 0 16:18 ? 00:00:00 uwsgi --ini uwsgi.ini
root 32132 32129 0 16:18 ? 00:00:00 uwsgi --ini uwsgi.ini
root 32133 32129 0 16:18 ? 00:00:00 uwsgi --ini uwsgi.ini
root 32134 32129 0 16:18 ? 00:00:00 uwsgi --ini uwsgi.ini
root 32135 32129 0 16:18 ? 00:00:00 uwsgi --ini uwsgi.ini
杀死进程
kill -9 32129 //将4个进程都杀死
7.nginx代理
安装nginx
cd /tmp
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install nginx
配置conf.d
cd /etc/nginx
cd /conf.d
删除默认defualt.conf文件
sudo rm -r defualt.conf
创建新文件并配置内容
sudo touch order.conf
vim order.conf
server {
#监听80端口
listen 80 default_server;
#服务网址
server_name 网址;
#静态文件配置
location /static {
alias /data/www/orderAll/web/static/;
}
location / {
try_files $uri @yourapplication;
}
location @yourapplication {
include uwsgi_params;
uwsgi_pass unix:/data/www/logs/order.sock;
}
}
sudo service nginx start #已开启使用sudo service nginx reload
检查配置
nginx -c /etc/nginx/nginx.conf
网友评论