OpenClaw 远程部署指南:VPS/云服务器完整教程
将 OpenClaw 部署到 VPS 可以实现 24/7 运行和随时随地访问。本文详细讲解在主流云服务商部署 OpenClaw 的完整流程,包括 Tailscale 组网、安全配置、性能优化等。
一、为什么选择远程部署
1.1 远程部署优势
| 优势 | 说明 |
|---|---|
| 24/7 运行 |
| 稳定网络 | 云服务器网络更稳定 | 随时访问 | 任何地方都能访问 AI 助手 | 资源独立 | 不占用本地设备资源 |
1.2 部署方案对比
| 方案 | 成本 | 难度 | 推荐场景 | 本地部署 |
低
| 低 | 测试、隐私敏感 | VPS 部署 | 中 | 中 | 生产环境 | 混合部署 | 中 |
| 高 | 最佳实践 |
—
二、VPS 选择
2.1 推荐配置
| 配置项 | 最低 | 推荐 | CPU |
| 2 核 | 内存 | 1GB | 2GB | 存储 | 20GB | 40GB | 带宽 |
| 1Mbps | 5Mbps |
2.2 推荐服务商
| 服务商 | 价格/月 | 特点 | Hetzner |
€5
| 欧洲,性价比高 | DigitalOcean | $6 | 全球,文档好 | Linode | $5 | 全球,稳定 | Vultr |
| $6 | 全球,灵活 | 阿里云 | ¥30 | 国内,速度快 |
—
三、安装步骤
3.1 服务器准备
SSH 连接:
ssh root@your-vps-ip
系统更新:
apt update && apt upgrade -y # Ubuntu/Debian
安装 Node.js:
curl -fsSL https://deb.nodesource.com/setup_22.xbash -
apt install -y nodejs
3.2 安装 OpenClaw
curl -fsSL https://openclaw.ai/install.shbash
openclaw onboard --install-daemon
3.3 配置防火墙
UFW 配置:
ufw allow 22/tcp # SSH
ufw allow 18789/tcp # OpenClaw Gateway
ufw enable
四、Tailscale 组网
4.1 为什么使用 Tailscale
- 无需公网 IP
- 自动 NAT 穿透
- 端到端加密
- 简单易用
4.2 安装 Tailscale
VPS 端:
curl -fsSL https://tailscale.com/install.shsh
tailscale up
本地端:
macOS
brew install tailscale
tailscale up
Windows
# 下载安装包安装
4.3 配置 Tailscale
获取 VPS 的 Tailscale IP:
tailscale ip
配置 OpenClaw 使用 Tailscale:
{
gateway: {
bind: "127.0.0.1",
port: 18789,
auth: {
token: "your-token"
},
allowTailscale: true
}
}
使用 Tailscale Serve:
openclaw gateway --tailscale serve
五、安全配置
5.1 SSH 安全
禁用密码登录:
/etc/ssh/sshd_config
PasswordAuthentication no
PubkeyAuthentication yes
重启 SSH:
systemctl restart sshd
5.2 OpenClaw 安全
配置白名单:
{
channels: {
whatsapp: {
dmPolicy: "allowlist",
allowFrom: ["+8613800138000"]
}
}
}
启用 Gateway 认证:
{
gateway: {
auth: {
token: "strong-random-token"
}
}
}
六、备份策略
6.1 备份脚本
#!/bin/bash
backup.sh
DATE=$(date +%Y%m%d)
tar -czf /backup/openclaw-$DATE.tar.gz ~/.openclaw/
上传到对象存储
aws s3 cp /backup/openclaw-$DATE.tar.gz s3://your-bucket/
6.2 定时备份
crontab -e
0 2 <em /root/backup.sh
七、监控与告警
7.1 系统监控
安装监控工具:
apt install -y htop iotop
查看资源使用:
htop # CPU/内存
df -h # 磁盘
7.2 OpenClaw 监控
查看状态
openclaw gateway status
查看日志
openclaw logs --follow
八、性能优化
8.1 系统优化
增加 Swap:
fallocate -l 2G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
优化内核参数:
/etc/sysctl.conf
vm.swappiness=10
net.core.somaxconn=65535
8.2 OpenClaw 优化
限制历史消息:
{
channels: {
telegram: {
historyLimit: 30
}
}
}
启用缓存:
{
models: {
cache: {
enabled: true,
ttl: 3600
}
}
}
九、故障排除
9.1 常见问题
| 问题 | 解决方案 | 无法连接 |
| 服务停止 | systemctl restart openclaw-gateway
| 内存不足 | 增加 Swap、升级配置 |
9.2 日志位置
系统日志
journalctl -u openclaw-gateway
OpenClaw 日志
/tmp/openclaw/openclaw-.log
十、总结
部署检查清单:
- [ ] 选择合适 VPS
- [ ] 安装 Node.js
- [ ] 安装 OpenClaw
- [ ] 配置 Tailscale
- [ ] 配置防火墙
- [ ] 设置备份
- [ ] 配置监控
关键要点:
- VPS 提供 24/7 运行环境
- Tailscale 简化网络配置
- 安全措施必不可少
- 定期备份很重要
下一篇预告:《OpenClaw 故障排除手册:常见问题快速解决》
/* 基础样式 */
.article-container {
max-width: 100%;
margin: 0 auto;
padding: 15px;
font-family: -apple-system, BlinkMacSystemFont, “Segoe UI”, “PingFang SC”, “Hiragino Sans GB”, “Microsoft YaHei”, sans-serif;
line-height: 1.8;
color: #333;
background: #fff;
}
/* 文章头部 */
.article-header {
border-bottom: 3px solid #4a90e2;
padding-bottom: 20px;
margin-bottom: 25px;
}
.main-title {
font-size: 1.8em;
color: #1a1a1a;
margin-bottom: 12px;
font-weight: 700;
line-height: 1.3;
}
.article-meta {
display: flex;
gap: 12px;
flex-wrap: wrap;
align-items: center;
}
.category-badge {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #fff;
padding: 4px 12px;
border-radius: 16px;
font-size: 0.85em;
font-weight: 500;
}
.read-time {
color: #666;
font-size: 0.85em;
}
/* 导读框 */
.intro-box {
background: linear-gradient(135deg, #f0f4ff 0%, #e8f0fe 100%);
border-left: 4px solid #4a90e2;
padding: 18px;
margin: 20px 0;
border-radius: 0 8px 8px 0;
display: flex;
gap: 12px;
align-items: flex-start;
}
.intro-icon {
font-size: 1.8em;
flex-shrink: 0;
}
.intro-text {
margin: 0;
color: #444;
font-size: 1em;
line-height: 1.6;
}
/* 目录 */
.toc-container {
background: #f8f9fa;
border: 1px solid #e9ecef;
border-radius: 8px;
padding: 15px;
margin: 25px 0;
}
.toc-title {
font-size: 1.2em;
color: #333;
margin-bottom: 12px;
font-weight: 600;
}
.toc-list {
list-style: none;
padding: 0;
margin: 0;
}
.toc-list li {
margin: 6px 0;
}
.toc-list a {
color: #4a90e2;
text-decoration: none;
display: block;
padding: 6px 10px;
border-radius: 4px;
font-size: 0.95em;
transition: all 0.2s;
}
.toc-list a:hover {
background: #4a90e2;
color: #fff;
}
/* 文章内容 */
.article-content {
font-size: 1em;
}
.article-title {
font-size: 1.6em;
color: #1a1a1a;
margin: 35px 0 18px;
padding-bottom: 8px;
border-bottom: 2px solid #4a90e2;
}
.section-title {
font-size: 1.4em;
color: #2c3e50;
margin: 30px 0 12px;
padding-left: 12px;
border-left: 4px solid #4a90e2;
}
.subsection-title {
font-size: 1.2em;
color: #34495e;
margin: 22px 0 10px;
}
.subsubsection-title {
font-size: 1.05em;
color: #666;
margin: 18px 0 8px;
}
/* 代码块 – 支持横向滚动 */
.code-wrapper {
margin: 18px 0;
border-radius: 6px;
overflow: hidden;
}
.code-block {
background: #1e1e1e;
padding: 15px;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
margin: 0;
border-radius: 6px;
}
.code-block code {
color: #d4d4d4;
font-family: “Fira Code”, “Consolas”, “Monaco”, monospace;
font-size: 0.85em;
line-height: 1.6;
white-space: pre;
}
.inline-code {
background: #f5f5f5;
color: #e83e8c;
padding: 2px 6px;
border-radius: 3px;
font-family: “Fira Code”, “Consolas”, monospace;
font-size: 0.9em;
}
/* 表格 – 响应式滚动 */
.table-wrapper {
margin: 20px 0;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.styled-table {
width: 100%;
border-collapse: collapse;
min-width: 600px;
font-size: 0.9em;
}
.styled-table thead {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #fff;
}
.styled-table th {
padding: 12px 15px;
text-align: left;
font-weight: 600;
white-space: nowrap;
}
.styled-table td {
padding: 12px 15px;
border-bottom: 1px solid #e1e4e8;
vertical-align: top;
}
.styled-table tbody tr {
transition: background 0.2s;
}
.styled-table tbody tr:hover {
background: #f8f9fa;
}
.styled-table tbody tr:nth-child(even) {
background: #fafbfc;
}
.styled-table tbody tr:nth-child(odd) {
background: #fff;
}
/* 列表 */
.styled-list {
list-style: none;
padding: 0;
margin: 15px 0;
}
.list-item {
padding: 6px 0 6px 22px;
position: relative;
color: #333;
}
.list-item::before {
content: “•”;
position: absolute;
left: 0;
color: #4a90e2;
font-weight: bold;
font-size: 1.2em;
}
.checkbox-item {
padding: 6px 0 6px 32px;
position: relative;
color: #333;
}
.checkbox-item.checked {
color: #28a745;
}
/* 信息框 */
.info-box {
background: #e8f4fd;
border-left: 4px solid #4a90e2;
padding: 15px;
margin: 18px 0;
border-radius: 0 6px 6px 0;
color: #2c3e50;
}
/* 分隔线 */
.section-divider {
border: none;
height: 2px;
background: linear-gradient(to right, transparent, #4a90e2, transparent);
margin: 35px 0;
}
/* 文章尾部 */
.article-footer {
margin-top: 40px;
padding-top: 25px;
border-top: 2px solid #e9ecef;
}
.tags-section {
margin-bottom: 20px;
}
.tag-label {
font-weight: 600;
color: #666;
margin-right: 8px;
}
.tag {
display: inline-block;
background: #f0f4ff;
color: #4a90e2;
padding: 4px 10px;
border-radius: 12px;
margin: 3px;
font-size: 0.85em;
text-decoration: none;
transition: all 0.2s;
}
.tag:hover {
background: #4a90e2;
color: #fff;
}
.back-to-top {
text-align: center;
padding: 15px;
background: #f8f9fa;
border-radius: 6px;
}
.back-to-top a {
color: #4a90e2;
text-decoration: none;
font-weight: 500;
}
/* 移动端优化 */
@media (max-width: 768px) {
.article-container {
padding: 12px;
}
.main-title {
font-size: 1.4em;
}
.article-title {
font-size: 1.3em;
}
.section-title {
font-size: 1.2em;
}
.code-block {
padding: 12px;
font-size: 0.8em;
}
.styled-table {
font-size: 0.85em;
min-width: 500px;
}
.styled-table th,
.styled-table td {
padding: 10px 12px;
}
.intro-box {
padding: 15px;
}
.intro-icon {
font-size: 1.5em;
}
}
@media (max-width: 480px) {
.main-title {
font-size: 1.3em;
}
.article-meta {
flex-direction: column;
gap: 8px;
}
.category-badge,
.read-time {
font-size: 0.8em;
}
.code-block {
font-size: 0.75em;
padding: 10px;
}
.styled-table {
min-width: 450px;
font-size: 0.8em;
}
.styled-table th,
.styled-table td {
padding: 8px 10px;
}
}
// 移动端表格提示
document.addEventListener(‘DOMContentLoaded’, function() {
var tables = document.querySelectorAll(‘.table-wrapper’);
tables.forEach(function(table) {
if (!table.querySelector(‘.scroll-hint’)) {
var hint = document.createElement(‘div’);
hint.className = ‘scroll-hint’;
hint.innerHTML = ‘👈 左右滑动查看更多’;
hint.style.cssText = ‘text-align:center;padding:8px;background:#f8f9fa;color:#666;font-size:12px;border-radius:0 0 8px 8px;’;
table.parentNode.insertBefore(hint, table.nextSibling);
}
});
});