Triển Khai Mô Hình Lưu Trú Phân Tán Glusterfs Hỗ Trợ Tính Năng Cao Available Cho Máy Ảo KVM

Môi Trường Phần Mềm và Network

Nhóm Nhiệm VụHệ Điều HànhHostname / IPDịch Vụ Chủ Đạo
Nút Lưu Trú GlusterFSCentOS 7.9gfs-peer-a / 192.168.10.101glusterfs-server 3.10.2
Nút Lưu Trú GlusterFSCentOS 7.9gfs-peer-b / 192.168.10.102glusterfs-server 3.10.2
Nút Lưu Trú GlusterFSCentOS 7.9gfs-peer-c / 192.168.10.103glusterfs-server 3.10.2
Nút Lưu Trú GlusterFSCentOS 7.9gfs-peer-d / 192.168.10.104glusterfs-server 3.10.2
Trình Quản Lý KVM Client 1CentOS 7.9hv-comp-01 / 192.168.10.201libvirt + gluster-fuse
Trình Quản Lý KVM Client 2CentOS 7.9hv-comp-02 / 192.168.10.202libvirt + gluster-fuse

Yêu Cầu Nghiệp Vụ

  1. Thiết lập hệ thống tệp tin phân tán GlusterFS đảm bảo sao chép dữ liệu theo cặp.
  2. Khảo bảo tính liên tục hoạt động của máy ảo KVM khi một trong các máy chủ vật lý gặp sự cố mất điện hoặc treo hệ thống.

Chiến Lược Kiến Trúc

  1. Cài đặt nền tảng virtualization KVM trên hai host mục tiêu.
  2. Bố trí dịch vụ GlusterFS lên bốn node lưu trữ.
  3. Gắn kết tài nguyên mạng volume về thư mục chung tại các host KVM.
  4. Lưu trữ ảnh đĩa (.qcow2) và file định nghĩa cấu hình (.xml) vào vùng shared, kích hoạt khả năng failover thông qua cluster manager.

Quy Trình Thi Công

1. Khởi Tạo Cụm Lưu Trú Phân Tán

Tắt tường lửa và SELinux trên toàn bộ node để tránh xung đột cổng:

systemctl disable --now firewalld
setenforce 0
sed -i 's/^SELINUX=.*/SELINUX=permissive/' /etc/selinux/config

Đồng bộ DNS nội bộ:

# /etc/hosts
192.168.10.101 gfs-peer-a
192.168.10.102 gfs-peer-b
192.168.10.103 gfs-peer-c
192.168.10.104 gfs-peer-d
192.168.10.201 hv-comp-01
192.168.10.202 hv-comp-02

Cài đặt gói lõi GlusterFS từ kho phần mềm địa phương:

yum -y install centos-release-gluster
yum clean all && yum makecache
yum -y install glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma

Kích hoạt daemon và thiết lập quan hệ peer trên node khởi đầu (gfs-peer-a):

systemctl enable --now glusterd.service
gluster peer probe gfs-peer-b
gluster peer probe gfs-peer-c
gluster peer probe gfs-peer-d
gluster peer status

Tạo partition chuẩn bị dữ liệu và định nghĩa volume dạng Replica 2 trải dài 4 node:

mkdir -p /srv/gluster-volume
# Thực thi mkdir tương tự trên gfs-peer-b, c, d
gluster volume create data-share replica 2 gfs-peer-a:/srv/gluster-volume gfs-peer-b:/srv/gluster-volume gfs-peer-c:/srv/gluster-volume gfs-peer-d:/srv/gluster-volume force
gluster volume info data-share
gluster volume start data-share

2. Tích Hợp Shared Storage Vào Host Compute

Cấu hình client挂载 và định nghĩa fstab cho persistence mount:

yum -y install glusterfs-client
mkdir -p /mnt/guest-pool
mount.glusterfs gfs-peer-a:data-share /mnt/guest-pool

