This post will simply explain setting HA Cluster with Corosync and Pacemaker Ubuntu 20.04 Server. Please read carefully step by step.
Important!
The installation works with requirement as below:
- Pacemaker version 2.0.3
- PCS version 0.10.4
- Corosync crm version 4.0.0
if use PCS version 0.9.x and before, the syntax is different in some places.
Hi Dude. Let me write for my own notes about hacluster with pacemaker
and corosync
. I am running virtualbox, with 2VM. This is detail IP address in used:
node 1 = 192.168.197.137 node 2 = 192.168.197.138 IP Float = 192.168.197.140
Ok, Lets Execute.
All commands are executed on both nodes (VMs) at the beginning.
Disable Firewall UFW or Use it
Ubuntu 20.04 come with bundling firewall called UFW. For this lab purpose, i prefer disable all firewall rulvim /etc/hostse. But if we want to use ufw firewall let add this command.
ufw allow from 192.168.197.137 to any (only node 1)
ufw allow from 192.168.197.138 to any (only node 2)
Specify the Hostname in /etc/hosts
In both VM (nodes) make the following entries in /etc/hosts
# vim /etc/hosts
192.168.197.137 node1.habibza.in
192.168.197.138 node2.habibza.in
Make sure, between host can ping for communicate.
Install Web Server, Corosync and Pacemaker
Install Nginx as webserver, Corosync and Pacemaker.
apt install nginx
apt install corosync pacemaker pcs
Activate and start Nginx.
systemctl enable nginx && systemctl start nginx
On each node, lets change the default Nginx page. This purpose we can determine where we are on each server node.
On node1:
echo "This is the default page for node1.habibza.in" | sudo tee /var/www/html/index.nginx-debian.html
On Node2:
echo "This is the default page for node2.habibza.in" | sudo tee /var/www/html/index.nginx-debian.html
Next, activate and start Pacemaker.
systemctl enable pcsd
systemctl start pcsd
With the installation a user “hacluster” was created, which still needs a password.
passwd hacluster
New password: PasswdSecr3t
Retype new password: PasswdSecr3t
Until this step, all commands were executed on both nodes. Next only on node1.
pcs cluster auth
Result: Warning: Unable to read the known-hosts file: No such file or directory: '/var/lib/pcsd/known-hosts' node1: Not authorized Nodes to authorize: node1 Username: hacluster Password:
Now authenticate the nodes.
pcs host auth node1.habibza.in node2.habibza.in
Result: Username: hacluster Password: PasswdSecr3t node1.example.com: Authorized node2.example.com: Authorized
pcs cluster setup cluster1 node1.habibza.in node2.habibza.in --force
pcs cluster enable --all
pcs cluster start --all
Disable second properties
pcs property set stonith-enabled=false
pcs property set no-quorum-policy=ignore
Defining Floating IP
Now, defining the Floating IP listed above, where that ip will be calling on hacluster.
pcs resource create floating_ip ocf:heartbeat:IPaddr2 ip=192.168.197.140 cidr_netmask=24 op monitor interval=60s
It should be checked which node is active and, if necessary, it should be alternately active.
pcs resource create http_server ocf:heartbeat:nginx configfile="/etc/nginx/nginx.conf" op monitor timeout="20s" interval="60s"
We have the status output.
# pcs status resources
* Resource Group: cluster1:
* floating_ip (ocf::heartbeat:IPaddr2): Started node1.example.com
* http_server (ocf::heartbeat:nginx): Started node2.example.com
At this step, that everything runs. But unfortunately on different nodes, we need to group all this node.
crm configure group cluster1 floating_ip http_server
It comes (with me) to an error message, which I ignore however.
Result: ERROR: (unpack_config) warning: Blind faith: not fencing unseen nodes
I get back the status again and see "pcs status resources"
.
pcs status resources
* Resource Group: cluster1:
* floating_ip (ocf::heartbeat:IPaddr2): Started node1.habibza.in
* http_server (ocf::heartbeat:nginx): Started node1.habibza.in
Call Web Interface Hacluster
Everything runs well on node1, as desired. Now call IP float to access web dashoard for continue setup.
https://192.168.197.140:2224/manage
Login with hacluster and thePassword and +Add Exiting in the popping up field then enter “node1.habibza.in”.
Then the button “Add Exiting”. Then you have to wait a bit until everything is loaded. Wait a moment and you can input cluster name. In my case, i am use name “mycluster-1”.
In the browser, when you type ip float http://192.168.197.140, the following will appear.
Make Node1 Standby
Now switch node1 to standby in the Web Admin interface. click button “standby”, until show "pacemaker standby"
and button "unstandby"
appear.
Lets see the result in picture below.
That is setting HA Cluster with Corosync and Pacemaker Ubuntu 20.04 Server. May be it’s helpful, please feel free to leave a comment if you have any questions and I’ll appreciate it.
Let's Buy Me Coffee. https://saweria.co/habibzain https://ko-fi.com/habibzain
wow wow wow thank you soo much. I was labbing this on vmware. I now understand the concept because of you. You took your time explaining. Many thanks
You ‘r welcome bro.
very nice.Will build on your instructions above.Does Ubuntu flavours use fencing?
pcs cluster setup cluster1 node1.ha.local node2.ha.local –force
then below error msg showing
Warning: Unable to read the known-hosts file: No such file or directory: ‘/var/lib/pcsd/known-hosts’
Error: Hosts ‘node1.ha.local’, ‘node2.ha.local’ are not known to pcs, try to authenticate the hosts using ‘pcs host auth node1.ha.local node2.ha.local’ command
Error: None of hosts is known to pcs.
Error: At least 1 and at most 8 addresses must be specified for a node, 0 address specified for node ‘node1.ha.local’
Error: At least 1 and at most 8 addresses must be specified for a node, 0 address specified for node ‘node2.ha.local’
Error: Errors have occurred, therefore pcs is unable to continue
touch /var/lib/pcsd/known-hosts
pcs host auth node1 node2 node…
pcs cluster setup NAME node1 node2 node…
works for me
Dear Stan, thanks for sharing.
Thankyou so much foy your clear article.
I still get error in ‘pcs resource create http_servet …. (i use apache)
Something likes “ocf:heartbeat:apache not found”
yours sincerely
suyanto ea
Hi. Suyanto EA.
Thanks for visit. Make sure all service apache and heartbeat running.