HA with CentOS and RedHat and like
Environment
Install two servers with one IP virtual and shared storage:
- Server1: ext1 with IP 192.168.122.113
- Server2: ext2 with IP 192.168.122.53
- IP virtual: 192.168.122.70
- Shared storage on device /dev/sda mounted on /home/db2
- HA user named hacluster with password manager
Tested on CentOS 7.5. Some exceptions for testing on RHEL 7.3.
Install software
On both nodes:
Configure /etc/hosts:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.122.113 ext1 192.168.122.53 ext2 192.168.122.70 ext
Install and enable pacemaker:
$ sudo yum install pcs fence-agents-all -y $ sudo systemctl disable firewalld $ sudo systemctl stop firewalld $ sudo passwd hacluster $ sudo systemctl start pcsd.service $ sudo systemctl enable pcsd.service $ sudo lvmconf --enable-halvm --services --startstopservices
If you prefer get working the firewall:
$ sudo firewall-cmd --permanent --add-service=high-availability $ sudo firewall-cmd --add-service=high-availability
If you are using RHEL you must enable HighAvailability.
If you receive this message:
Unit lvm2-cluster-activation.service could not be found. Failed to execute operation: No such file or directory Failed to stop lvm2-cluster-activation.service: Unit lvm2-cluster-activation.service not loaded.
Use this steps:
$ sudo lvmconf --enable-halvm $ sudo systemctl disable lvm2-lvmetad $ sudo systemctl stop lvm2-lvmetad
On one node:
Create one partition with fdisk and configure a physical group, a volume group and logical volume:
$ sudo pcs cluster auth ext1 ext2 $ sudo pcs cluster setup --start --name baccluster ext1 ext2 $ sudo pcs cluster enable --all $ sudo fdisk /dev/sda $ sudo pvcreate /dev/sda1 $ sudo vgcreate bacvg /dev/sda1 $ sudo lvcreate -L10G -n baclv bacvg $ sudo mkfs.ext4 /dev/mapper/bacvg-baclv
Edit /etc/lvm/lvm.conf and create or modify the line volume_list = [ ], add all the vg that are outside the shared storage, in our case all except bacvg. For example: volume_list = [ “centos” , “otro” ]
Execute on both nodes:
$ sudo dracut -H -f /boot/initramfs-$(uname -r).img $(uname -r)
On the other node:
$ sudo partprobe $ sudo pvscan $ sudo vgscan $ sudo lvscan
Validate that you can see the logical volume created on the other server.
Reboot both nodes.
On one node:
$ sudo pcs resource create bacip IPaddr2 ip=192.168.122.70 cidr_netmask=24 --group bacgroup $ sudo pcs resource create baclvm LVM volgrpname=bacvg exclusive=true --group bacgroup $ sudo pcs resource create bacfs Filesystem device="/dev/mapper/bacvg-baclv" directory="/home/db2/" fstype="ext4" --group bacgroup $ sudo pcs property set stonith-enabled=false $ sudo pcs property set no-quorum-policy=ignore
You can get cluster status with:
$ sudo pcs status
You can migrate resources between nodes
$ sudo pcs resource move bacgroup ext2
If the resources migrates automatically to the node that you moved all resources, remove the location contraint with:
$ sudo pcs resource clear bacgroup
Monitoring resources
The cluster can starts automatically resources if was stopped, this can be OK or not. If you want that the cluster doesn't monitor resources use this command to create it:
pcs resource create bachttpd systemd:httpd op monitor enabled=false --group bacgroup
If the resource was created update it:
pcs resource update bachttpd op monitor enabled=false