Corosync 提供叢集通訊層(心跳傳遞),Pacemaker 作為資源管理器 (CRM) 掛載於其上,兩者結合形成高可用容器,服務可動態增減,靈活性遠優於 Heartbeat。
| 角色 | IP |
|---|---|
| VIP (虛擬 IP) | 192.168.10.130 |
| Node1 | 192.168.10.103 |
| Node2 | 192.168.10.219 |
yum install corosync pacemaker python-dateutil redhat-rpm-config pssh
rpm -ivh https://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-6/x86_64/crmsh-2.1-1.6.x86_64.rpm
# Node1
echo "HOSTNAME=node1" > /etc/sysconfig/network
# Node2
echo "HOSTNAME=node2" > /etc/sysconfig/network
# 兩節點 /etc/hosts 同步新增
192.168.10.103 node1
192.168.10.219 node2
/etc/init.d/network restart
cd /etc/corosync
cp corosync.conf.example corosync.conf
# 關鍵段落:
totem {
version: 2
secauth: off
interface {
ringnumber: 0
bindnetaddr: 192.168.10.0
mcastaddr: 239.255.1.1
mcastport: 5405
ttl: 1
}
}
service {
name: pacemaker
}
corosync-keygen # 產生 authkey
scp authkey corosync.conf root@node2:/etc/corosync/
chkconfig nginx off
service nginx stop
service corosync start
netstat -na | grep 5405 # 應見 UDP 5405 監聽
crm status # 檢視叢集狀態
若 crm status 報 Could not establish cib_ro connection:
service iptables stop; setenforce 0。authkey 兩節點完全一致。ping 239.255.1.1 應通。後續可透過 crm configure 將 Nginx、VIP 納為受管資源,實現自動故障轉移。