habibzain Just husband, father and enthusiastic men about System Administration. Love to write short article about it. Perhaps can help and be useful for others.

Setting HA cluster with Corosync and Pacemaker Ubuntu 20.04 server

2 min read

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:

  1. Pacemaker version 2.0.3
  2. PCS version 0.10.4
  3. 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.

ha cluster corosync pacemaker
node1 ping to hostname node2

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.

See also  Install Percona Server for MySQL 5.6 In Ubuntu 18

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: 
ha cluster corosync pacemaker
“pcs cluster auth” result

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
pacemaker corosync hacluster
“pcs host auth” result
pcs cluster setup cluster1 node1.habibza.in node2.habibza.in --force
pcs cluster enable --all
pcs cluster enable
pcs cluster start --all
pcs cluster start

Disable second properties

pcs property set stonith-enabled=false
pcs property set no-quorum-policy=ignore
pcs property set

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
pcs status resources

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
“crm configure group” error.

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”.

See also  How to Setting IP Static Ubuntu 18 or 20.04

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”.

ha cluster corosync pacemaker
HA Dashboard.

In the browser, when you type ip float http://192.168.197.140, the following will appear.

node1 web.

Make Node1 Standby

Now switch node1 to standby in the Web Admin interface. click button “standby”, until show "pacemaker standby" and button "unstandby" appear.

ha cluster corosync pacemaker
set node1 to standby
ha cluster corosync pacemaker
"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.

Buy Me a Coffee at ko-fi.com

https://saweria.co/habibzain
https://ko-fi.com/habibzain
habibzain Just husband, father and enthusiastic men about System Administration. Love to write short article about it. Perhaps can help and be useful for others.

Ansible Ubuntu 20.04

Introduction Ansible is an open-source automation tool that simplifies configuration management, application deployment, and task automation. It is designed to be simple, lightweight, and...
habibzain
1 min read

8 Replies to “Setting HA cluster with Corosync and Pacemaker Ubuntu 20.04…”

  1. 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

  2. very nice.Will build on your instructions above.Does Ubuntu flavours use fencing?

  3. 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

  4. touch /var/lib/pcsd/known-hosts

    pcs host auth node1 node2 node…
    pcs cluster setup NAME node1 node2 node…
    works for me

  5. 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

Leave a Reply

Your email address will not be published. Required fields are marked *

Never miss good article from us, get weekly updates in your inbox