104 lines
1.8 KiB
Markdown
104 lines
1.8 KiB
Markdown
# README-DEPLOY
|
||
|
||
仅保留部署命令,按顺序执行。
|
||
|
||
## 1. 首次部署(服务器)
|
||
|
||
```bash
|
||
cd /www/wwwroot
|
||
git clone <your_repo_url> inventory
|
||
cd inventory
|
||
python3 -m venv venv
|
||
source venv/bin/activate
|
||
pip install -r requirements.txt
|
||
python init_db.py
|
||
```
|
||
|
||
## 2. 启动(临时测试)
|
||
|
||
```bash
|
||
cd /www/wwwroot/inventory
|
||
source venv/bin/activate
|
||
python app.py
|
||
```
|
||
|
||
访问:`http://127.0.0.1:5000`
|
||
|
||
## 3. 生产启动(Gunicorn)
|
||
|
||
先安装:
|
||
|
||
```bash
|
||
cd /www/wwwroot/inventory
|
||
source venv/bin/activate
|
||
pip install gunicorn
|
||
```
|
||
|
||
启动:
|
||
|
||
```bash
|
||
cd /www/wwwroot/inventory
|
||
source venv/bin/activate
|
||
gunicorn -w 2 -b 127.0.0.1:5000 app:app
|
||
```
|
||
|
||
说明:建议只监听 `127.0.0.1`,由 Nginx/宝塔反向代理。
|
||
|
||
## 4. 生产环境变量(建议)
|
||
|
||
登录认证默认开启,建议在生产环境显式设置管理员账号和会话密钥:
|
||
|
||
```bash
|
||
export INVENTORY_ADMIN_USERNAME="your_admin"
|
||
export INVENTORY_ADMIN_PASSWORD="your_strong_password"
|
||
export INVENTORY_SECRET_KEY="replace_with_random_long_secret"
|
||
```
|
||
|
||
## 5. 每次发布更新
|
||
|
||
### 本地
|
||
|
||
```bash
|
||
cd C:/Users/BeihongWang/Desktop/inventory
|
||
git add .
|
||
git commit -m "feat: your change"
|
||
git push origin main
|
||
```
|
||
|
||
### 服务器
|
||
|
||
```bash
|
||
cd /www/wwwroot/inventory
|
||
git pull origin main
|
||
source venv/bin/activate
|
||
pip install -r requirements.txt
|
||
```
|
||
|
||
然后在宝塔中重启 Python 项目(或重启 Gunicorn 进程)。
|
||
|
||
## 6. 数据库备份
|
||
|
||
```bash
|
||
cp /www/wwwroot/inventory/data/inventory.db /www/backup/inventory_$(date +%F).db
|
||
```
|
||
|
||
## 7. 快速排查
|
||
|
||
查看服务端口是否监听:
|
||
|
||
```bash
|
||
ss -lntp | grep 5000
|
||
```
|
||
|
||
本机探活:
|
||
|
||
```bash
|
||
curl http://127.0.0.1:5000
|
||
```
|
||
|
||
若域名打不开,优先检查:
|
||
|
||
1. Python 项目是否运行中
|
||
2. 域名解析是否生效
|
||
3. Nginx/宝塔反向代理是否指向 `127.0.0.1:5000`
|