$npx -y skills add chaterm/terminal-skills --skill installationOpenClaw 安装与部署
| 1 | # OpenClaw 安装与部署 |
| 2 | |
| 3 | ## 概述 |
| 4 | OpenClaw 是一个开源的分布式任务调度和工作流编排平台,本文档涵盖各种环境下的安装部署方法。 |
| 5 | |
| 6 | ## 环境要求 |
| 7 | |
| 8 | ### 系统要求 |
| 9 | ```bash |
| 10 | # 检查系统版本 |
| 11 | cat /etc/os-release |
| 12 | uname -a |
| 13 | |
| 14 | # 最低要求 |
| 15 | # - CPU: 2 核心 |
| 16 | # - 内存: 4GB |
| 17 | # - 磁盘: 20GB |
| 18 | # - 操作系统: Linux (CentOS 7+, Ubuntu 18.04+, Debian 10+) |
| 19 | |
| 20 | # 检查资源 |
| 21 | free -h |
| 22 | df -h |
| 23 | nproc |
| 24 | ``` |
| 25 | |
| 26 | ### 依赖检查 |
| 27 | ```bash |
| 28 | # 检查 Docker |
| 29 | docker --version |
| 30 | docker info |
| 31 | |
| 32 | # 检查 Docker Compose |
| 33 | docker-compose --version |
| 34 | |
| 35 | # 检查 Java (如需原生安装) |
| 36 | java -version |
| 37 | |
| 38 | # 检查 Python |
| 39 | python3 --version |
| 40 | pip3 --version |
| 41 | ``` |
| 42 | |
| 43 | ## Docker 方式安装(推荐) |
| 44 | |
| 45 | ### 单机部署 |
| 46 | ```bash |
| 47 | # 创建工作目录 |
| 48 | mkdir -p /opt/openclaw && cd /opt/openclaw |
| 49 | |
| 50 | # 下载 docker-compose.yml |
| 51 | curl -fsSL https://raw.githubusercontent.com/openclaw/openclaw/main/docker-compose.yml -o docker-compose.yml |
| 52 | |
| 53 | # 创建必要目录 |
| 54 | mkdir -p {data,logs,config} |
| 55 | |
| 56 | # 启动服务 |
| 57 | docker-compose up -d |
| 58 | |
| 59 | # 查看状态 |
| 60 | docker-compose ps |
| 61 | docker-compose logs -f |
| 62 | ``` |
| 63 | |
| 64 | ### 自定义配置 |
| 65 | ```yaml |
| 66 | # docker-compose.yml |
| 67 | version: '3.8' |
| 68 | |
| 69 | services: |
| 70 | openclaw-server: |
| 71 | image: openclaw/openclaw-server:latest |
| 72 | container_name: openclaw-server |
| 73 | ports: |
| 74 | - "8080:8080" |
| 75 | - "9090:9090" |
| 76 | environment: |
| 77 | - OPENCLAW_DB_HOST=openclaw-db |
| 78 | - OPENCLAW_DB_PORT=3306 |
| 79 | - OPENCLAW_DB_NAME=openclaw |
| 80 | - OPENCLAW_DB_USER=openclaw |
| 81 | - OPENCLAW_DB_PASSWORD=${DB_PASSWORD:-openclaw123} |
| 82 | - OPENCLAW_REDIS_HOST=openclaw-redis |
| 83 | - OPENCLAW_REDIS_PORT=6379 |
| 84 | - JAVA_OPTS=-Xms1g -Xmx2g |
| 85 | volumes: |
| 86 | - ./data:/opt/openclaw/data |
| 87 | - ./logs:/opt/openclaw/logs |
| 88 | - ./config:/opt/openclaw/config |
| 89 | depends_on: |
| 90 | - openclaw-db |
| 91 | - openclaw-redis |
| 92 | restart: unless-stopped |
| 93 | |
| 94 | openclaw-worker: |
| 95 | image: openclaw/openclaw-worker:latest |
| 96 | container_name: openclaw-worker |
| 97 | environment: |
| 98 | - OPENCLAW_SERVER_HOST=openclaw-server |
| 99 | - OPENCLAW_SERVER_PORT=9090 |
| 100 | - WORKER_GROUP=default |
| 101 | - WORKER_THREADS=8 |
| 102 | volumes: |
| 103 | - ./logs:/opt/openclaw/logs |
| 104 | depends_on: |
| 105 | - openclaw-server |
| 106 | restart: unless-stopped |
| 107 | deploy: |
| 108 | replicas: 2 |
| 109 | |
| 110 | openclaw-db: |
| 111 | image: mysql:8.0 |
| 112 | container_name: openclaw-db |
| 113 | environment: |
| 114 | - MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD:-root123} |
| 115 | - MYSQL_DATABASE=openclaw |
| 116 | - MYSQL_USER=openclaw |
| 117 | - MYSQL_PASSWORD=${DB_PASSWORD:-openclaw123} |
| 118 | volumes: |
| 119 | - ./data/mysql:/var/lib/mysql |
| 120 | restart: unless-stopped |
| 121 | |
| 122 | openclaw-redis: |
| 123 | image: redis:7-alpine |
| 124 | container_name: openclaw-redis |
| 125 | command: redis-server --appendonly yes |
| 126 | volumes: |
| 127 | - ./data/redis:/data |
| 128 | restart: unless-stopped |
| 129 | ``` |
| 130 | |
| 131 | ### 环境变量配置 |
| 132 | ```bash |
| 133 | # 创建 .env 文件 |
| 134 | cat > .env << 'EOF' |
| 135 | # 数据库配置 |
| 136 | DB_ROOT_PASSWORD=your_root_password |
| 137 | DB_PASSWORD=your_db_password |
| 138 | |
| 139 | # 服务配置 |
| 140 | OPENCLAW_PORT=8080 |
| 141 | OPENCLAW_GRPC_PORT=9090 |
| 142 | |
| 143 | # 日志级别 |
| 144 | LOG_LEVEL=INFO |
| 145 | EOF |
| 146 | |
| 147 | # 启动时加载 |
| 148 | docker-compose --env-file .env up -d |
| 149 | ``` |
| 150 | |
| 151 | ## Kubernetes 部署 |
| 152 | |
| 153 | ### Helm 安装 |
| 154 | ```bash |
| 155 | # 添加 Helm 仓库 |
| 156 | helm repo add openclaw https://charts.openclaw.io |
| 157 | helm repo update |
| 158 | |
| 159 | # 查看可用版本 |
| 160 | helm search repo openclaw |
| 161 | |
| 162 | # 安装(默认配置) |
| 163 | helm install openclaw openclaw/openclaw -n openclaw --create-namespace |
| 164 | |
| 165 | # 安装(自定义配置) |
| 166 | helm install openclaw openclaw/openclaw \ |
| 167 | -n openclaw --create-namespace \ |
| 168 | -f values.yaml |
| 169 | |
| 170 | # 查看状态 |
| 171 | kubectl get pods -n openclaw |
| 172 | kubectl get svc -n openclaw |
| 173 | ``` |
| 174 | |
| 175 | ### values.yaml 示例 |
| 176 | ```yaml |
| 177 | # values.yaml |
| 178 | server: |
| 179 | replicaCount: 2 |
| 180 | resources: |
| 181 | requests: |
| 182 | memory: "1Gi" |
| 183 | cpu: "500m" |
| 184 | limits: |
| 185 | memory: "2Gi" |
| 186 | cpu: "1000m" |
| 187 | |
| 188 | worker: |
| 189 | replicaCount: 3 |
| 190 | resources: |
| 191 | requests: |
| 192 | memory: "512Mi" |
| 193 | cpu: "250m" |
| 194 | limits: |
| 195 | memory: "1Gi" |
| 196 | cpu: "500m" |
| 197 | |
| 198 | mysql: |
| 199 | enabled: true |
| 200 | auth: |
| 201 | rootPassword: "your_root_password" |
| 202 | database: openclaw |
| 203 | username: openclaw |
| 204 | password: "your_password" |
| 205 | primary: |
| 206 | persistence: |
| 207 | size: 20Gi |
| 208 | |
| 209 | redis: |
| 210 | enabled: true |
| 211 | architecture: standalone |
| 212 | auth: |
| 213 | enabled: false |
| 214 | |
| 215 | ingress: |
| 216 | enabled: true |
| 217 | className: nginx |
| 218 | hosts: |
| 219 | - host: openclaw.example.com |
| 220 | paths: |
| 221 | - path: / |
| 222 | pathType: Prefix |
| 223 | ``` |
| 224 | |
| 225 | ### 手动 YAML 部署 |
| 226 | ```bash |
| 227 | # 创建命名空间 |
| 228 | kubectl create namespace openclaw |
| 229 | |
| 230 | # 应用配置 |
| 231 | kubectl apply -f https://raw.githubusercontent.com/openclaw/openclaw/main/deploy/kubernetes/ -n openclaw |
| 232 | |
| 233 | # 或本地文件 |
| 234 | kubectl apply -f openclaw-deployment.yaml -n openclaw |
| 235 | |
| 236 | # 查看部署状态 |
| 237 | kubectl get all -n openclaw |
| 238 | kubectl describe deployment openclaw-server -n openclaw |
| 239 | ``` |
| 240 | |
| 241 | ## 原生安装 |
| 242 | |
| 243 | ### 下载安装包 |
| 244 | ```bash |
| 245 | # 下载最新版本 |
| 246 | OPENCLAW_VERSION=$(curl -s https://api.github.com/repos/openclaw/openclaw/releases/latest | grep tag_name | cut -d '"' -f 4) |
| 247 | wget https://github.com/openclaw/openclaw/releases/download/${OPENCLAW_VERSION}/openclaw-${OPENCLAW_VERSION}.tar.gz |
| 248 | |
| 249 | # 解压 |
| 250 | tar -xzf openclaw-${OPENCLAW_VERSION}.tar.gz -C /opt/ |
| 251 | mv /opt/openclaw-${OPENCLAW_VERSION} /opt/openclaw |
| 252 | cd /opt/openclaw |
| 253 | ``` |
| 254 | |
| 255 | ### 初始化数据库 |
| 256 | ```bash |
| 257 | # 创建数据库 |
| 258 | mysql -u root -p << 'EOF' |
| 259 | CREATE DATABASE IF NOT EXISTS openclaw DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; |
| 260 | CREATE USER IF NOT EXISTS 'openclaw'@'%' IDENTIFIED BY 'your_password'; |
| 261 | GR |