1. 查询Python和Centos版本
python -V
cat /etc/centos-release
2. 上传源码到应用发布目录
打开XFTP上传就行
3. 安装pip
yum install python3-pip
4. 通过pip安装虚拟环境
pip3 install virtualenv
5. 到需要的目录创建虚拟环境
cd /data/clearAccount/
virtualenv myenv
6. 进入虚拟空间
source myenv/bin/activate
7. 安装依赖库
pip install -r requirements.txt
8. 安装WSGI HTTP 服务器(gunicorn)
pip install gunicorn
配置gunicorn系统服务
vim /etc/systemd/system/gunicorn.service
添加下面的内容
[Unit]
Description=Gunicorn
After=network.target
[Service]
User=root
Group=root
WorkingDirectory=/data/clearAccount
#Gunicorn 执行路径(虚拟环境 myenv 中的 gunicorn)
ExecStart=/data/clearAccount/myenv/bin/gunicorn -w 4 -b 0.0.0.0:8000 app:app
Restart=always
[Install]
WantedBy=multi-user.target
管理gunicorn服务命令
# reload守护进程
systemctl daemon-reload
# 服务自启动
systemctl enable gunicorn
# 启动服务
systemctl start gunicorn
# 查看服务状态
systemctl status gunicorn
# 停服务
systemctl stop gunicorn.service
9. 反向代理服务(nginx)
安装nginx
yum install nginx
修改nginx配置文件
vim /etc/nginx/nginx.conf
添加nginx配置内容
server {
listen 8080;
listen [::]:8080;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
# 静态文件路径(指向项目的 static 目录)
location /static {
alias /data/clearAccount/static;
}
# 动态请求转发给 Gunicorn
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
检查nginx配置文件
nginx -t
重启nginx服务
systemctl restart nginx
验证8080端口是否通
telnet 127.0.0.1 8080
#如果Telnet没有安装,请安装,命令如下:
yum install telnet
nginx其他命令
#重载nginx
systemctl restart nginx.service
#查看nginx状态
systemctl status nginx.service
#停止nginx
systemctl stopnginx.service
10. 防火墙策略(firewalld)
#查看防火墙状态,如果没有启用,就不管了,启用的话,放开8080端口
systemctl status firewalld.service
#放开8080端口
firewall-cmd --zone=public --add-port=8080/tcp --permanent
#重载firewalld
firewall-cmd --reload
11. 检查文件和目录权限
在前端调用后台的脚本去执行,需要给后台脚本执行权限
chmod 755 /data/clearAccount/scripts/test.sh

被折叠的 条评论
为什么被折叠?



