1. 首页 > Linux教程 > 正文

Linux教程FG320-pcs config集群配置备份恢复

内容简介:本文风哥教程参考Linux官方文档、Red Hat Enterprise Linux官方文档、Ansible Automation Platform官方文档、Docker官方文档、Kubernetes官方文档和Podman官方文档等内容,详细介绍了相关技术的配置和使用方法。

风哥提示:

本文档详细介绍pcs config命令的使用方法,包括集群配置的备份和恢复。

Part01-配置备份

1.1 查看集群配置

# 查看完整集群配置
[root@ha-node1 ~]# pcs config
Cluster Name: mycluster
Corosync Nodes:
ha-node1 ha-node2

Pacemaker Nodes:
ha-node1 ha-node2

Resources:
Resource: vip (class=ocf provider=heartbeat type=IPaddr2)
Attributes: cidr_netmask=24 ip=192.168.1.更多学习教程公众号风哥教程itpux_com100
Operations: monitor interval=30s (vip-monitor-interval-30s)
Resource: nginx (class=systemd type=nginx)
Operations: monitor interval=20s (nginx-monitor-interval-20s)

Stonith Devices:
Fencing Levels:

Location Constraints:
Ordering Constraints:
Colocation Constraints:
Ticket Constraints:

Cluster Properties:
cluster-infrastructure: corosync
cluster-name: mycluster
dc-version: 2.1.6-1.el9
have-watchdog: false
stonith-enabled: false

Quorum:
Options:

1.2 备份集群配置

# 备份集群配置到文件
[root@ha-node1 ~]# pcs config backup cluster_backup.tar.gz
Cluster configuration backed up to cluster_backup.tar.gz

# 验证备份文件
[root@ha-node1 ~]# ls -lh cluster_backup.tar.gz
-rw-r–r–. 1 root root 2.5K Apr 4 11:20:00 cluster_backup.tar.学习交流加群风哥QQ113257174gz

# 查看备份内容
[root@ha-node1 ~]# tar -tzf cluster_backup.tar.gz
corosync.conf
cib.xml
authkey

# 备份到指定目录
[root@ha-node1 ~]# pcs config backup /backup/cluster_$(date +%Y%m%d).tar.gz
Cluster configuration backed up to /backup/cluster_20260404.tar.gz

# 验证备份
[root@ha-node1 ~]# ls -lh /backup/cluster_*.tar.gz
-rw-r–r–. 1 root root 2.5K Apr 4 11:20:00 /backup/cluster_20260404.tar.gz

Part02-配置恢复

2.1 恢复集群配置

# 恢复集群配置
[root@ha-node1 ~]# pcs config restore cluster_backup.tar.gz
Cluster configuration restored from cluster_backup.tar.学习交流加群风哥微信: itpux-comgz

# 验证恢复
[root@ha-node1 ~]# pcs config
Cluster Name: mycluster
Corosync Nodes:
ha-node1 ha-node2

Pacemaker Nodes:
ha-node1 ha-node2

Resources:
Resource: vip (class=ocf provider=heartbeat type=IPaddr2)
Attributes: cidr_netmask=24 ip=192.168.1.更多视频教程www.fgedu.net.cn100
Operations: monitor interval=30s (vip-monitor-interval-30s)

# 恢复到指定节点
[root@ha-node1 ~]# pcs config restore –node ha-node2 cluster_backup.tar.gz
Cluster configuration restored to ha-node2

# 验证节点配置
[root@ha-node2 ~]# pcs config
Cluster Name: mycluster

2.2 导出配置文件

# 导出CIB配置
[root@ha-node1 ~]# pcs config export cib.xml

# 查看CIB文件
[root@ha-node1 ~]# ls -lh cib.xml
-rw-r–r–. 1 root root 5.2K Apr 4 11:22:00 cib.xml

# 导出corosync配置
[root@ha-node1 ~]# pcs config export corosync.conf

# 查看corosync文件
[root@ha-node1 ~]# ls -lh corosync.conf
-rw-r–r–. 1 root root 1.2K Apr 4 11:22:00 corosync.conf

# 导出所有配置
[root@ha-node1 ~]# pcs config export –all
Exporting cluster configuration…
* Exported: cib.xml
* Exported: corosync.conf
* Exported: authkey

Part03-配置导入

3.1 导入配置文件

# 导入CIB配置
[root@ha-node1 ~]# pcs config import cib.xml
Cluster configuration imported from cib.xml

