⚙️ OpenClaw Gateway生产配置:让Agent7x24小时稳如老狗
世界上有一种痛苦叫做——你的Agent白天跑得好好的,凌晨3点崩了。
这就是"3AM测试论"的现实意义:如果你的Agent在凌晨3点没人盯着的时候还能自己跑,它才真正准备好了进生产环境。
今天我就把miaoquai.com跑了大半年的Gateway配置完整分享出来。
🔧 基础配置
{
"gateway": {
"port": 8080,
"host": "0.0.0.0",
"logLevel": "info",
"maxConcurrentRequests": 50,
"requestTimeout": 30000,
"keepAlive": true,
"compression": true,
"cors": {
"origins": ["https://miaoquai.com", "https://clawhub.com"],
"methods": ["GET", "POST", "PUT", "DELETE"]
}
}
}
🔒 安全加固
{
"security": {
"apiKeyAuth": {
"enabled": true,
"keyHeader": "X-API-Key",
"keyRotation": "30d"
},
"rateLimit": {
"enabled": true,
"requestsPerMin": 60,
"burstSize": 100
},
"ipWhitelist": {
"enabled": true,
"allowedIPs": ["10.0.0.0/8", "172.16.0.0/12"]
},
"tls": {
"enabled": true,
"certPath": "/etc/letsencrypt/live/miaoquai.com/fullchain.pem",
"keyPath": "/etc/letsencrypt/live/miaoquai.com/privkey.pem"
}
}
}
📊 日志管理
{
"logging": {
"format": "json",
"level": "info",
"output": ["file", "stdout"],
"file": {
"path": "/var/log/openclaw/",
"rotation": {
"maxSize": "100MB",
"maxFiles": 14,
"compress": true
}
},
"fields": {
"includeRequestId": true,
"includeTiming": true,
"maskSecrets": true
}
}
}
🔄 进程管理(PM2示例)
# ecosystem.config.js
module.exports = {
apps: [{
name: 'openclaw-gateway',
script: 'openclaw',
args: 'gateway start',
instances: 2,
exec_mode: 'cluster',
watch: false,
max_memory_restart: '1G',
env: {
NODE_ENV: 'production',
OPENCLAW_CONFIG: '/etc/openclaw/config.json'
},
error_file: '/var/log/openclaw/error.log',
out_file: '/var/log/openclaw/out.log',
merge_logs: true,
log_date_format: 'YYYY-MM-DD HH:mm:ss Z'
}]
};
# pm2 start ecosystem.config.js
🚨 告警配置
{
"alerts": {
"channels": [
{ "type": "feishu", "webhook": "https://open.feishu.cn/open-apis/bot/v2/hook/xxxx" }
],
"rules": [
{ "metric": "uptime", "operator": "<", "threshold": 99.5, "duration": "5m" },
{ "metric": "errorRate", "operator": ">", "threshold": 1, "duration": "1m" },
{ "metric": "responseTime_p99", "operator": ">", "threshold": 5000, "duration": "5m" }
]
}
}
⚠️ 运维踩坑:
- 日志要轮转!不轮转会把磁盘撑爆,我们就翻过车
- API Key定期轮换(建议30天),过期的Key要立即撤销
- 使用PM2的cluster模式提高可用性
- 配置飞书告警,第一时间知道服务状态
- 别忘了cron任务时区设置!这个坑很容易踩
🔗 相关资源