[{"data":1,"prerenderedAt":597},["ShallowReactive",2],{"content:\u002Fposts\u002Fopenclaw-installation-and-setup":3,"surround:\u002Fposts\u002Fopenclaw-installation-and-setup":588},{"id":4,"title":5,"body":6,"categories":558,"date":560,"description":561,"draft":562,"extension":563,"image":564,"meta":565,"navigation":567,"path":568,"permalink":564,"pinned":562,"published":564,"readingTime":569,"recommend":564,"references":564,"seo":574,"sitemap":575,"stem":576,"tags":577,"type":586,"updated":560,"__hash__":587},"content\u002Fposts\u002Fposts\u002Fopenclaw-installation-and-setup.md","OpenClaw (小龙虾) 部署指南：打造企业级 AI 自动化助手",{"type":7,"value":8,"toc":530},"minimark",[9,19,22,27,61,65,71,81,85,88,96,99,105,121,125,128,134,139,146,154,158,161,167,234,238,245,251,258,274,278,282,285,291,302,306,309,319,325,332,338,379,383,386,417,422,426,433,436,444,447,469,473,476,481,485,488,494,500,504,508,514,518,524],[10,11,15],"alert",{"type":12,"title":13,"icon":14},"info","AI 迁移提示","tabler:robot",[16,17,18],"p",{},"本文由 AI 协助从旧站迁移，尚未完成逐篇人工审校；内容如有疏漏，将在复核后修订。",[16,20,21],{},"本文记录在 Windows WSL 子系统下部署 OpenClaw（社区昵称\"小龙虾\"）的完整流程：从导入 Ubuntu WSL 镜像、执行安装脚本、配置 gateway，到注册 systemd 开机自启与常用故障排查。",[23,24,26],"h2",{"id":25},"_1-前置条件","1. 前置条件",[28,29,30,34,47,54],"ul",{},[31,32,33],"li",{},"Windows 10（版本 2004 及以上）或 Windows 11",[31,35,36,37,41,42,46],{},"已安装 ",[38,39,40],"strong",{},"WSL 2","（未装可执行 ",[43,44,45],"code",{"code":45},"wsl --install"," 安装）",[31,48,49,50,53],{},"预留 ",[38,51,52],{},"8 GB 以上"," 磁盘空间（Ubuntu 镜像 + OpenClaw 运行数据）",[31,55,56,57,60],{},"已下载好 Ubuntu WSL 镜像文件（如 ",[43,58,59],{"code":59},"ubuntu-24.04.4-wsl-amd64.wsl","）",[23,62,64],{"id":63},"_2-导入-ubuntu-wsl-子系统","2. 导入 Ubuntu WSL 子系统",[16,66,67,70],{},[38,68,69],{},"在宿主机 PowerShell 中执行","：",[72,73,79],"pre",{"className":74,"code":76,"language":77,"meta":78},[75],"language-powershell","# 格式：wsl --import \u003C自定义系统名称> \u003C安装路径> \u003C镜像文件路径>\nwsl --import openclaw F:\\openclaw \"$env:USERPROFILE\\Downloads\\ubuntu-24.04.4-wsl-amd64.wsl\"\n\n# 进入 WSL 子系统\nwsl -d openclaw\n","powershell","",[43,80,76],{"__ignoreMap":78},[23,82,84],{"id":83},"_3-安装-openclaw在-wsl-内部","3. 安装 OpenClaw（在 WSL 内部）",[16,86,87],{},"进入 WSL 子系统后，先装好基础依赖：",[72,89,94],{"className":90,"code":92,"language":93,"meta":78},[91],"language-bash","# 如果网络环境不好（apt 更新缓慢或失败），请自行更换 apt 源（tuna、阿里云等）\napt update\napt install -y curl zip unzip\n","bash",[43,95,92],{"__ignoreMap":78},[16,97,98],{},"执行 OpenClaw 官方安装脚本：",[72,100,103],{"className":101,"code":102,"language":93,"meta":78},[91],"curl -fsSL https:\u002F\u002Fopenclaw.ai\u002Finstall.sh | bash\n\n# 将工具权限配置为完整模式\nopenclaw config set tools.profile full\n",[43,104,102],{"__ignoreMap":78},[10,106,109,115],{"type":107,"title":108},"warning","`curl | bash` 的安全提醒",[16,110,111,114],{},[43,112,113],{"code":113},"curl ... | bash"," 会把远程脚本直接喂给 bash 执行，一旦上游或你当时的 DNS 解析被污染，就相当于在本机执行了不可控的代码。如果对安全有要求，建议先下载审查再执行：",[72,116,119],{"className":117,"code":118,"language":93,"meta":78},[91],"curl -fsSL https:\u002F\u002Fopenclaw.ai\u002Finstall.sh -o install.sh\nless install.sh           # 浏览脚本内容确认无异常\nbash install.sh\n",[43,120,118],{"__ignoreMap":78},[23,122,124],{"id":123},"_4-配置文件说明","4. 配置文件说明",[16,126,127],{},"编辑 OpenClaw 配置文件：",[72,129,132],{"className":130,"code":131,"language":93,"meta":78},[91],"nano ~\u002F.openclaw\u002Fopenclaw.json\n",[43,133,131],{"__ignoreMap":78},[135,136,138],"h3",{"id":137},"_41-推荐配置本机使用","4.1 推荐配置（本机使用）",[16,140,141,142,145],{},"默认情况下推荐 ",[43,143,144],{"code":144},"bind: local","，只监听本机回环，需要远程访问时用 SSH 隧道打通（见 4.3）。",[72,147,152],{"className":148,"code":150,"language":151,"meta":78},[149],"language-json","{\n  \"gateway\": {\n    \"port\": 18789,\n    \"mode\": \"local\",\n    \"bind\": \"local\",\n    \"auth\": {\n      \"mode\": \"token\",\n      \"token\": \"your_token_here\"\n    },\n    \"tailscale\": {\n      \"mode\": \"off\"\n    }\n  }\n}\n","json",[43,153,150],{"__ignoreMap":78},[135,155,157],{"id":156},"_42-开启局域网访问谨慎使用","4.2 开启局域网访问（谨慎使用）",[16,159,160],{},"如果确实需要让局域网其他设备直连，修改为以下配置：",[72,162,165],{"className":163,"code":164,"language":151,"meta":78},[149],"{\n  \"gateway\": {\n    \"port\": 18789,\n    \"mode\": \"local\",\n    \"bind\": \"lan\",\n    \"auth\": {\n      \"mode\": \"token\",\n      \"token\": \"your_token_here\"\n    },\n    \"controlUi\": {\n      \"dangerouslyAllowHostHeaderOriginFallback\": true,\n      \"allowInsecureAuth\": true,\n      \"dangerouslyDisableDeviceAuth\": true\n    },\n    \"tailscale\": {\n      \"mode\": \"off\",\n      \"resetOnExit\": false\n    }\n  }\n}\n",[43,166,164],{"__ignoreMap":78},[10,168,170,173,199,214,219],{"type":107,"title":169},"`bind: lan` + dangerously 开关的安全影响",[16,171,172],{},"上述配置会把 OpenClaw 暴露到整个局域网，同时关闭三重安全校验：",[28,174,175,183,191],{},[31,176,177,182],{},[38,178,179],{},[43,180,181],{"code":181},"dangerouslyAllowHostHeaderOriginFallback","：关闭 Origin 校验，允许任意来源调用",[31,184,185,190],{},[38,186,187],{},[43,188,189],{"code":189},"allowInsecureAuth","：允许明文（非 HTTPS）认证",[31,192,193,198],{},[38,194,195],{},[43,196,197],{"code":197},"dangerouslyDisableDeviceAuth","：禁用设备绑定",[16,200,201,202,205,206,209,210,213],{},"配置项里出现 ",[43,203,204],{"code":204},"dangerously"," 是作者对使用者最强的警告。结合 ",[43,207,208],{"code":208},"tools.profile full","（完整系统工具权限），",[38,211,212],{},"任何能访问 18789 端口的设备都能用这个 AI 助手在本机做任意事","，包括读写文件、执行命令。",[16,215,216,70],{},[38,217,218],{},"推荐替代方案",[28,220,221,227],{},[31,222,223,224,226],{},"本机使用：保留 ",[43,225,144],{"code":144},"（4.1 节），配合下面的 SSH 隧道",[31,228,229,230,233],{},"远程访问：开启 ",[43,231,232],{"code":232},"tailscale"," 段，基于身份认证的 Mesh VPN，比裸 lan 安全得多",[135,235,237],{"id":236},"_43-ssh-隧道访问推荐的远程用法","4.3 SSH 隧道访问（推荐的远程用法）",[16,239,240,241,244],{},"从其他机器访问时，SSH 隧道比 ",[43,242,243],{"code":243},"bind: lan"," 安全得多：",[72,246,249],{"className":247,"code":248,"language":93,"meta":78},[91],"# 在客户端执行，把远程 18789 映射到本地 18789\nssh -N -L 18789:127.0.0.1:18789 user@10.0.0.53\n",[43,250,248],{"__ignoreMap":78},[16,252,253,254,257],{},"这样本地浏览器访问 ",[43,255,256],{"code":256},"http:\u002F\u002Flocalhost:18789"," 就是在访问远端机器的 OpenClaw，且端口仅对你的 SSH 可见。",[10,259,261,268],{"type":12,"title":260},"改完配置要重启服务",[16,262,263,264,267],{},"本节的配置修改都需要",[38,265,266],{},"重启 OpenClaw 服务","后才会生效。如果已经按第 5 节注册了 systemd 服务，执行：",[72,269,272],{"className":270,"code":271,"language":93,"meta":78},[91],"sudo systemctl restart openclaw\n",[43,273,271],{"__ignoreMap":78},[23,275,277],{"id":276},"_5-启动服务","5. 启动服务",[135,279,281],{"id":280},"_51-前台运行首次调试","5.1 前台运行（首次调试）",[16,283,284],{},"首次安装建议前台运行，确认一切正常：",[72,286,289],{"className":287,"code":288,"language":93,"meta":78},[91],"source ~\u002F.bashrc\nopenclaw gateway\n",[43,290,288],{"__ignoreMap":78},[16,292,293,294,297,298,301],{},"终端会打印启动日志，能看到 ",[43,295,296],{"code":296},"Listening on :18789"," 之类的信息即为成功。按 ",[43,299,300],{"code":300},"Ctrl+C"," 退出。",[135,303,305],{"id":304},"_52-注册为-systemd-服务长期运行","5.2 注册为 systemd 服务（长期运行）",[16,307,308],{},"前台运行正常后，推荐注册成 systemd 服务，方便开机自启与异常自拉。",[16,310,311,318],{},[38,312,313,314,317],{},"先查找 ",[43,315,316],{"code":316},"openclaw"," 二进制的绝对路径","（systemd 不读用户 PATH，必须写死）：",[72,320,323],{"className":321,"code":322,"language":93,"meta":78},[91],"which openclaw\n# 示例输出：\u002Fusr\u002Flocal\u002Fbin\u002Fopenclaw\n",[43,324,322],{"__ignoreMap":78},[16,326,327,328,331],{},"创建服务文件（把 ",[43,329,330],{"code":330},"ExecStart"," 里的路径换成上一步查到的值）：",[72,333,336],{"className":334,"code":335,"language":93,"meta":78},[91],"sudo tee \u002Fetc\u002Fsystemd\u002Fsystem\u002Fopenclaw.service > \u002Fdev\u002Fnull \u003C\u003C'EOF'\n[Unit]\nDescription=OpenClaw Gateway Service\nAfter=network.target\n\n[Service]\nType=simple\nUser=root\nWorkingDirectory=\u002Froot\nExecStart=\u002Fusr\u002Flocal\u002Fbin\u002Fopenclaw gateway\nRestart=always\nRestartSec=10\n\n[Install]\nWantedBy=multi-user.target\nEOF\n\nsudo systemctl daemon-reload\nsudo systemctl enable --now openclaw\nsudo systemctl status openclaw\n",[43,337,335],{"__ignoreMap":78},[10,339,341,359,362,368,371],{"type":107,"title":340},"生产环境建议用专用用户，不要 root 跑",[16,342,343,344,347,348,351,352,354,355,358],{},"上面的服务文件 ",[43,345,346],{"code":346},"User=root"," 是为了匹配 WSL 默认导入的 root 环境（",[43,349,350],{"code":350},"wsl --import"," 进去默认就是 root）。但 ",[43,353,208],{"code":208}," 给了 OpenClaw 执行命令、读写文件的完整能力——",[38,356,357],{},"以 root 运行等于把整台机器的 root 权限交给 AI","。",[16,360,361],{},"对安全有要求时，创建专用用户并把 OpenClaw 装到该用户下：",[72,363,366],{"className":364,"code":365,"language":93,"meta":78},[91],"sudo useradd -r -m -s \u002Fbin\u002Fbash openclaw\nsudo -iu openclaw bash -c 'curl -fsSL https:\u002F\u002Fopenclaw.ai\u002Finstall.sh | bash'\nsudo -iu openclaw openclaw config set tools.profile full\nsudo -iu openclaw which openclaw     # 查询准确路径，一般是 \u002Fhome\u002Fopenclaw\u002F.openclaw\u002Fbin\u002Fopenclaw\n",[43,367,365],{"__ignoreMap":78},[16,369,370],{},"然后把服务文件里改成：",[72,372,377],{"className":373,"code":375,"language":376,"meta":78},[374],"language-ini","User=openclaw\nWorkingDirectory=\u002Fhome\u002Fopenclaw\nExecStart=\u002Fhome\u002Fopenclaw\u002F.openclaw\u002Fbin\u002Fopenclaw gateway\n","ini",[43,378,375],{"__ignoreMap":78},[23,380,382],{"id":381},"_6-访问-openclaw","6. 访问 OpenClaw",[16,384,385],{},"服务起来之后：",[387,388,389,398,406],"ol",{},[31,390,391,392,394,395,397],{},"如果是 ",[43,393,144],{"code":144},"：在 WSL 本机浏览器打开 ",[43,396,256],{"code":256},"，或从宿主机\u002F其他机器通过 SSH 隧道（见 4.3）访问",[31,399,391,400,402,403],{},[43,401,243],{"code":243},"：直接在局域网任意设备打开 ",[43,404,405],{"code":405},"http:\u002F\u002F\u003CWSL 宿主机 IP>:18789",[31,407,408,409,412,413,416],{},"使用 ",[43,410,411],{"code":411},"openclaw.json"," 里配置的 ",[43,414,415],{"code":415},"token"," 登录 Web 控制台",[10,418,419],{"type":12},[16,420,421],{},"OpenClaw 具体的 Web UI 操作、工具使用示例与最佳实践超出本文部署指南的范围，建议参考官方文档或社区资料进一步了解。",[23,423,425],{"id":424},"_7-故障排查","7. 故障排查",[135,427,429,430],{"id":428},"_71-systemd-user-services-are-unavailable","7.1 ",[43,431,432],{"code":432},"Systemd user services are unavailable",[16,434,435],{},"安装时若输出：",[72,437,442],{"className":438,"code":440,"language":441},[439],"language-text","Systemd user services are unavailable. Skipping lingering checks and service install.\n","text",[43,443,440],{"__ignoreMap":78},[16,445,446],{},"这是 WSL 默认没启用用户级 systemd 导致的。两种解法：",[28,448,449,459],{},[31,450,451,454,455,458],{},[38,452,453],{},"方案 A","：直接前台运行 ",[43,456,457],{"code":457},"openclaw gateway","（见 5.1），开机启动需手动操作",[31,460,461,464,465,468],{},[38,462,463],{},"方案 B（推荐）","：按第 5.2 节注册为 ",[38,466,467],{},"system 级"," systemd 服务（不是 user 级），不受此限制",[135,470,472],{"id":471},"_72-改了配置后没生效","7.2 改了配置后没生效",[16,474,475],{},"配置文件修改后必须重启服务：",[72,477,479],{"className":478,"code":271,"language":93,"meta":78},[91],[43,480,271],{"__ignoreMap":78},[135,482,484],{"id":483},"_73-服务起不来-状态-failed","7.3 服务起不来 \u002F 状态 failed",[16,486,487],{},"查看详细日志：",[72,489,492],{"className":490,"code":491,"language":93,"meta":78},[91],"sudo journalctl -u openclaw -n 100 --no-pager\n",[43,493,491],{"__ignoreMap":78},[16,495,496,497,499],{},"常见原因：",[43,498,330],{"code":330}," 里的二进制路径不对（不同用户安装位置不同）、端口 18789 被占用、配置文件 JSON 语法错误。",[23,501,503],{"id":502},"_8-常用命令速查","8. 常用命令速查",[135,505,507],{"id":506},"_81-powershell宿主机","8.1 PowerShell（宿主机）",[72,509,512],{"className":510,"code":511,"language":77,"meta":78},[75],"# 进入 WSL 子系统\nwsl -d openclaw\n\n# 关闭 WSL 子系统\nwsl -d openclaw --shutdown\n\n# 查看已安装的 WSL 子系统列表\nwsl -l -v\n",[43,513,511],{"__ignoreMap":78},[135,515,517],{"id":516},"_82-linuxwsl-内部systemd-服务方式","8.2 Linux（WSL 内部，systemd 服务方式）",[72,519,522],{"className":520,"code":521,"language":93,"meta":78},[91],"# 查看服务状态\nsudo systemctl status openclaw\n\n# 启动 \u002F 停止 \u002F 重启\nsudo systemctl start openclaw\nsudo systemctl stop openclaw\nsudo systemctl restart openclaw\n\n# 查看实时日志\nsudo journalctl -u openclaw -f\n",[43,523,521],{"__ignoreMap":78},[10,525,527],{"type":12,"title":526},"作者注",[16,528,529],{},"本教程在 Windows 11 + WSL 2 + Ubuntu 24.04 环境下验证过。OpenClaw 本身的功能和使用方法请查阅其官方文档。",{"title":78,"searchDepth":531,"depth":531,"links":532},4,[533,535,536,537,543,547,548,554],{"id":25,"depth":534,"text":26},2,{"id":63,"depth":534,"text":64},{"id":83,"depth":534,"text":84},{"id":123,"depth":534,"text":124,"children":538},[539,541,542],{"id":137,"depth":540,"text":138},3,{"id":156,"depth":540,"text":157},{"id":236,"depth":540,"text":237},{"id":276,"depth":534,"text":277,"children":544},[545,546],{"id":280,"depth":540,"text":281},{"id":304,"depth":540,"text":305},{"id":381,"depth":534,"text":382},{"id":424,"depth":534,"text":425,"children":549},[550,552,553],{"id":428,"depth":540,"text":551},"7.1 Systemd user services are unavailable",{"id":471,"depth":540,"text":472},{"id":483,"depth":540,"text":484},{"id":502,"depth":534,"text":503,"children":555},[556,557],{"id":506,"depth":540,"text":507},{"id":516,"depth":540,"text":517},[559],"服务","2026-03-07","在 Windows WSL \u002F Linux 环境下导入 Ubuntu 子系统、安装 OpenClaw (小龙虾)，配置 gateway、token 认证与 systemd 开机自启的完整流程。",false,"md",null,{"slots":566},{},true,"\u002Fposts\u002Fopenclaw-installation-and-setup",{"text":570,"minutes":571,"time":572,"words":573},"8 min read",7.67,460200,1534,{"title":5,"description":561},{"loc":568},"posts\u002Fposts\u002Fopenclaw-installation-and-setup",[578,579,580,581,582,583,584,585],"OpenClaw","AI","Automation","WSL","Ubuntu","Windows","systemd","HomeLab","tech","zgieyzO3zZoEzY2j4t_7pb5ltBSJezjFUXQFFTRLPPg",[589,593],{"title":590,"path":591,"stem":592,"date":560,"type":586,"children":-1},"NAS 变身播放机：Kodi Docker-Compose 硬解直通手册","\u002Fposts\u002Ffnos-kodi-docker-hdmi-passthrough","posts\u002Fposts\u002Ffnos-kodi-docker-hdmi-passthrough",{"title":594,"path":595,"stem":596,"date":560,"type":586,"children":-1},"PowerShell SSH 效率手册：免密、别名与端口转发","\u002Fposts\u002Fpowershell-ssh-config-guide","posts\u002Fposts\u002Fpowershell-ssh-config-guide",1788712223088]