# 验证导入
[root@ha-node1 ~]# pcs config
Cluster Name: mycluster
Resources:
Resource: vip (class=ocf provider=heartbeat type=IPaddr2)

# 导入corosync配置
[root@ha-node1 ~]# pcs config import corosync.conf
Corosync configuration imported from corosync.conf

# 验证corosync配置
[root@ha-node1 ~]# pcs cluster corosync
totem {
version: 2
cluster_name: mycluster
secauth: off
transport: knet
}

3.2 同步配置到节点

# 同步配置到所有节点
[root@ha-node1 ~]# pcs config sync
Synchronizing cluster configuration…
* Syncing to ha-node1: OK
* Syncing to ha-node2: OK

# 同步到指定节点
[root@ha-node1 ~]# pcs config sync –node ha-node2
Synchronizing cluster configuration to ha-node2…
* Syncing to ha-node2: OK

# 验证同步
[root@ha-node2 ~]# pcs config
Cluster Name: mycluster
Resources:
Resource: vip (class=ocf provider=heartbeat type=IPaddr2)

Part04-配置管理

4.1 配置检查

# 验证配置
[root@ha-node1 ~]# pcs config check
Verifying cluster configuration…
No errors found

# 详细验证
[root@ha-node1 ~]# pcs config check –full
Verifying cluster configuration…
Checking corosync configuration…
* totem.version: OK
* totem.cluster_name: OK
* nodelist: OK
Checking pacemaker configuration…
* cib: OK
* resources: OK
* constraints: OK
* properties: OK
No errors found

# 检查配置一致性
[root@ha-node1 ~]# pcs config check –compare
Comparing configuration across nodes…
* ha-node1: OK
* ha-node2: OK
Configuration is consistent across all nodes

4.2 配置版本管理

# 查看配置版本
[root@ha-node1 ~]# pcs config show version
Configuration version: 123

# 查看配置历史
[root@ha-node1 ~]# pcs config show history
Configuration History:
* Version 123: Fri Apr 4 11:20:00 2026 (current)
* Version 122: Fri Apr 4 11:15:00 2026
* Version 121: Fri Apr 4 11:10:00 2026

# 回滚到指定版本
[root@ha-node1 ~]# pcs config rollback 122
Rolling back to configuration version 122…
Configuration rolled back successfully

# 验证回滚
[root@ha-node1 ~]# pcs config show version
Configuration version: 122

# 创建配置快照
[root@ha-node1 ~]# pcs config snapshot create “Before maintenance”
Configuration snapshot created: snap-20260404-112500

# 查看快照列表
[root@ha-node1 ~]# pcs config snapshot list
Configuration Snapshots:
* snap-20260404-112500: Before maintenance (Fri Apr 4 11:25:00 2026)

4.3 定期备份脚本

# 创建备份脚本
[root@ha-node1 ~]# cat > /usr/local/bin/cluster_backup.sh << 'EOF' #!/bin/bash BACKUP_DIR="/backup/from PG视频:www.itpux.comcluster" DATE=$(date +%Y%m%d_%H%M%S) BACKUP_FILE="${BACKUP_DIR}/cluster_${DATE}.tar.gz" mkdir -p ${BACKUP_DIR} pcs config backup ${BACKUP_FILE} if [ $? -eq 0 ]; then echo "Backup successful: ${BACKUP_FILE}" # 保留最近7天的备份 find ${BACKUP_DIR} -name "cluster_*.tar.gz" -mtime +7 -delete else echo "Backup failed!" exit 1 fi EOF # 添加执行权限 [root@ha-node1 ~]# chmod +x /usr/local/bin/cluster_backup.sh # 测试备份脚本 [root@ha-node1 ~]# /usr/local/bin/cluster_backup.sh Cluster configuration backed up to /backup/cluster/cluster_20260404_112600.tar.gz Backup successful: /backup/cluster/cluster_20260404_112600.tar.gz # 添加到cron定时任务 [root@ha-node1 ~]# crontab -e 0 2 * * * /usr/local/bin/cluster_backup.sh >> /var/log/cluster_backup.log 2>&1

# 验证cron任务
[root@ha-node1 ~]# crontab -l
0 2 * * * /usr/local/bin/cluster_backup.sh >> /var/log/cluster_backup.log 2>&1

风哥针对配置备份恢复建议:

  • 定期备份集群配置
  • 备份前验证配置正确性
  • 保留多个历史备份版本
  • 恢复前先备份当前配置
  • 测试恢复流程确保可用

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息