☰
如何手工搭建红帽高可用集群
2026/10/17 8:15:38 网站建设 项目流程

1. 环境准备

# 在所有节点上安装必要软件包
yum install -y pcs pacemaker corosync fence-agents-all
# 启用并启动 pcsd 服务

systemctl enable pcsd

systemctl start pcsd

# 设置 hacluster 用户密码(所有节点使用相同密码)

passwd hacluster

2. 集群认证和创建

# 在一个节点上认证所有集群节点

pcs cluster auth node1 node2 -u hacluster -p your_password

# 创建集群

pcs cluster setup my_cluster node1 node2

# 启动集群
pcs cluster start --all

pcs cluster enable --all

3. 配置 STONITH(防止脑裂)

# 配置 fencing 设备(根据实际环境选择)

pcs stonith create fence_vm fence_vmware_soap \
pcmk_host_list="node1,node2" \
ipaddr="vcenter.example.com" \
login="admin" \
passwd="password" \
ssl="1" \
ssl_insecure="1" \
datacenter="Datacenter" \
protocol="https"

4. 添加集群资源

# 添加虚拟 IP 地址

pcs resource create VirtualIP IPaddr2 \
ip=192.168.1.100 cidr_netmask=24 op monitor interval=30s
# 添加 Web 服务(示例)

pcs resource create WebServer apache \
configfile=/etc/httpd/conf/httpd.conf op monitor interval=1min
# 设置资源依赖关系

pcs constraint colocation add WebServer with VirtualIP INFINITY

pcs constraint order VirtualIP then WebServer

5. 验证集群状态

# 查看集群状态

pcs status

# 查看集群配置

pcs config show

# 测试故障转移

pcs cluster stop node1

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询