直接启动(使用默认配置)

openclaw openclaw官方 2

OpenClaw Gateway 启动命令教程

OpenClaw Gateway 是一个网络代理/网关服务,以下是其启动命令的详细说明:

直接启动(使用默认配置)-第1张图片-OpenClaw开源下载|官方OpenClaw下载

基本启动命令


# 指定配置文件启动
openclaw-gateway -c config.yaml
openclaw-gateway --config /path/to/config.yml
# 前台运行(不守护进程)
openclaw-gateway -f
openclaw-gateway --foreground

常用参数选项

# 指定监听端口(覆盖配置文件中的设置)
openclaw-gateway -p 8080
openclaw-gateway --port 8080
# 指定工作目录
openclaw-gateway --workdir /var/lib/openclaw
# 指定日志文件
openclaw-gateway --log /var/log/openclaw.log
openclaw-gateway --log-level debug  # 日志级别:debug, info, warn, error
# 指定PID文件
openclaw-gateway --pidfile /var/run/openclaw.pid
# 显示版本信息
openclaw-gateway -v
openclaw-gateway --version
# 显示帮助信息
openclaw-gateway -h
openclaw-gateway --help

完整启动示例

# 示例1:完整参数启动
openclaw-gateway \
  --config /etc/openclaw/config.yaml \
  --port 8443 \
  --log /var/log/openclaw/gateway.log \
  --log-level info \
  --pidfile /var/run/openclaw.pid \
  --foreground
# 示例2:开发环境调试启动
openclaw-gateway \
  -c dev-config.yaml \
  --log-level debug \
  --foreground

系统服务管理方式

使用 systemd(推荐)

# 创建服务文件
sudo nano /etc/systemd/system/openclaw-gateway.service
[Unit]
Description=OpenClaw Gateway Service
After=network.target
[Service]
Type=simple
User=openclaw
Group=openclaw
WorkingDirectory=/opt/openclaw
ExecStart=/usr/local/bin/openclaw-gateway \
          --config /etc/openclaw/config.yaml \
          --log /var/log/openclaw/gateway.log
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target

启动服务:

# 重载systemd配置
sudo systemctl daemon-reload
# 启动服务
sudo systemctl start openclaw-gateway
# 设置开机自启
sudo systemctl enable openclaw-gateway
# 查看状态
sudo systemctl status openclaw-gateway
# 查看日志
sudo journalctl -u openclaw-gateway -f

使用 Supervisor

[program:openclaw-gateway]
command=/usr/local/bin/openclaw-gateway --config /etc/openclaw/config.yaml
directory=/opt/openclaw
user=openclaw
autostart=true
autorestart=true
stderr_logfile=/var/log/openclaw/error.log
stdout_logfile=/var/log/openclaw/out.log

Docker 容器运行

# 使用Docker运行
docker run -d \
  --name openclaw-gateway \
  -p 8080:8080 \
  -v /path/to/config:/etc/openclaw \
  -v /path/to/logs:/var/log/openclaw \
  openclaw/gateway:latest
# Docker Compose示例
version: '3'
services:
  openclaw-gateway:
    image: openclaw/gateway:latest
    ports:
      - "8080:8080"
    volumes:
      - ./config.yaml:/etc/openclaw/config.yaml
      - ./logs:/var/log/openclaw
    command: --config /etc/openclaw/config.yaml --foreground

配置文件示例

config.yaml 基础配置:

# OpenClaw Gateway 配置文件
gateway:
  port: 8080
  host: 0.0.0.0
  timeout: 30s
security:
  tls:
    enabled: false
    cert: /path/to/cert.pem
    key: /path/to/key.pem
logging:
  level: info
  file: /var/log/openclaw/gateway.log
upstreams:
  - name: backend-service
    target: http://localhost:3000
    weight: 100

启动流程检查

# 1. 检查配置文件语法
openclaw-gateway --config config.yaml --check
# 2. 测试启动(不实际运行)
openclaw-gateway --dry-run
# 3. 验证端口是否监听
netstat -tlnp | grep openclaw
ss -tlnp | grep openclaw
# 4. 检查进程状态
ps aux | grep openclaw
pgrep -lf openclaw

故障排除

# 查看详细启动日志
openclaw-gateway --foreground --log-level debug
# 检查端口冲突
lsof -i :8080
# 检查权限问题
sudo -u openclaw openclaw-gateway --config config.yaml
# 验证配置文件
openclaw-gateway --validate-config config.yaml

环境变量支持

OpenClaw Gateway 通常支持环境变量配置:

# 使用环境变量覆盖配置
export OPENCLAW_PORT=8443
export OPENCLAW_LOG_LEVEL=debug
openclaw-gateway

注意事项:

  1. 权限管理:确保运行用户有配置文件和日志目录的读写权限
  2. 端口占用:避免与系统其他服务端口冲突
  3. 配置文件:建议使用绝对路径指定配置文件位置
  4. 日志轮转:生产环境建议配置日志轮转(使用logrotate)
  5. 监控:建议结合监控系统(如Prometheus)监控服务状态

根据你的具体部署环境和需求,选择适合的启动方式,如果是生产环境,推荐使用 systemd 或 Docker 进行服务化管理。

标签: 直接启动 默认配置

抱歉,评论功能暂时关闭!