ssh root@阿里云公网ip
执行:yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel
mysql-devel gcc gcc-devel python-devel 下载依赖包
下载3.6.5python环境:wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
解压环境压缩包:tar -zxvf Python-3.6.5.tgz
cd python-3.5.6
./configure
make
make install
./python 查询当前环境
./python -m venv /root/python3env
source python3env/bin/activate进入虚拟环境
在项目命令输入行中执行:pip freeze 之后执行 pip freeze > requirements.txt
另开cmder移动文件 执行:scp -r 项目路径 root@阿里云公网ip:/root/名字
原本的cmder中执行:pip install -r requirements.txt
pip install uwsgi
yum install nginx
vim django_uwsgi.ini
第一种配置方式
[uwsgi]
socket = :9000
chdir = /root/mysite
module = mysite.wsgi
master = true
processes = 3 开启cpu数量:cpu核数*2+1
vacuum = true
----------------------------------
第二中配置方式
[uwsgi]
socket = :9000
chdir = /root/mysite
wsgi-file = mysite/wsgi.py
master = true
prosesses = 3
vacuum = true
deamonize = /var/log/uwsgi/mysite.log
pidfile = /var/log/uwsgi/mysite.pid
mkdir /var/log/uwsgi
-----------------------------------
查看运行进程:ps -ef|grep nginx
设置supervisor 控制子进程自启动
pip install supervisor
cd /etc
mkdir supervisor
cd supervisor
echo_supervisor.conf > supervisor.conf
vim supervisor.conf
修改最后一行为 files = /etc/supervisor/conf.d/*.conf
mkdir conf.d
mkdir /var/log/supervisor
vim supervisord.conf
[inet_http_server]下的port改变0
lsof -i:端口:查看端口是否被占用
supervisord -c supervisord.conf
根目录下:cd /usr/lib/systemd/system
vim nginx.service 查看nginx服务的一些配置
cp nginx.service supervisor.service 将nginx.service里的内容复制到supervisor.service里(自己起的
名字)
ps -ef |grep supervis 查看进程,将进程的复制,/usr/bin/supervisord -c supervisord.conf
放到ExecStart后,并在supervisord.conf前添加路径
修改 supervisor.service文件
[Unit]
Description=Supervisor daemon
[Service]
Type=forking
PIDFile=/var/run/supervisor.pid
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorct1 shutdown
ExecReload=/usr/bin/supervisorct1 reload
KillMode=process
Restart=on-failure
RestartSec=40s
[Install]
WantedBy=multi-user.target
将supervisor进程重启, systemctl enable supervisor.service(设置开机自启)
systemctl disable supervisor.service(取消开机自启)
reboot 重启cmder
设置项目的配置文件,cd /etc/supervisor/conf.d
在虚拟环境的项目里 whereis uwsgi 查看uwsgi的路径(/root/python3env/bin/uwsgi),将路径放在最前边
/root/python3env/bin/uwsgi --ini /root/mysite/mysite_uwsgi.ini --buffer-size 30000
用绝对路径,然后运行,测试是否正常运行
vim mysite.conf
然后编辑mysite.conf文件
[program:mysite]
command = /root/python3env/bin/uwsgi --ini /root/mysite/mysite_uwsgi.ini --buffer-size 30000
directory = /root/mysite
# 将日志放在mysite_supervisor.log里
redirect_stderr = true
# 日志文件
stdout_logfile = /var/log/mysite_supervisor.log
supervisorctl (输入help,)
然后执行 update (更新文件)
重启 reboot
lsof -i:8090 查看在supervisor.cof的端口
并 kill -9 占用端口进程
然后 systenctl reload
最后再启动 supervisord -c supervisord.conf
还是不行就reboot 点击项目名称查看日志