1) Kiến trúc đích
| Service | Domain mới | Port local | Ghi chú |
|---|---|---|---|
| OpenClaw Gateway / Control UI | bot.vinhmkt.net | 127.0.0.1:18789 | Không mở public trực tiếp port 18789 |
| 9router | 9router.vinhmkt.net | 127.0.0.1:20128 | Dashboard + API qua nginx |
| YouTube Analyzer V12 | yt.vinhmkt.net | 127.0.0.1:3002 | Chạy bằng systemd service |
2) Điều kiện cần trước khi chạy
- VPS mới là Linux có systemd (Ubuntu/Debian là đẹp nhất).
- Đã có quyền root SSH vào VPS mới.
- Đã quản lý được DNS của
vinhmkt.net. - Đã trỏ DNS của
bot.vinhmkt.net,9router.vinhmkt.net,yt.vinhmkt.netvề IP VPS mới. - VPS mới mở inbound tối thiểu
80/tcpvà443/tcp. - VPS mới SSH được sang VPS cũ bằng root hoặc user đủ quyền đọc các thư mục nguồn.
- VPS cũ vẫn đang là source of truth và chưa bị sửa linh tinh thêm.
command -v ufw >/dev/null 2>&1 && ufw allow 80/tcp
command -v ufw >/dev/null 2>&1 && ufw allow 443/tcp
command -v ufw >/dev/null 2>&1 && ufw status || trueNếu VPS mới đang dùng UFW, chạy block trên để đảm bảo web + SSL truy cập được từ ngoài vào. Nếu máy không cài UFW thì block này sẽ tự bỏ qua. Không cần mở public các port nội bộ như 18789, 20128, 3002.
Nếu thiếu một trong các điều kiện trên, nhiều lệnh bên dưới sẽ chạy lỗi hoặc restore ra trạng thái nửa vời.
3) Biến cần thay trước khi copy-paste
Thay các giá trị này trước khi chạy lệnh:
OLD_VPS_IP=<OLD_VPS_IP>
NEW_VPS_IP=<IP_VPS_MOI>
NEW_DOMAIN_BOT=bot.vinhmkt.net
NEW_DOMAIN_ROUTER=9router.vinhmkt.net
NEW_DOMAIN_YT=yt.vinhmkt.net4) Bước 1 — Chuẩn bị DNS
Tạo 3 bản ghi A:
bot.vinhmkt.net A <IP_VPS_MOI>
9router.vinhmkt.net A <IP_VPS_MOI>
yt.vinhmkt.net A <IP_VPS_MOI>Kiểm tra DNS đã ăn chưa:
dig +short bot.vinhmkt.net
dig +short 9router.vinhmkt.net
dig +short yt.vinhmkt.netPhải ra đúng IP của VPS mới.
5) Bước 2 — Chuẩn bị base VPS mới
apt-get update
apt-get install -y curl git rsync nginx certbot python3-certbot-nginx ca-certificatescurl -fsSL https://deb.nodesource.com/setup_22.x | bash -
apt-get install -y nodejs
node -v
npm -vnpm install -g openclaw@2026.4.1
openclaw --versionKhuyến nghị mạnh: VPS mới nên cài đúng OpenClaw 2026.4.1 trước để clone lõi giống hệt hệ đang chạy. Không nên nhảy version mới ngay trong bước migrate ban đầu.
mkdir -p /opt/diemmy/workspace
mkdir -p /opt/9router
mkdir -p /opt/youtube-analyzer-v12
mkdir -p /root/.openclaw
mkdir -p /root/.config/systemd/user/openclaw-gateway.service.d6) Bước 3 — Copy lõi từ VPS cũ
Các lệnh này chạy trên VPS mới.
ssh root@<OLD_VPS_IP> 'echo SSH_OK'Nếu chưa ra SSH_OK thì đừng chạy rsync vội, kẻo đứng giữa đường rồi ngơ người luôn anh ạ.
rsync -aHAX --info=progress2 root@<OLD_VPS_IP>:/opt/diemmy/workspace/ /opt/diemmy/workspace/
rsync -aHAX --info=progress2 root@<OLD_VPS_IP>:/root/.openclaw/ /root/.openclaw/
rsync -aHAX --info=progress2 root@<OLD_VPS_IP>:/var/lib/9router/ /var/lib/9router/
rsync -aHAX --info=progress2 root@<OLD_VPS_IP>:/opt/9router/ /opt/9router/
rsync -aHAX --info=progress2 root@<OLD_VPS_IP>:/opt/youtube-analyzer-v12/ /opt/youtube-analyzer-v12/
rsync -aHAX root@<OLD_VPS_IP>:/etc/systemd/system/9router.service /etc/systemd/system/9router.service
rsync -aHAX root@<OLD_VPS_IP>:/etc/systemd/system/youtube-analyzer-v12.service /etc/systemd/system/youtube-analyzer-v12.service
rsync -aHAX root@<OLD_VPS_IP>:/root/.config/systemd/user/ /root/.config/systemd/user/ls -la /opt/diemmy/workspace | head
ls -la /root/.openclaw | head
ls -la /opt/9router | head
ls -la /opt/youtube-analyzer-v12 | head
ls -la /etc/systemd/system/9router.service
ls -la /etc/systemd/system/youtube-analyzer-v12.service
ls -la /root/.config/systemd/user/openclaw-gateway.service7) Bước 4 — Chỉnh cấu hình domain mới
cp /root/.openclaw/openclaw.json /root/.openclaw/openclaw.json.before-vinhmkt-migration
cp /opt/9router/.env /opt/9router/.env.before-vinhmkt-migration 2>/dev/null || truegrep -Rni "nvv.io.vn" /root/.openclaw/openclaw.json /opt/diemmy/workspace 2>/dev/null | head -100perl -0pi -e 's#https://bot\.nvv\.io\.vn#https://bot.vinhmkt.net#g' /root/.openclaw/openclaw.json
perl -0pi -e 's#https://9router\.nvv\.io\.vn#https://9router.vinhmkt.net#g' /root/.openclaw/openclaw.json
perl -0pi -e 's#https://yt\.nvv\.io\.vn#https://yt.vinhmkt.net#g' /root/.openclaw/openclaw.jsonopenclaw.json có key gateway.controlUi.allowedOrigins — phải đổi hết domain cũ sang domain mới ở đây nữa, nếu không Control UI sẽ bị CORS chặn khi truy cập qua bot.vinhmkt.net.grep -n "vinhmkt.net" /root/.openclaw/openclaw.json || truegrep -Rni "nvv.io.vn" /root/.openclaw /opt/9router /opt/diemmy/workspace /opt/youtube-analyzer-v12 2>/dev/null | head -2008) Bước 5 — Khởi động service lõi
loginctl enable-linger root
systemctl --user daemon-reload
systemctl --user enable openclaw-gateway
systemctl --user restart openclaw-gateway
systemctl --user status openclaw-gateway --no-pager
curl -s http://127.0.0.1:18789/health
openclaw status --deepsystemctl daemon-reload
systemctl enable 9router
systemctl restart 9router
systemctl status 9router --no-pager
ss -ltnp | grep ':20128\b' || true
curl -I http://127.0.0.1:20128systemctl daemon-reload
systemctl enable youtube-analyzer-v12
systemctl restart youtube-analyzer-v12
systemctl status youtube-analyzer-v12 --no-pager
ss -ltnp | grep ':3002\b' || true
curl -fsS http://127.0.0.1:3002/api/health9) Bước 6 — Dựng nginx reverse proxy
cat > /etc/nginx/sites-available/bot.vinhmkt.net <<'EOF'
server {
listen 80;
listen [::]:80;
server_name bot.vinhmkt.net;
location / {
proxy_pass http://127.0.0.1:18789;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
EOFcat > /etc/nginx/sites-available/9router.vinhmkt.net <<'EOF'
server {
listen 80;
listen [::]:80;
server_name 9router.vinhmkt.net;
location / {
proxy_pass http://127.0.0.1:20128;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
EOFcat > /etc/nginx/sites-available/yt.vinhmkt.net <<'EOF'
server {
listen 80;
listen [::]:80;
server_name yt.vinhmkt.net;
location / {
proxy_pass http://127.0.0.1:3002;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
EOFln -sf /etc/nginx/sites-available/bot.vinhmkt.net /etc/nginx/sites-enabled/bot.vinhmkt.net
ln -sf /etc/nginx/sites-available/9router.vinhmkt.net /etc/nginx/sites-enabled/9router.vinhmkt.net
ln -sf /etc/nginx/sites-available/yt.vinhmkt.net /etc/nginx/sites-enabled/yt.vinhmkt.net
/usr/sbin/nginx -t
systemctl reload nginx10) Bước 7 — Xin SSL
- DNS đã trỏ đúng về VPS mới
- nginx đang trả được HTTP port 80
- port 80 và 443 không bị firewall chặn
certbot --nginx -d bot.vinhmkt.net -d 9router.vinhmkt.net -d yt.vinhmkt.netsystemctl status certbot.timer --no-pager || true11) Bước 8 — Verify đầy đủ
ss -ltnp | grep -E ':(18789|20128|3002)\b' || trueopenclaw status --deep
openclaw cron list
openclaw memory status --deepsystemctl status 9router --no-pager
curl -I -L https://9router.vinhmkt.netsystemctl status youtube-analyzer-v12 --no-pager
curl -fsS http://127.0.0.1:3002/api/health
curl -I -L https://yt.vinhmkt.net
curl -I -L https://yt.vinhmkt.net/api/healthcurl -I -L https://bot.vinhmkt.netsystemctl is-enabled 9router
systemctl is-enabled youtube-analyzer-v12
systemctl --user is-enabled openclaw-gateway- Không có failed unit (
systemctl --failed) - OpenClaw status lên bình thường, channels connected
- 9router có service + endpoint + dashboard truy cập được
- YouTube Analyzer có
200và/api/healthOK - Domain mới đều truy cập được qua HTTPS
- Cả 3 service đều
enabled(auto-start sau reboot)
12) Lỗi thường gặp
Case 1 — systemctl --user không chạy ổn
Nguyên nhân thường là chưa bật linger cho root hoặc user manager chưa lên đúng.
loginctl enable-linger root
loginctl show-user root
systemctl --user daemon-reload
systemctl --user status openclaw-gateway --no-pager
journalctl --user -u openclaw-gateway -n 100 --no-pagerCase 2 — 9router lên service nhưng route/combo lỗi
Thường do thiếu env/db/auth state từ VPS cũ.
systemctl status 9router --no-pager
ss -ltnp | grep ':20128\b' || true
curl -I http://127.0.0.1:20128Case 3 — YouTube Analyzer lên service nhưng API lỗi
Thường do thiếu .env hoặc DB auth/data chưa copy đủ.
systemctl status youtube-analyzer-v12 --no-pager
curl -fsS http://127.0.0.1:3002/api/health
ls -la /opt/youtube-analyzer-v12
ls -la /opt/youtube-analyzer-v12/dataCase 4 — nginx -t báo command not found
Dùng full path:
/usr/sbin/nginx -t
systemctl reload nginx13) Rollback nếu có vấn đề
Điểm mạnh của kế hoạch này: VPS cũ và domain cũ vẫn sống riêng, nên rollback rất nhẹ.
# Không cần đụng VPS cũ.
# Nếu VPS mới có lỗi:
# 1) dừng service lỗi trên VPS mới
# 2) chỉnh tiếp nội bộ
# 3) test lại bằng domain mới
# production cũ vẫn an toàn14) Bản siêu ngắn để copy-paste
apt-get update
apt-get install -y curl git rsync nginx certbot python3-certbot-nginx ca-certificates
curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
apt-get install -y nodejs
npm install -g openclaw@2026.4.1
mkdir -p /opt/diemmy/workspace /opt/9router /opt/youtube-analyzer-v12 /root/.openclaw /root/.config/systemd/user/openclaw-gateway.service.d /var/lib/9router
ssh root@<OLD_VPS_IP> 'echo SSH_OK'
rsync -aHAX root@<OLD_VPS_IP>:/opt/diemmy/workspace/ /opt/diemmy/workspace/
rsync -aHAX root@<OLD_VPS_IP>:/root/.openclaw/ /root/.openclaw/
rsync -aHAX root@<OLD_VPS_IP>:/opt/9router/ /opt/9router/
rsync -aHAX root@<OLD_VPS_IP>:/var/lib/9router/ /var/lib/9router/
rsync -aHAX root@<OLD_VPS_IP>:/opt/youtube-analyzer-v12/ /opt/youtube-analyzer-v12/
rsync -aHAX root@<OLD_VPS_IP>:/etc/systemd/system/9router.service /etc/systemd/system/9router.service
rsync -aHAX root@<OLD_VPS_IP>:/etc/systemd/system/youtube-analyzer-v12.service /etc/systemd/system/youtube-analyzer-v12.service
rsync -aHAX root@<OLD_VPS_IP>:/root/.config/systemd/user/ /root/.config/systemd/user/
loginctl enable-linger root
systemctl --user daemon-reload
systemctl --user enable openclaw-gateway
systemctl --user restart openclaw-gateway
systemctl daemon-reload
systemctl enable 9router
systemctl restart 9router
systemctl enable youtube-analyzer-v12
systemctl restart youtube-analyzer-v12