cat >> /etc/fstab <<EOF
gfs-peer-a:data-share   /mnt/guest-pool   glusterfs   defaults,_netdev   0 0
EOF
df -Th /mnt/guest-pool</code>

Chuẩn bị môi trường ssh không mật khẩu giữa các compute host phục vụ lệnh live migration:

for host in hv-comp-01 hv-comp-02; do
  ssh-keyscan $host >> ~/.ssh/known_hosts
  ssh-copy-id root@$host
done

Tạo mới instance máy ảo dựa trên template qcow2 đã copy sang vùng shared:

cp /opt/templates/CentOS-7-x86_64-GenericCloud.qcow2 /mnt/guest-pool/vm-workload-01.qcow2
virt-customize -a /mnt/guest-pool/vm-workload-01.qcow2 --root-password password:SecureP@ss2024

virt-install \
  --name vm-workload-01 \
  --ram 2048 --vcpus 2 \
  --disk path=/mnt/guest-pool/vm-workload-01.qcow2,format=qcow2,bus=virtio,size=20 \
  --network bridge=br0,model=virtio \
  --graphics none --console pty,target_type=serial \
  --import --noautoconsole

3. Chuẩn Hóa Cấu Hình Định Dạng Tài Nguyên

Toàn bộ metadata xml của libvirt cần được đặt trong đường dẫn chung để bất kỳ node nào cũng có thể truy xuất:

mkdir -p /mnt/guest-pool/config-xml
virsh dumpxml vm-workload-01 > /mnt/guest-pool/config-xml/vm-workload-01.xml
virsh destroy vm-workload-01
virsh undefine vm-workload-01

4. Xây Dựng Lớp Cluster Quản Lý Tự Động

Trên cả hai compute node, cài đặt bộ công cụ pcs/pacemaker/corosync:

yum -y install pcs pacemaker fence-agents-all policycoreutils-python-utils
passwd hacluster # Đặt mật khẩu trùng nhau cho user quản trị cụm
systemctl enable --now pcsd

Kết nối xác thực và sinh topology cluster:

pcs cluster auth hv-comp-01 hv-comp-02 -u hacluster -p SecureP@ss2024
pcs cluster setup --name kvm-ha-cluster hv-comp-01 hv-comp-02
pcs cluster start --all
pcs cluster enable --all

Vô hiệu hóa cơ chế STONITH tạm thời do môi trường lab chưa tích hợp hardware fence device:

pcs property set stonith-enabled=false

Khai báo resource kiểu VirtualDomain trỏ tới file xml đã lưu ở bước trước:

pcs resource create vm-app VirtualDomain \
  hypervisor="qemu:///system" \
  config="/mnt/guest-pool/config-xml/vm-workload-01.xml" \
  migration_transport=ssh \
  meta allow-migrate=true

5. Kiểm Chứng Cơ Chế Failover

Xóa ràng buộc pin node hiện tại cho phép dịch chuyển linh hoạt:

pcs constraint remove location-vm-app 2>/dev/null || true
pcs constraint show

Di chuyển thủ công resource sang host thứ hai:

pcs resource move vm-app hv-comp-02
# Hoặc sử dụng tie-break nếu cần ưu tiên node đích

Kiểm tra trạng thái vận hành sau khi thực thi relocate:

# Tại hv-comp-01
virsh list --all | grep vm-workload-01
pcs status | grep vm-app

# Tại hv-comp-02
virsh list --all | grep vm-workload-01
pcs status | grep vm-app

Mô phỏng sự cố bằng cách tắt tiến trình corosync/pacemaker trên node đang chạy:

pcs cluster stop hv-comp-02

Xác nhận cluster manager tự động khôi phục và khởi động lại service tại node còn sống:

# Tại hv-comp-01
pcs status
virsh list --all

# Sau khi khôi phục node bị ngắt kết nối
pcs cluster start hv-comp-02
pcs cluster enable hv-comp-02
pcs cluster restart --all

Thẻ: glusterfs libvirt Pacemaker Corosync Live Migration

Đăng vào ngày 26 tháng 9 lúc 13:14