1. 首页 > Linux教程 > 正文

Linux教程FG312-pcs cluster集群管理命令

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

本文档详细介绍pcs cluster命令的

风哥提示:

使用方法,包括集群创建、启动、停止和管理等操作。

Part01-集群创建命令

1.1 创建集群

# 创建集群
[root@ha-node1 ~]# pcs cluster setup mycluster ha-node1 ha-node2 –force
Destroying cluster on hosts: ‘ha-node1’, ‘ha-node2’…
ha-node2: Successfully destroyed cluster
ha-node1: Successfully destroyed cluster
Requesting remove ‘pcsd settings’ from ‘ha-node1’, ‘ha-node2’
ha-node1: successful removal of the file ‘pcsd settings’
ha-node2: successful removal of the file ‘pcsd settings’
Sending ‘corosync authkey’, ‘pacemaker authkey’ to ‘ha-node1’, ‘ha-node2’
ha-node1: successful distribution of the file ‘corosync authkey’
ha-node1: successful distribution of the file ‘pacemaker authkey’
ha-node2: successful distribution of the file ‘corosync authkey’
ha-node2: successful distribution of the file ‘pacemaker authkey’
Sending ‘corosync.conf’ to ‘ha-node1’, ‘ha-from PG视频:www.itpux.comnode2’
ha-node1: successful distribution of the file ‘corosync.conf’
ha-node2: successful distribution of the file ‘corosync.conf’
Cluster has been successfully set up.

# 创建集群时指定地址
[root@ha-node1 ~]# pcs cluster setup mycluster \
ha-node1 addr=192.168.1.10 \
ha-node2 addr=192.168.1.11

# 创建集群时指定仲裁设备
[root@ha-node1 ~]# pcs cluster setup mycluster ha-node1 ha-node2 ha-node3

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

Resources:
Stonith Devices:
Fencing Levels:

Part02-集群启动停止

2.1 启动集群

# 启动所有节点
[root@ha-node1 ~]# pcs cluster start –all
ha-node1: Starting Cluster (corosync)…
ha-node1: Starting Cluster (pacemaker)…
ha-node2: Starting Cluster (corosync)…
ha-node2: Starting Cluster (pacemaker)…

# 启动单个节点
[root@ha-node1 ~]# pcs cluster start ha-node1
ha-node1: Starting Cluster (corosync)…
ha-node1: Starting Cluster (pacemaker)…

# 启动本地节点
[root@ha-node1 ~]# pcs cluster start
Starting Cluster (corosync)…
Starting Cluster (pacemaker)…

# 启用集群开机自启
[root@ha-node1 ~]# pcs cluster enable –all
ha-node1: Cluster Enabled
ha-node2: Cluster Enabled

# 查看集群状态
[root@ha-node1 ~]# pcs status cluster
Cluster Status:
Cluster Summary:
* Stack: corosync
* Current DC: ha-node1 (version 2.1.6-1.el9)
* Last updated: Fri Apr 4 10:30:00 2026
* Last change: Fri Apr 4 10:25:00 2026
* 2 nodes configured
* 0 resource instances configured

2.2 停止集群

# 停止所有节点
[root@ha-node1 ~]# pcs cluster stop –all
ha-node1: Stopping Cluster (pacemaker)…
ha-node1: Stopping Cluster (corosync)…
ha-node2: Stopping Cluster (pacemaker)…
ha-node2: Stopping Cluster (corosync)…

# 停止单个节点
[root@ha-node1 ~]# pcs cluster stop ha-node2
ha-node2: Stopping Cluster (pacemaker)…
ha-node2: Stopping Cluster (corosync)…

# 停止本地节点
[root@ha-node1 ~]# pcs cluster stop
Stopping Cluster (pacemaker)…
Stopping Cluster (corosync)…

# 禁用集群开机自启
[root@ha-node1 ~]# pcs cluster disable –all
ha-node1: Cluster Disabled
ha-node2: Cluster Disabled

Part03-节点管理

3.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:

3.2 移除节点

# 将节点设置为待机状态
[root@ha-node1 ~]# pcs cluster standby ha-node3

# 停止节点上的集群服务
[root@ha-node1 ~]# pcs cluster stop ha-node3
ha-node3: Stopping Cluster (pacemaker)…
ha-node3: Stopping Cluster (corosync)…

# 从集群中移除节点
[root@ha-node1 ~]# pcs cluster node remove ha-node3
Attempting to stop corosync on ha-node3…
ha-node3: Stopping Cluster…
ha-node3: Successfully stopped cluster
Attempting to remove ha-node3 from cluster…
ha-node3: Successfully removed

# 验证节点已移除
[root@ha-node1 ~]# pcs status nodes
Pacemaker Nodes:
Online: ha-node1 ha-node2
Standby:
Maintenance:
Offline:

Part04-集群维护

4.1 节点维护模式

# 将节点设置为维护模式
[root@ha-node1 ~]# pcs cluster maintenance ha-node2
ha-node2: Setting node to maintenance mode

# 查看节点状态
[root@ha-node1 ~]# pcs status nodes
Pacemaker Nodes:
Online: ha-node1
Standby:
Maintenance: ha-node2
Offline:

# 取消维护模式
[root@ha-node1 ~]# pcs cluster unmaintenance ha-node2
ha-node2: Unsetting node maintenance mode

# 验证节点状态
[root@ha-node1 ~]# pcs status nodes
Pacemaker Nodes:
Online: ha-node1 ha-node2
Standby:
Maintenance:
Offline:

4.2 集群清理

# 清理集群配置
[root@ha-node1 ~]# pcs cluster destroy –all
ha-node1: Stopping Cluster (pacemaker)…
ha-node1: Stopping Cluster (corosync)…
ha-node2: Stopping Cluster (pacemaker)…
ha-node2: Stopping Cluster (corosync)…
ha-node1: Successfully destroyed cluster
ha-node2: Successfully destroyed cluster

# 清理本地节点
[root@ha-node1 ~]# pcs cluster destroy
Stopping Cluster (pacemaker)…
Stopping Cluster (corosync)…
Successfully destroyed cluster

# 验证清理结果
[root@ha-node1 ~]# ls /etc/corosync/
ls: cannot access ‘/etc/corosync/’: No such file or directory

[root@ha-node1 ~]# ls /var/lib/pacemaker/
ls: cannot access ‘/var/lib/pacemaker/’: No such file or directory

Part05-集群验证

5.1 验证集群配置

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

# 验证资源配置
[root@ha-node1 ~]# pcs cluster verify –full
Verifying cluster configuration…
Checking corosync configuration…
Checking pacemaker configuration…
No errors found

# 查看集群GUID
[root@ha-node1 ~]# pcs cluster guid
Cluster GUID: 12345678-90ab-cdef-1234-567890abcdef

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

nodelist {
node {
ring0_addr: ha-node1
name: ha-node1
nodeid: 1
}
node {
ring0_addr: ha-node2
name: ha-node2
nodeid: 2
}
}

quorum {
provider: corosync_votequorum
two_node: 1
}

风哥针对pcs cluster命令建议:

  • 使用–all参数操作所有节点
  • 维护前将节点设置为standby
  • 定期验证集群配置
  • 备份集群配置文件
  • 监控集群状态变化

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

联系我们

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

微信号:itpux-com

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