OpenClaw Linux 教程OpenClaw Linux 教程
首页
基础教程
最佳实践
OpenClaw 官网
编程指南
首页
基础教程
最佳实践
OpenClaw 官网
编程指南
  • 基础教程

    • 📚 基础教程
    • 第1章 - 认识 OpenClaw
    • 第2章 - 环境准备
    • 第3章 - 安装 OpenClaw
    • 第4章 - 引导向导配置
    • 第5章 - Gateway 网关
    • 第6章 - 连接聊天渠道
    • 第7章 - 工具与技能
    • 第8章 - 日常使用技巧
    • 第9章 - 自定义模型与阿里云百炼

第4章 - 引导向导配置

嗨,朋友!OpenClaw 已经装好了,现在我们来运行引导向导,一步步完成初始化配置。这个向导非常贴心,会引导你设置好所有必要的东西。

🚀 启动引导向导

打开终端,运行:

openclaw onboard --install-daemon

提示

--install-daemon 参数会同时安装 systemd 守护进程,让 OpenClaw Gateway 开机自启。这对 Linux 服务器特别有用!

📋 向导步骤详解

向导会依次引导你完成以下配置:

1. 选择 AI 模型 🤖

向导会问你想用哪个 AI 模型:

? Select your AI model provider:
  ❯ Anthropic (Claude) - Recommended
    OpenAI (GPT)
    Local model

建议选择 Anthropic Claude,官方强烈推荐 Claude Opus 4.6,它有更好的长上下文能力和安全性。

2. 配置 API Key 🔑

输入你在上一章准备好的 API Key:

? Enter your Anthropic API key: sk-ant-xxxxxxxxxxxxx

重要

API Key 只会保存在你的本地配置文件中,不会上传到任何地方。但请确保你的服务器安全。

3. 设置 Gateway 🌐

向导会配置 Gateway 的监听地址和端口:

? Gateway port (default: 18789): 18789

默认端口 18789 通常不需要修改。Gateway 默认只监听 127.0.0.1(本地),这是最安全的方式。

4. 安装守护进程 🔄

在 Linux 上,向导会自动创建 systemd 用户服务:

✓ Installed systemd user service
✓ Gateway daemon will start on boot

这意味着 OpenClaw Gateway 会:

  • 随系统自动启动
  • 崩溃后自动重启
  • 在后台安静运行

⚙️ 手动配置(进阶)

如果你想手动修改配置,编辑 ~/.openclaw/openclaw.json:

{
  "agent": {
    "model": "anthropic/claude-opus-4-6"
  },
  "gateway": {
    "port": 18789,
    "bind": "127.0.0.1"
  }
}

常用配置项

配置项说明默认值
agent.modelAI 模型选择anthropic/claude-opus-4-6
gateway.portGateway 监听端口18789
gateway.bindGateway 绑定地址127.0.0.1

注意

不要将 gateway.bind 设置为 0.0.0.0,除非你清楚自己在做什么。直接暴露 Gateway 到公网是不安全的。如果需要远程访问,请使用 Tailscale 或 SSH 隧道(后面的最佳实践会详细讲)。

🔍 验证配置

向导完成后,验证一切是否正常:

# 检查 Gateway 状态
openclaw gateway status

# 预期输出
# ✓ Gateway is running on 127.0.0.1:18789
# 打开 Dashboard(在本地浏览器)
openclaw dashboard

# 预期输出
# Dashboard available at http://127.0.0.1:18789/
# 发送一条测试消息
openclaw agent --message "你好,我是你的新主人!" --thinking high

如果一切正常,你应该能看到 AI 的回复。恭喜你,OpenClaw 已经在你的 Linux 上跑起来了!🎉

🔄 重新运行向导

如果你想重新配置,随时可以再次运行:

openclaw onboard

📂 环境变量

OpenClaw 支持通过环境变量自定义一些路径:

# 设置 OpenClaw 主目录
export OPENCLAW_HOME=/custom/path

# 设置状态目录
export OPENCLAW_STATE_DIR=/custom/state

# 设置配置文件路径
export OPENCLAW_CONFIG_PATH=/custom/openclaw.json

你可以把这些添加到 ~/.bashrc 中使其永久生效:

echo 'export OPENCLAW_HOME=~/.openclaw' >> ~/.bashrc
source ~/.bashrc

💪 练习题

  1. openclaw onboard --install-daemon 中 --install-daemon 的作用是什么?
  2. OpenClaw 的默认 Gateway 端口是多少?
  3. 为什么不建议把 gateway.bind 设为 0.0.0.0?

答案提示

  1. 安装 systemd 守护进程服务,让 Gateway 开机自启并在后台运行
  2. 默认端口是 18789
  3. 因为这会把 Gateway 暴露到公网,存在安全风险。应该使用 Tailscale 或 SSH 隧道

下一步: 第5章 - Gateway 网关 →

最近更新: 2026/2/28 09:29
Contributors: 王长安
Prev
第3章 - 安装 OpenClaw
Next
第5章 - Gateway 网关