Ubuntu部署Python项目;创建虚拟环境;supervisorctl使用
一个新的 Python 项目部署到 Ubuntu 上的过程
项目拉取到服务器里之后
root@w115:/home/salesgpt# python3 -m venv myenv The virtual environment was not created successfully because ensurepip is not available. On Debian/Ubuntu systems, you need to install the python3-venv package using the following command. apt install python3.10-venv You may need to use sudo with that command. After installing the python3-venv package, recreate your virtual environment. Failing command: /home/salesgpt/myenv/bin/python3
安装完成之后,继续:```python3 -m venv myenv```
切换至项目目录下:
启动虚拟环境:source myenv/bin/activate
关闭:deactivate
查看端口是否占用 ```netstat -tuln | grep 8001```
supervisord 配置(方式很多,自行根据自己习惯)
root@w115:/etc/supervisor# cat conf.d/salesgpt.conf [program:salesgpt] command=/usr/local/bin/uvicorn run_api:app --host 0.0.0.0 --port 8001 --workers=2 directory=/home/salesgpt autostart=false autorestart=false stderr_logfile=/home/salesgpt_logs/app.err.log stdout_logfile=/home/salesgpt_logs/app.out.log
情况二:
[program:salesgpt]
command=/home/salesgpt/myenv/bin/python3 /home/salesgpt/run_api.py --host 0.0.0.0 --port 8001 --workers=2
directory=/home/salesgpt
autostart=false
autorestart=false
stderr_logfile=/home/salesgpt_logs/app.err.log
stdout_logfile=/home/salesgpt_logs/app.out.log
environment=PATH="/home/salesgpt/myenv/bin",LANG="en_US.UTF-8",LC_ALL="en_US.UTF-8"
如何检测自己配置的对不对:
```supervisorctl stauts```
```supervisorctl stauts salesgpt```
启动命令,没有修改默认位置的话,建议在 ```/etc/supervisor``` 下执行
supervisorctl reload
sudo supervisorctl start salesgpt
sudo supervisorctl status