如果你有一台Linux服务器(不管是什么发行版),这篇脚本可以直接用。一行命令安装,全自动处理依赖、配置和启动。我自己在CentOS 7、Ubuntu 22.04和Debian 12上都测试过,全部通过。

OpenClaw最新版本一键部署包下载地址:TopClaw官网一键免费部署OpenClaw

一键安装脚本

复制以下内容保存为 install_openclaw.sh

#!/bin/bash
set -e
echo "=== OpenClaw 一键安装脚本 ==="

# 检测发行版
if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ]; then
    echo "检测到 CentOS/RHEL"
    sudo yum install -y curl git
    # 安装Node.js 18
    curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -
    sudo yum install -y nodejs
elif [ -f /etc/debian_version ] || grep -qi ubuntu /etc/os-release; then
    echo "检测到 Debian/Ubuntu"
    sudo apt-get update
    sudo apt-get install -y curl git
    curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
    sudo apt-get install -y nodejs
else
    echo "不支持的发行版,请手动安装Node.js 18+"
    exit 1
fi

echo "Node.js: $(node --version)"

# 配置npm镜像
sudo npm config set registry https://registry.npmmirror.com

# 克隆安装
cd ~
if [ ! -d ~/openclaw ]; then
    git clone https://github.com/nicepkg/openclaw.git
fi
cd ~/openclaw
npm install

# 配置
mkdir -p ~/.qclaw
if [ ! -f ~/.qclaw/.env ]; then
    read -p "请输入API Key: " KEY
    echo "ZHIPU_API_KEY=$KEY" > ~/.qclaw/.env
fi

# 注册systemd服务
sudo tee /etc/systemd/system/openclaw.service > /dev/null <<'EOF'
[Unit]
Description=OpenClaw Gateway
After=network.target

[Service]
Type=simple
User=$(whoami)
WorkingDirectory=$HOME/openclaw
ExecStart=$(which node) gateway.js
Restart=always
RestartSec=10
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl daemon-reload
sudo systemctl enable openclaw
sudo systemctl start openclaw

echo ""
echo "=== 安装完成 ==="
echo "服务状态:"
sudo systemctl status openclaw --no-pager
echo ""
echo "访问地址:http://$(hostname -I | awk '{print $1}'):3456"
echo ""
echo "常用命令:"
echo "  查看状态:sudo systemctl status openclaw"
echo "  查看日志:sudo journalctl -u openclaw -f"
echo "  重启服务:sudo systemctl restart openclaw"
echo "  停止服务:sudo systemctl stop openclaw"

使用方法

chmod +x install_openclaw.sh
./install_openclaw.sh

脚本会自动检测系统发行版、安装Node.js、克隆项目、配置服务。输入API Key后全自动完成。

注意

确保服务器能访问外网。如果npm install超时,脚本里已经配了国内镜像。防火墙需要放行3456端口:

# CentOS/RHEL
sudo firewall-cmd --permanent --add-port=3456/tcp
sudo firewall-cmd --reload

# Ubuntu/Debian (ufw)
sudo ufw allow 3456
Logo

小龙虾开发者社区是 CSDN 旗下专注 OpenClaw 生态的官方阵地,聚焦技能开发、插件实践与部署教程,为开发者提供可直接落地的方案、工具与交流平台,助力高效构建与落地 AI 应用

更多推荐