🏠hoatranlab.io.vn 💬Zalo: 0917516878 📞0917516878 ✉️[email protected]

Phase 7: Cluster & High Availability

Bài 7.1: Tạo 3-node cluster

Lý thuyết cốt lõi

Proxmox Cluster dùng:

  • Corosync 3 (VE 9): message passing, consensus (Totem protocol)
  • pve-cluster (pmxcfs): FUSE filesystem đồng bộ /etc/pve giữa node

Quorum: (N/2) + 1. Cluster 3 node → quorum = 2 → chịu mất 1 node.

Corosync network:

  • Primary ring: link 0 (mặc định vmbr0)
  • Optional backup ring: link 1 (thêm link khác network)
  • Khuyến nghị: 2 link riêng biệt (corosync cần latency <5ms, <1% loss)

Bài tập thực hành

Trên node 1 (init):

pvecm create mycluster --link0 10.0.0.11 --link1 10.100.0.11
pvecm status

Trên node 2 và node 3 (join):

pvecm add 10.0.0.11 --link0 <local_ip> --link1 <local_cluster_ip>
# Nhập root password của node 1

Kiểm tra:

pvecm status
pvecm nodes
cat /etc/pve/corosync.conf

Kết quả đầu ra

$ pvecm status
Cluster information
-------------------
Name:             mycluster
Config Version:   3
Transport:        knet
Secure auth:      on

Quorum information
------------------
Date:             Wed Apr 22 11:45:23 2026
Quorum provider:  corosync_votequorum
Nodes:            3
Quorate:          Yes

Votequorum information
----------------------
Expected votes:   3
Highest expected: 3
Total votes:      3
Quorum:           2
Flags:            Quorate

Membership information
----------------------
    Nodeid      Votes Name
         1          1 pve01 (local)
         2          1 pve02
         3          1 pve03

Troubleshooting

Lỗi Nguyên nhân Fix
waiting for quorum Mạng corosync lỗi Check firewall port 5405, ping node khác
clock skew too large NTP lệch Sync NTP server chung
Join thất bại SSH key mismatch ssh-copy-id thủ công
Split-brain (2 vs 1) Network partition Node thiểu số sẽ fence, node đa số tiếp tục

Critical rule: KHÔNG BAO GIỜ chạy cluster 2 node production (mất 1 node = mất quorum). Dùng qdevice (3rd witness) hoặc tối thiểu 3 node.

Ứng dụng thực tế

Branch office 2 node: thêm qdevice trên VM nhỏ ở HQ:

apt install corosync-qnetd       # trên HQ witness
apt install corosync-qdevice     # trên 2 node branch
pvecm qdevice setup <hq_ip>

→ Vote count = 3, mất 1 node vẫn quorate.


Bài 7.2: High Availability (HA) và HA Rules (VE 9)

Lý thuyết cốt lõi

HA trong Proxmox = VM tự động khởi động lại ở node khác khi node gốc chết.

VE 8 dùng HA Groups (deprecated VE 9) → VE 9 dùng HA Rules linh hoạt hơn:

  • Node Affinity: VM chạy trên node X, fallback Y, Z
  • Resource Affinity: 2 VM phải cùng node (app + cache) HOẶC khác node (DB master/slave)

Fencing: node "chết" phải được fence (reset) trước khi VM restart ở node khác — tránh split-brain.

Bài tập thực hành

Enable HA cho VM 100:

# Web GUI: Datacenter > HA > Add
# CLI:
ha-manager add vm:100 --state started --max_restart 3 --max_relocate 2

# Tạo HA Rule: VM 100 ưu tiên pve01, fallback pve02
pvesh create /cluster/ha/rules --rule vm-100-pref \
    --type node-affinity \
    --resources 100 \
    --nodes 'pve01:10,pve02:5,pve03:1'

Test failover:

# Giả lập pve01 chết: unplug network hoặc power off
# → sau ~60 giây, VM 100 restart trên pve02

ha-manager status

Kết quả đầu ra

$ ha-manager status
quorum OK
master pve02 (active, Wed Apr 22 11:55:00 2026)
lrm pve01 (lost agent lock, Wed Apr 22 11:54:30 2026)
lrm pve02 (active, Wed Apr 22 11:55:00 2026)
lrm pve03 (idle, Wed Apr 22 11:55:00 2026)
service vm:100 (pve02, started)

Troubleshooting

  • VM không failover: check ha-manager status, /var/log/daemon.log grep "ha-manager"
  • Fence loop: node liên tục fence → kiểm tra corosync link, storage shared
  • Watchdog hardware: ưu tiên hw watchdog (IPMI) hơn softdog

Ứng dụng thực tế

VM database mission-critical: HA + ZFS replication 5 phút tới node thứ 2 → RTO 2 phút, RPO 5 phút.


Bài 7.3: Live migration VM giữa node

Lý thuyết cốt lõi

Live migration: chuyển VM đang chạy từ node A sang node B, downtime <1 giây.

Yêu cầu:

  • VM dùng shared storage (Ceph/NFS) → migrate nhanh (chỉ RAM)
  • Hoặc local storage → migrate cả disk (chậm hơn)

Bài tập thực hành

# Shared storage (Ceph/NFS) — chỉ chuyển RAM
qm migrate 100 pve02 --online

# Local storage — chuyển cả disk
qm migrate 100 pve02 --online --with-local-disks

# Offline migrate (VM stopped)
qm migrate 100 pve02

Kết quả đầu ra

$ qm migrate 100 pve02 --online
2026-04-22 12:00:05 starting migration of VM 100 to node 'pve02' (10.0.0.12)
2026-04-22 12:00:05 starting VM 100 on remote node 'pve02'
2026-04-22 12:00:08 start remote tunnel
2026-04-22 12:00:09 ssh tunnel ver 1
2026-04-22 12:00:09 starting online/live migration on unix:/run/qemu-server/100.migrate
2026-04-22 12:00:09 migration speed limit: 8589.93 MiB/s
2026-04-22 12:00:10 migration downtime limit: 100 ms
2026-04-22 12:00:38 migration status: completed
2026-04-22 12:00:38 migration finished successfully (duration 00:00:33)

Troubleshooting

  • CPU feature mismatch: host CPU khác → chọn --cpu host không work, đổi --cpu qemu64 hoặc x86-64-v3
  • Migration tunnel timeout: network quá chậm → tăng migrate_speed trong datacenter config

Ứng dụng thực tế

Patching Proxmox host: migrate tất cả VM khỏi node → reboot host → migrate lại. Không downtime cho user.