跳转至

服务部署

部署方式

方式一:直接部署

# 进入项目目录
cd /home/ubuntu/bioinfo-system-new

# 激活虚拟环境
source .venv/bin/activate

# 前台运行(开发)
python -m uvicorn main:app --reload --host 0.0.0.0 --port 8000

# 后台运行(生产)
nohup python -m uvicorn main:app \
  --host 0.0.0.0 --port 8000 \
  --workers 4 \
  --log-level info \
  > logs/server.log 2>&1 &

echo $! > logs/server.pid

方式二:Systemd 服务

创建服务文件 /etc/systemd/system/bioinfo.service:

[Unit]
Description=Bioinfo System
After=network.target

[Service]
User=ubuntu
WorkingDirectory=/home/ubuntu/bioinfo-system-new
ExecStart=/home/ubuntu/bioinfo-system-new/.venv/bin/python -m uvicorn main:app --host 0.0.0.0 --port 8000
Restart=always
RestartSec=5
Environment="PATH=/home/ubuntu/bioinfo-system-new/.venv/bin"

[Install]
WantedBy=multi-user.target

启用服务:

sudo systemctl daemon-reload
sudo systemctl enable bioinfo
sudo systemctl start bioinfo
sudo systemctl status bioinfo

方式三:Docker 部署

# 构建镜像
docker build -t bioinfo-system .

# 运行容器
docker run -d \
  --name bioinfo \
  -p 8000:8000 \
  -v ./data:/app/data \
  -v ./logs:/app/logs \
  bioinfo-system

Nginx 反向代理

server {
    listen 80;
    server_name bioinfo.example.com;

    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        # WebSocket 支持
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

环境变量配置

创建 .env 文件:

# JWT配置
JWT_SECRET_KEY=your-secret-key-here
JWT_ALGORITHM=HS256
JWT_EXPIRE_MINUTES=60

# LLM配置
OLLAMA_HOST=http://localhost:11434
LLM_MODEL=qwen3.5:9b
MINIMAX_API_KEY=your-api-key
MINIMAX_MODEL=minimaxi-01

# 数据库配置
DATABASE_URL=sqlite:///./data/bioinfo.db
# 或 PostgreSQL
# DATABASE_URL=postgresql://user:pass@localhost:5432/bioinfo

# 文件存储
UPLOAD_DIR=/home/ubuntu/bioinfo-system-new/data/uploads
MAX_FILE_SIZE=52428800

# 飞书集成
FEISHU_APP_ID=your_app_id
FEISHU_APP_SECRET=your_secret

# 安全设置
RATE_LIMIT_REQUESTS=100
RATE_LIMIT_WINDOW=60
CORS_ORIGINS=http://localhost:*,https://*.example.com

防火墙配置

# 开放端口(仅内网)
sudo ufw allow from 192.168.0.0/16 to any port 8000

# 或使用 iptables
sudo iptables -A INPUT -p tcp -s 192.168.0.0/16 --dport 8000 -j ACCEPT

服务管理命令

操作 命令
启动 sudo systemctl start bioinfo
停止 sudo systemctl stop bioinfo
重启 sudo systemctl restart bioinfo
状态 sudo systemctl status bioinfo
日志 journalctl -u bioinfo -f

返回运维手册