$npx -y skills add chaterm/terminal-skills --skill configurationOpenClaw 配置管理
| 1 | # OpenClaw 配置管理 |
| 2 | |
| 3 | ## 概述 |
| 4 | OpenClaw 的核心配置、环境变量、性能调优和安全配置指南。 |
| 5 | |
| 6 | ## 核心配置文件 |
| 7 | |
| 8 | ### application.yml 结构 |
| 9 | ```yaml |
| 10 | # /opt/openclaw/conf/application.yml |
| 11 | |
| 12 | server: |
| 13 | port: 8080 |
| 14 | grpc: |
| 15 | port: 9090 |
| 16 | servlet: |
| 17 | context-path: / |
| 18 | |
| 19 | spring: |
| 20 | application: |
| 21 | name: openclaw-server |
| 22 | datasource: |
| 23 | url: jdbc:mysql://localhost:3306/openclaw?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai |
| 24 | username: openclaw |
| 25 | password: your_password |
| 26 | driver-class-name: com.mysql.cj.jdbc.Driver |
| 27 | hikari: |
| 28 | maximum-pool-size: 20 |
| 29 | minimum-idle: 5 |
| 30 | idle-timeout: 300000 |
| 31 | connection-timeout: 30000 |
| 32 | max-lifetime: 1800000 |
| 33 | |
| 34 | redis: |
| 35 | host: localhost |
| 36 | port: 6379 |
| 37 | password: |
| 38 | database: 0 |
| 39 | lettuce: |
| 40 | pool: |
| 41 | max-active: 16 |
| 42 | max-idle: 8 |
| 43 | min-idle: 2 |
| 44 | |
| 45 | openclaw: |
| 46 | # 集群配置 |
| 47 | cluster: |
| 48 | name: openclaw-cluster |
| 49 | node-id: ${HOSTNAME:node-1} |
| 50 | heartbeat-interval: 10000 |
| 51 | |
| 52 | # 调度配置 |
| 53 | scheduler: |
| 54 | thread-pool-size: 20 |
| 55 | max-retry-times: 3 |
| 56 | retry-interval: 30000 |
| 57 | task-timeout: 3600000 |
| 58 | |
| 59 | # 执行器配置 |
| 60 | executor: |
| 61 | max-concurrent-tasks: 100 |
| 62 | task-queue-size: 10000 |
| 63 | |
| 64 | # 日志配置 |
| 65 | logging: |
| 66 | level: INFO |
| 67 | retention-days: 30 |
| 68 | max-file-size: 100MB |
| 69 | ``` |
| 70 | |
| 71 | ### Worker 配置 |
| 72 | ```yaml |
| 73 | # /opt/openclaw/conf/worker.yml |
| 74 | |
| 75 | worker: |
| 76 | # 服务端连接 |
| 77 | server: |
| 78 | host: openclaw-server |
| 79 | port: 9090 |
| 80 | |
| 81 | # Worker 配置 |
| 82 | group: default |
| 83 | name: ${HOSTNAME:worker-1} |
| 84 | threads: 8 |
| 85 | max-tasks: 50 |
| 86 | |
| 87 | # 心跳配置 |
| 88 | heartbeat: |
| 89 | interval: 5000 |
| 90 | timeout: 30000 |
| 91 | |
| 92 | # 任务配置 |
| 93 | task: |
| 94 | temp-dir: /tmp/openclaw |
| 95 | log-dir: /opt/openclaw/logs/tasks |
| 96 | max-log-size: 10MB |
| 97 | ``` |
| 98 | |
| 99 | ## 环境变量配置 |
| 100 | |
| 101 | ### Server 环境变量 |
| 102 | ```bash |
| 103 | # 数据库配置 |
| 104 | export OPENCLAW_DB_HOST=localhost |
| 105 | export OPENCLAW_DB_PORT=3306 |
| 106 | export OPENCLAW_DB_NAME=openclaw |
| 107 | export OPENCLAW_DB_USER=openclaw |
| 108 | export OPENCLAW_DB_PASSWORD=your_password |
| 109 | |
| 110 | # Redis 配置 |
| 111 | export OPENCLAW_REDIS_HOST=localhost |
| 112 | export OPENCLAW_REDIS_PORT=6379 |
| 113 | export OPENCLAW_REDIS_PASSWORD= |
| 114 | |
| 115 | # 服务配置 |
| 116 | export OPENCLAW_PORT=8080 |
| 117 | export OPENCLAW_GRPC_PORT=9090 |
| 118 | |
| 119 | # JVM 配置 |
| 120 | export JAVA_OPTS="-Xms1g -Xmx2g -XX:+UseG1GC -XX:MaxGCPauseMillis=200" |
| 121 | |
| 122 | # 日志级别 |
| 123 | export LOG_LEVEL=INFO |
| 124 | ``` |
| 125 | |
| 126 | ### Worker 环境变量 |
| 127 | ```bash |
| 128 | # Server 连接 |
| 129 | export OPENCLAW_SERVER_HOST=openclaw-server |
| 130 | export OPENCLAW_SERVER_PORT=9090 |
| 131 | |
| 132 | # Worker 配置 |
| 133 | export WORKER_GROUP=default |
| 134 | export WORKER_NAME=worker-1 |
| 135 | export WORKER_THREADS=8 |
| 136 | |
| 137 | # 任务配置 |
| 138 | export TASK_TEMP_DIR=/tmp/openclaw |
| 139 | export TASK_LOG_DIR=/opt/openclaw/logs/tasks |
| 140 | ``` |
| 141 | |
| 142 | ### Docker 环境变量传递 |
| 143 | ```bash |
| 144 | # docker-compose.yml 方式 |
| 145 | docker-compose up -d |
| 146 | |
| 147 | # 或直接传递 |
| 148 | docker run -d \ |
| 149 | -e OPENCLAW_DB_HOST=mysql \ |
| 150 | -e OPENCLAW_DB_PASSWORD=password \ |
| 151 | -e JAVA_OPTS="-Xms1g -Xmx2g" \ |
| 152 | openclaw/openclaw-server:latest |
| 153 | ``` |
| 154 | |
| 155 | ## 数据库配置 |
| 156 | |
| 157 | ### 连接池配置 |
| 158 | ```yaml |
| 159 | spring: |
| 160 | datasource: |
| 161 | hikari: |
| 162 | # 最大连接数 |
| 163 | maximum-pool-size: 20 |
| 164 | # 最小空闲连接 |
| 165 | minimum-idle: 5 |
| 166 | # 空闲超时 (5分钟) |
| 167 | idle-timeout: 300000 |
| 168 | # 连接超时 (30秒) |
| 169 | connection-timeout: 30000 |
| 170 | # 连接最大生命周期 (30分钟) |
| 171 | max-lifetime: 1800000 |
| 172 | # 连接池名称 |
| 173 | pool-name: OpenClawHikariPool |
| 174 | # 连接测试查询 |
| 175 | connection-test-query: SELECT 1 |
| 176 | ``` |
| 177 | |
| 178 | ### 多数据源配置 |
| 179 | ```yaml |
| 180 | spring: |
| 181 | datasource: |
| 182 | primary: |
| 183 | url: jdbc:mysql://master:3306/openclaw |
| 184 | username: openclaw |
| 185 | password: password |
| 186 | secondary: |
| 187 | url: jdbc:mysql://slave:3306/openclaw |
| 188 | username: openclaw |
| 189 | password: password |
| 190 | read-only: true |
| 191 | ``` |
| 192 | |
| 193 | ### 数据库优化参数 |
| 194 | ```sql |
| 195 | -- MySQL 推荐配置 |
| 196 | SET GLOBAL innodb_buffer_pool_size = 1G; |
| 197 | SET GLOBAL innodb_log_file_size = 256M; |
| 198 | SET GLOBAL max_connections = 500; |
| 199 | SET GLOBAL innodb_flush_log_at_trx_commit = 2; |
| 200 | SET GLOBAL sync_binlog = 0; |
| 201 | ``` |
| 202 | |
| 203 | ## Redis 配置 |
| 204 | |
| 205 | ### 单机配置 |
| 206 | ```yaml |
| 207 | spring: |
| 208 | redis: |
| 209 | host: localhost |
| 210 | port: 6379 |
| 211 | password: |
| 212 | database: 0 |
| 213 | timeout: 10000 |
| 214 | lettuce: |
| 215 | pool: |
| 216 | max-active: 16 |
| 217 | max-idle: 8 |
| 218 | min-idle: 2 |
| 219 | max-wait: 10000 |
| 220 | ``` |
| 221 | |
| 222 | ### 集群配置 |
| 223 | ```yaml |
| 224 | spring: |
| 225 | redis: |
| 226 | cluster: |
| 227 | nodes: |
| 228 | - redis-node-1:6379 |
| 229 | - redis-node-2:6379 |
| 230 | - redis-node-3:6379 |
| 231 | max-redirects: 3 |
| 232 | lettuce: |
| 233 | cluster: |
| 234 | refresh: |
| 235 | adaptive: true |
| 236 | period: 30000 |
| 237 | ``` |
| 238 | |
| 239 | ### 哨兵配置 |
| 240 | ```yaml |
| 241 | spring: |
| 242 | redis: |
| 243 | sentinel: |
| 244 | master: mymaster |
| 245 | nodes: |
| 246 | - sentinel-1:26379 |
| 247 | - sentinel-2:26379 |
| 248 | - sentinel-3:26379 |
| 249 | password: redis_password |
| 250 | ``` |
| 251 | |
| 252 | ## 调度器配置 |
| 253 | |
| 254 | ### 基础配置 |
| 255 | ```yaml |
| 256 | openclaw: |
| 257 | scheduler: |
| 258 | # 调度线程池大小 |
| 259 | thread-pool-size: 20 |
| 260 | |
| 261 | # 任务重试配置 |
| 262 | max-retry-times: 3 |
| 263 | retry-interval: 30000 |
| 264 | |
| 265 | # 任务超时 (1小时) |
| 266 | task-timeout: 3600000 |
| 267 | |
| 268 | # 任务队列 |
| 269 | queue-capacity: 10000 |
| 270 | |
| 271 | # 调度策略 |
| 272 | strategy: ROUND_ROBIN # ROUND_ROBIN, RANDOM, LEAST_LOAD, CONSISTENT_HASH |
| 273 | ``` |
| 274 | |
| 275 | ### 高级调度策略 |
| 276 | ```yaml |
| 277 | openclaw: |
| 278 | scheduler: |
| 279 | # 故障转移 |
| 280 | failover: |
| 281 | enabled: true |
| 282 | max-attempts: 3 |
| 283 | |
| 284 | # 负载均衡 |
| 285 | load-balance: |
| 286 | strategy: LEAST_LOAD |
| 287 | weight-enabled: true |
| 288 | |
| 289 | # 任务分片 |
| 290 | sharding: |
| 291 | enabled: true |
| 292 | default-count: |