pyhton⇒linux部署方法
1.·从git上拷贝,保持到本地helloword目录
git clone https://xxx.git
2.必要的时候修改配置文件,删除不需要的文件
3.用7zp工具将文件压缩成helloword.tar.gz文件
4.用winscp将helloword.tar.gz文件,放置在liunx上指定的工作目录中,例如/app
5.登录tera Term,用下面命令确认状况。
ls -altr
6.切换到工作目录,然后解压helloword.tar.gz文件,并且确认状况。
cd /app;tar -zxvf helloword.tar.gz;ls -altr
7.用requirements.txt下载必要的库到指定目录dependencies
pip download -d dependencies -r requirements.txt
8.用7zp工具将目录dependencies压缩成dependencies.tar.gz文件
9.用winscp将dependencies.tar.gz文件,放置在liunx上指定的工作目录中,例如/app
10.登录tera Term,用下面命令确认状况。
ls -altr
11.切换到工作目录,然后解压dependencies.tar.gz文件,并且确认状况。
cd /app;tar -zxvf dependencies.tar.gz;ls -altr
12.用requirements.txt和下载的依赖包安装库
pip install --no-index --find-links=dependencies -r requirements.txt
13.虚拟环境做成
python3 -m venv .venv;ls -altr
14.激活虚拟环境
source .venv/bin/activate
15.做成sh文件/app/helloword/helloword.sh(以fastapi为例)
#!/bin/bash AP_HOME=/app/helloworld UVICORN_LOG=/var/log/helloword/uvicorn.log #uvicorn start source ${AP_HOME}/.venv/bin/activate nohup ${AP_HOME}/.venv/bin/uvicorn app.main:app --reload --host=0.0.0.0 --port=8000 >> ${UVICORN_LOG} 2>&1 &
16.systemd执行用的Unit定义文件做成
/etc/systemd/system/helloworld.service
[Unit] Description =helloworld After=network.target [Service] User=a Group=b WorkingDirectory=/app/helloworld ExecStart = /app/helloworld/helloworld.sh Type = forking Restart=always [Install] WantedBy = multi-user.target
17.确认systemd是否作为service
systemctl list-unit-files --type=service |grep helloworld
18.service启动,停止
systemctl status helloworld
sytemctl stop helloworld
sytemctl start helloworld
19.修改apche配置文件/etc/httpd/conf/httpd.conf
KeepAlive Off
MaxKeepAliveRequests 100
KeepAliveTimeout 120
Timeout 7800
User a
Group b
ProxyPass /app/helloworld htp://localhost:8000/helloworld ProxyPassReverse /app/helloworld htp://localhost:8000/helloworld
20.·apache启动,停止
systemctl status httpd
sytemctl stop httpd
sytemctl start httpd
本文来自博客园,作者:我为P狂,转载请注明原文链接:https://www.cnblogs.com/lzqdiy/articles/17781768.html

浙公网安备 33010602011771号