Pacemaker & Corosync High Availability
Pacemaker and Corosync integrate with PiVirt to provide automated cluster quorum management, split-brain protection, and high-availability daemon supervision across all nodes.
Architecture
Section titled “Architecture”flowchart TB
subgraph Pacemaker["Pacemaker Cluster"]
CORO["Corosync (Messaging)"]
CRM["Pacemaker (CRM)"]
RA["Resource Agents (OCF / LSB)"]
end
subgraph Node1["Node 1"]
P1["pivirtd / iscsiman"]
end
subgraph Node2["Node 2"]
P2["pivirtd / iscsiman"]
end
subgraph Node3["Node 3"]
P3["pivirtd / iscsiman"]
end
Pacemaker --> Node1
Pacemaker --> Node2
Pacemaker --> Node3
Install Pacemaker
Section titled “Install Pacemaker”Install Packages
Section titled “Install Packages”# On all nodesapt-get install -y pacemaker corosync fence-agents resource-agentsConfigure Corosync
Section titled “Configure Corosync”# Generate authkeycorosync-keygen
# Copy to all nodesscp /etc/corosync/authkey node-02:/etc/corosync/scp /etc/corosync/authkey node-03:/etc/corosync/
# Configure corosynccat > /etc/corosync/corosync.conf <<EOFtotem { version: 2 cluster_name: pivirt-cluster transport: knet crypto_cipher: aes256 crypto_hash: sha256}
nodelist { node { ring0_addr: 10.0.1.10 name: node-01 nodeid: 1 } node { ring0_addr: 10.0.1.11 name: node-02 nodeid: 2 } node { ring0_addr: 10.0.1.12 name: node-03 nodeid: 3 }}
quorum { provider: corosync_votequorum expected_votes: 3 two_node: 0}
logging { to_logfile: yes logfile: /var/log/corosync/corosync.log to_syslog: yes}EOF
# Copy to all nodesscp /etc/corosync/corosync.conf node-02:/etc/corosync/scp /etc/corosync/corosync.conf node-03:/etc/corosync/Start Services
Section titled “Start Services”# On all nodessystemctl enable --now corosyncsystemctl enable --now pacemaker
# Verifysystemctl status corosyncsystemctl status pacemakerConfigure Fencing
Section titled “Configure Fencing”SBD Fencing
Section titled “SBD Fencing”# Install SBDapt-get install -y sbd
# Configure SBDcat > /etc/default/sbd <<EOFSBD_DEVICE="/dev/disk/by-id/scsi-360050764008181c60000000000000002"SBD_PACEMAKER=yesSBD_STARTMODE=alwaysEOF
# Initialize SBDsbd -d /dev/disk/by-id/scsi-360050764008181c60000000000000002 create
# Enable SBDsystemctl enable sbdIPMI Fencing
Section titled “IPMI Fencing”# Configure IPMI fencingpcs stonith create ipmi-fence fence_ipmi_lan \ ipaddr=10.0.0.11 \ login=admin \ passwd=password \ lanplus=1 \ pcmk_host_list=node-01
# Add fencing for other nodespcs stonith create ipmi-fence-02 fence_ipmi_lan \ ipaddr=10.0.0.12 \ login=admin \ passwd=password \ lanplus=1 \ pcmk_host_list=node-02Configure Resources
Section titled “Configure Resources”iSCSI Target Resource
Section titled “iSCSI Target Resource”# Create iSCSI target resourcepcs resource create iscsi-target ocf:pilab:iscsi-target \ iqn="iqn.2024-01.hu.pilab:vm-storage" \ op monitor interval=30s
# Create clone (run on all nodes)pcs resource clone iscsi-targetOCFS2 Resource
Section titled “OCFS2 Resource”# Create OCFS2 resourcepcs resource create ocfs2-vm-shared ocf:heartbeat:Filesystem \ device="/dev/disk/by-id/scsi-360050764008181c60000000000000001" \ directory="/var/lib/pivirtd/shared" \ fstype="ocfs2" \ options="_netdev,nointr" \ op monitor interval=30s
# Create clonepcs resource clone ocfs2-vm-sharedpivirtd Resource
Section titled “pivirtd Resource”# Create pivirtd resourcepcs resource create pivirtd systemd:pivirtd \ op monitor interval=30s
# Create clonepcs resource clone pivirtdConfigure Constraints
Section titled “Configure Constraints”Colocation Constraints
Section titled “Colocation Constraints”# Ensure OCFS2 runs with iSCSIpcs constraint colocation add ocfs2-vm-shared-clone with iscsi-target-clone INFINITY
# Ensure pivirtd runs with OCFS2pcs constraint colocation add pivirtd-clone with ocfs2-vm-shared-clone INFINITYOrdering Constraints
Section titled “Ordering Constraints”# Start iSCSI before OCFS2pcs constraint order iscsi-target-clone then ocfs2-vm-shared-clone
# Start OCFS2 before pivirtdpcs constraint order ocfs2-vm-shared-clone then pivirtd-cloneMonitoring
Section titled “Monitoring”Check Cluster Status
Section titled “Check Cluster Status”# Check cluster statuspcs status
# Check resource statuspcs resource status
# Check node statuspcs node statusCheck Logs
Section titled “Check Logs”# Check Pacemaker logsjournalctl -u pacemaker -f
# Check Corosync logsjournalctl -u corosync -fTroubleshooting
Section titled “Troubleshooting”Cluster Not Forming
Section titled “Cluster Not Forming”# Check Corosynccorosync-cfgtool -s
# Check quorumcorosync-quorumtool -s
# Check logsjournalctl -u corosync -fResource Failures
Section titled “Resource Failures”# Check resource statuspcs resource debug-start <resource-name>
# Check resource logsjournalctl -u pacemaker -f | grep <resource-name>
# Check resource agent/usr/lib/ocf/resource.d/pilab/iscsi-target meta-dataFencing Issues
Section titled “Fencing Issues”# Test fencingpcs stonith fence node-02
# Check fencing logsjournalctl -u pacemaker -f | grep -i fence