内容简介:本文风哥教程参考Linux官方文档、Red Hat Enterprise Linux官方文档、Ansible Automation Platform官方文档、Docker官方文档、Kubernetes官方文档和Podman官方文档等内容,详细介绍了相关技术的配置和使用方法。
风哥提示:
本文档详细介绍集群升级和迁移的方法。
Part01-集群软件升级
1.学习交流加群风哥QQ1132571741 升级前准备
[root@ha-node1 ~]# pcs –version
pcs 0.11.4
[root@ha-node1 ~]# rpm -q pacemaker corosync
pacemaker-2.1.6-1.el9.x86_64
corosync-3.1.7-1.el9.x86_64
# 备份集群配置
[root@ha-node1 ~]# pcs config backup /backup/cluster_before_upgrade.tar.gz
Cluster configuration backed up to /backup/cluster_before_upgrade.tar.gz
# 验证备份
[root@ha-node1 ~]# ls -lh /backup/cluster_before_upgrade.tar.gz
-rw-r–r–. 1 root root 2.5K Apr 4 12:45:00 /backup/cluster_before_upgrade.tar.gz
# 查看集群状态
[root@ha-node1 ~]# pcs status
Cluster name: mycluster
Cluster Summary:
* Stack: corosync
* Current DC: ha-node1 (version 2.1.6-1.el9)
* Last updated: Fri Apr 4 12:45:00 2026
* Last change: Fri Apr 4 12:40:00 2026
* 2 nodes configured
* 3 resource instances configured
Node List:
* Online: [ ha-node1 ha-node2 ]
Full List of Resources:
* vip (ocf::heartbeat:IPaddr2): Started ha-node1
* nginx (systemd:nginx): Started ha-node1
* mysql (systemd:mariadb): Started ha-node1
1.2 滚动升级节点
[root@ha-node1 ~]# pcs cluster standby ha-node2
# 验证资源已转移到node1
[root@ha-node1 ~]# pcs status resources
* vip (ocf::heartbeat:IPaddr2): Started ha-node1
* nginx (systemd:nginx): Started ha-node1
* mysql (systemd:mariadb): Started ha-node1
# 停止node2集群服务
[root@ha-node1 ~]# pcs cluster stop ha-node2
ha-node2: Stopping Cluster (pacemaker)…
ha-node2: Stopping Cluster (corosync)…
# 在node2上升级软件
[root@ha-node2 ~]# dnf update -y pacemaker corosync pcs
Updating Subscription Management repositories.
Last metadata expiration check: 0:05:23 ago on Fri Apr 4 12:45:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Upgrading:
pacemaker x86_64 2.1.7-1.el9 appstream 1.3 M
corosync x86_64 3.1.8-1.el9 appstream 290 k
pcs x86_64 0.11.5-1.el9 appstream 3.6 M
Transaction Summary
================================================================================
Upgrade 3 Packages
Total download size: 5.2 M
Downloading Packages:
(1/3): corosync-3.1.8-1.el9.x86_64.rpm 2.9 MB/s | 290 kB 00:00
(2/3): pacemaker-2.1.7-1.el9.x86_64.rpm 5.2 MB/s | from PG视频:www.itpux.com1.3 MB 00:00
(3/3): pcs-0.11.5-1.el9.x86_64.rpm 8.0 MB/s | 3.6 MB 00:00
——————————————————————————–
Total 5.2 MB/s | 5.2 MB 00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Upgrading : corosync-3.1.8-1.el9.x86_64 1/3
Upgrading : pacemaker-2.1.7-1.el9.x86_64 2/3
Upgrading : pcs-0.11.5-1.el9.x86_64 3/3
Running scriptlet: pcs-0.11.5-1.el9.x86_64 3/3
Verifying : corosync-3.1.8-1.el9.x86_64 1/3
Verifying : pacemaker-2.1.7-1.el9.x86_64 2/3
Verifying : pcs-0.11.5-1.el9.x86_64 3/3
Upgraded:
corosync-3.1.8-1.el9.x86_64 pacemaker-2.1.7-1.el9.x86_64 pcs-0.11.5-1.el9.x86_64
Complete!更多视频教程www.fgedu.net.cn
# 启动node2集群服务
[root@ha-node1 ~]# pcs cluster start ha-node2
ha-node2: Starting Cluster (corosync)…
ha-node2: Starting Cluster (pacemaker)…
# 取消node2待机模式
[root@ha-node1 ~]# pcs cluster unstandby ha-node2
# 验证node2上线
[root@ha-node1 ~]# pcs status nodes
Pacemaker Nodes:
Online: ha-node1 ha-node2
Standby:
Maintenance:
Offline:
1.3 升级剩余节点
[root@ha-node1 ~]# pcs cluster standby ha-node1
# 验证资源已转移到node2
[root@ha-node1 ~]# pcs status resources
* vip (ocf::heartbeat:IPaddr2): Started ha-node2
* nginx (systemd:nginx): Started ha-node2
* mysql (systemd:mariadb): Started ha-node2
# 停止node1集群服务
[root@ha-node1 ~]# pcs cluster stop ha-node1
ha-node1: Stopping Cluster (pacemaker)…
ha-node1: Stopping Cluster (corosync)…
# 在node1上升级软件
[root@ha-node1 ~]# dnf update -y pacemaker corosync pcs
Updating Subscription Management repositories.
Last metadata expiration check: 0:05:23 ago on Fri Apr 4 12:50:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Upgrading:
pacemaker x86_64 2.1.7-1.el9 appstream 1.3 M
corosync x86_64 3.1.8-1.el9 appstream 290 k
pcs x86_64 0.11.5-1.el9 appstream 3.6 M
Transaction Summary
================================================================================
Upgrade 3 Packages
Total download size: 5.2 M
Downloading Packages:
(1/3): corosync-3.1.8-1.el9.x86_64.rpm 2.9 MB/s | 290 kB 00:00
(2/3): pacemaker-2.1.7-1.el9.x86_64.rpm 5.2 MB/s | 1.3 MB 00:00
(3/3): pcs-0.11.5-1.el9.x86_64.rpm 8.0 MB/s | 3.6 MB 00:00
——————————————————————————–
Total 5.2 MB/s | 5.2 MB 00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Upgrading : corosync-3.1.8-1.el9.x86_64 1/3
Upgrading : pacemaker-2.1.7-1.el9.x86_64 2/3
Upgrading : pcs-0.11.5-1.el9.x86_64 3/3
Running scriptlet: pcs-0.11.5-1.el9.x86_64 3/3
Verifying : corosync-3.1.8-1.el9.x86_64 1/3
Verifying : pacemaker-2.1.7-1.el9.x86_64 2/3
Verifying : pcs-0.11.5-1.el9.x86_64 3/3
Upgraded:
corosync-3.1.8-1.el9.x86_64 pacemaker-2.1.7-1.el9.x86_64 pcs-0.11.5-1.el9.x86_64
Complete!
# 启动node1集群服务
[root@ha-node1 ~]# pcs cluster start ha-node1
ha-node1: Starting Cluster (corosync)…
ha-node1: Starting Cluster (pacemaker)…
# 取消node1待机模式
[root@ha-node1 ~]# pcs cluster unstandby ha-node1
# 验证升级后版本
[root@ha-node1 ~]# rpm -q pacemaker corosync pcs
pacemaker-2.1.7-1.el9.x86_64
corosync-3.1.8-1.el9.x86_64
pcs-0.11.5-1.el9.x86_64
# 验证集群状态
[root@ha-node1 ~]# pcs status
Cluster name: mycluster
Cluster Summary:
* Stack: corosync
* Current DC: ha-node2 (version 2.1.7-1.el9)
* Last updated: Fri Apr 4 12:55:00 2026
* Last change: Fri Apr 4 12:50:00 2026
* 2 nodes configured
* 3 resource instances configured
Node List:
* Online: [ ha-node1 ha-node2 ]
Full List of Resources:
* vip (ocf::heartbeat:IPaddr2): Started ha-node2
* nginx (systemd:nginx): Started ha-node2
* mysql (systemd:mariadb): Started ha-node2
Part02-集群迁移
2.1 迁移到新节点
[root@ha-node1 ~]# pcs cluster node add ha-node3
Sending ‘corosync authkey’, ‘pacemaker authkey’ to ‘ha-node3’
ha-node3: successful distribution of the file ‘corosync authkey’
ha-node3: successful distribution of the file ‘pacemaker authkey’
Sending ‘corosync.conf’ to ‘ha-node3’
ha-node3: successful distribution 学习交流加群风哥微信: itpux-comof the file ‘corosync.conf’
ha-node3: Succeeded
# 在新节点启动集群服务
[root@ha-node3 ~]# pcs cluster start
Starting Cluster (corosync)…
Starting Cluster (pacemaker)…
# 验证新节点加入
[root@ha-node1 ~]# pcs status nodes
Pacemaker Nodes:
Online: ha-node1 ha-node2 ha-node3
Standby:
Maintenance:
Offline:
# 将资源迁移到新节点
[root@ha-node1 ~]# pcs resource move vip ha-node3
[root@ha-node1 ~]# pcs resource move nginx ha-node3
[root@ha-node1 ~]# pcs resource move mysql ha-node3
# 验证资源迁移
[root@ha-node1 ~]# pcs status resources
* vip (ocf::heartbeat:IPaddr2): Started ha-node3
* nginx (systemd:nginx): Started ha-node3
* mysql (systemd:mariadb): Started ha-node3
# 清除移动约束
[root@ha-node1 ~]# pcs resource clear vip
[root@ha-node1 ~]# pcs resource clear nginx
[root@ha-node1 ~]# pcs resource clear mysql
2.2 移除旧节点
[root@ha-node1 ~]# pcs cluster standby ha-node1
# 停止旧节点集群服务
[root@ha-node1 ~]# pcs cluster stop ha-node1
ha-node1: Stopping Cluster (pacemaker)…
ha-node1: Stopping Cluster (corosync)…
# 从集群中移除旧节点
[root@ha-node3 ~]# pcs cluster node remove ha-node1
Attempting to stop corosync on ha-node1…
ha-node1: Stopping Cluster…
ha-node1: Successfully stopped cluster
Attempting to remove ha-node1 from cluster…
ha-node1: Successfully removed
# 验证节点移除
[root@ha-node3 ~]# pcs status nodes
Pacemaker Nodes:
Online: ha-node2 ha-node3
Standby:
Maintenance:
Offline:
# 验证集群状态
[root@ha-node3 ~]# pcs status
Cluster name: mycluster
Cluster Summary:
* Stack: corosync
* Current DC: ha-node3 (version 2.1.7-1.el9)
* Last updated: Fri Apr 4 13:00:00 2026
* Last change: Fri Apr 4 12:58:00 2026
* 2 nodes configured
* 3 resource instances configured
Node List:
* Online: [ ha-node2 ha-node3 ]
Full List of Resources:
* vip (ocf::heartbeat:IPaddr2): Started ha-node3
* nginx (systemd:nginx): Started ha-node3
* mysql (systemd:mariadb): Started ha-node3
- 升级前备份集群配置
- 使用滚动升级方式
- 先升级非主节点
- 迁移时确保资源安全
- 验证升级后集群功能
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
