Flask环境搭建(Centos9+Python3.9)

部署运行你感兴趣的模型镜像

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

您可能感兴趣的与本文相关的镜像

Python3.11

Python3.11

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值