← 返回首页

内存不足导致崩溃

VPS 内存太小,OpenClaw 运行一段时间后 OOM

❌ 常见错误
# 错误1: OOM Killed
Killed - memory limit exceeded

# 错误2: JavaScript heap out of memory
FATAL ERROR: Reached heap limit Allocation failed

# 错误3: 系统内存不足
Out of memory: Kill process

解决方案

方案一:创建 Swap 虚拟内存(推荐)

如果服务器内存小于 2GB,建议创建 Swap:

# 创建 2GB Swap 文件
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

# 开机自动启用
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

# 验证
free -h

方案二:增加物理内存

如果经常 OOM,建议升级服务器配置:

方案三:限制 Node.js 内存

在启动命令中限制内存使用:

# 限制最大内存为 1gb
NODE_OPTIONS="--max-old-space-size=1024" openclaw start

方案四:使用 Docker 限制内存

docker run -d \
  --name openclaw \
  --memory=1g \
  --memory-swap=1g \
  -p 18789:18789 \
  openclaw/openclaw:latest

检查内存使用

# 查看内存使用
free -h

# 实时监控
htop

# 或
docker stats openclaw

服务器推荐配置

用途 推荐内存 月费用
测试 1-2GB ¥20-40
日常使用 4GB ¥60-80
重度使用 8GB+ ¥150+