litellm-gateway/docs/DEPLOYMENT.md

164 lines
2.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 部署指南
## 目标节点
**OMV (Open Media Vault) on NAS / Proxmox**
推荐直接跑在 Nas 上,不强制 Docker直接 Python 运行。
---
## 步骤 1 — 环境准备
### 检查 Python 版本
```bash
python3 --version # 需要 >= 3.9
```
### 创建用户(可选,推荐)
```bash
useradd -m -s /bin/bash litellm
su - litellm
mkdir -p ~/litellm-gateway
```
---
## 步骤 2 — 安装依赖
```bash
pip install litellm
```
可选:
```bash
pip install uvicorn[standard] # ASGI 服务器(生产推荐)
```
---
## 步骤 3 — 配置
```bash
cd ~/litellm-gateway
# 复制环境变量模板
cp .env.example .env
# 编辑 .env填入真实值
nano .env
```
**必须设置的值:**
- `MINIMAX_API_KEY` — MiniMax 真实 API Key
- `LITELLM_MASTER_KEY` — 管理员 key`sk-` 开头)
---
## 步骤 4 — 启动
```bash
chmod +x run.sh
./run.sh
```
**后台运行(生产):**
```bash
# nohup
nohup ./run.sh > logs/litellm.log 2>&1 &
# 或用 systemd见下方
```
---
## 步骤 5 — 验证
```bash
# 健康检查
curl http://localhost:4000/health
# 测试 chat completions
curl -X POST http://localhost:4000/v1/chat/completions \
-H "Authorization: Bearer sk-your-master-key" \
-H "Content-Type: application/json" \
-d '{
"model": "MiniMax-M2.7",
"messages": [{"role": "user", "content": "Hello"}]
}'
```
---
## 步骤 6 — OpenClaw 接入
`~/.openclaw/openclaw.json` 中修改 MiniMax provider
```json
{
"providers": {
"minimax": {
"apiKey": "sk-your-minimax-api-key"
},
"minimax-portal": {
"apiKey": "sk-your-litellm-key",
"baseURL": "http://<your-server>:4000/v1"
}
}
}
```
> ⚠️ 注意LiteLLM 使用 OpenAI 兼容接口,所以 OpenClaw 的 `minimax-portal` provider 可以直接指向 LiteLLM 的 `/v1` 端点。
---
## systemd 服务OMV 持久化)
```ini
# /etc/systemd/system/litellm.service
[Unit]
Description=LiteLLM Gateway
After=network.target
[Service]
Type=simple
User=litellm
WorkingDirectory=/home/litellm/litellm-gateway
ExecStart=/home/litellm/litellm-gateway/run.sh
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
```
```bash
sudo systemctl daemon-reload
sudo systemctl enable litellm
sudo systemctl start litellm
```
---
## 网络访问控制
### 仅内网访问(推荐)
确保 LiteLLM 的端口 `:4000` 不暴露到公网。
### Tailscale / ZeroTier 组网(推荐)
```bash
# 在服务器上安装 Tailscale
curl -fsSL https://tailscale.com/install.sh | sh
tailscale up --accept-routes
# OpenClaw 节点也加入同一网络
# 然后 LiteLLM 只监听 Tailscale IP如 100.64.x.x:4000
```
### 防火墙规则OMV
```bash
# 只允许内网段访问 4000
iptables -A INPUT -p tcp -s 192.168.1.0/24 --dport 4000 -j ACCEPT
iptables -A INPUT -p tcp --dport 4000 -j DROP
```