At first we need to instal this packages if they are not presented:
yum -y install corosync pacemaker pcs
Before your cluster could be configured, you need to start the pcs daemon and boot up at each node, so type those command into your terminal:
systemctl enable pcsd.service systemctl start pcsd.service
Also, yum will create a account “hacluster” for management, so you should change it’s password.
Now it is time to define your cluster. Use hacluster account and the password you chose in previous step.
pcs cluster auth itsol-db1 itsol-db2
pcs cluster setup --name itsol-db itsol-db1 itsol-db2 pcs cluster start --all
Then you should see the cluster boot up.
pcs status nodes pcs status corosync
Now you can define resources, in this example there is a 2 virtual IP addresses, one for master and one for slave.
pcs resource create virtual_ip ocf:heartbeat:IPaddr2 ip=10.1.40.135 cidr_netmask=32 op monitor interval=30s pcs resource create virtual_ip2 ocf:heartbeat:IPaddr2 ip=10.1.40.136 cidr_netmask=32 op monitor interval=30s
Since we have simple cluster (only two nodes), we’ll just disable the stonith and quorum options:
pcs property set stonith-enabled=false pcs property set no-quorum-policy=ignore
To check current status and resource location
pcs status resources pcs status|grep virtual_ip
Now is time to add another constraint for location – you specify on which node you prefer to be your resource. In our case:
pcs constraint location virtual_ip prefers itsol-db1=50 pcs constraint location virtual_ip2 prefers itsol-db2=50
To check all constrains
Some other commands that can be used in this configuration
pcs cluster stop --all pcs cluster start --all pcs cluster stop itsol-db1
And also if you want to transfer a virtual IP to another node you can simply put the preffered one in standby
pcs cluster standby itsol-db1
And to bring it back
pcs cluster unstandby itsol-db1
In case you want to run a bash script on resource transfer you can copy Dummy script from heartbeat resource folder and add it like a resource
cd /usr/lib/ocf/resource.d/heartbeat/ cp Dummy FailOverScript pcs resource create script ocf:heartbeat:FailOverScript op monitor interval=1min pcs constraint colocation add script virtual_ip INFINITY pcs constraint order script then virtual_ip
To test this scrip
export OCF_ROOT=/usr/lib/ocf /usr/lib/ocf/resource.d/heartbeat/FailOverScript