# High Availability (HA)

**High Availability** (HA) simply refers to the quality of a system to operate continuously without failure for a long period of time. HA solutions can be implemented using hardware and software, and one of the common solutions to implementing HA is clustering.  
  
Let start with the configuration-  
  
**Requirements-**  
  
Two systems with Ubuntu 18.04 / CentOS 7 installed.  
  
Configure static IP in both of them.  
  
In my case node1 - 172.16.0.10/24 node2 - 172.16.0.20/24  
  
Install NGINX and configure it.  
  
Set the hostname in both machines and add hostname details in /etc/hosts.  
  
  
Now start the configuration.  
  
**Configuration-**  
  
CentOS Users

  
First, we need to install the required packages for HA and nginx.  
  
For enabling epel repositories in centos-

```plaintext
yum install epel-release
```

Now install all required packages.

```plaintext
yum install -y pcs corosync pacemaker nginx
```

  
Start and enable the service and add entries in firewall.

```plaintext

systemctl start/enable pcsd nginx
```

```plaintext

firewall-cmd --permanent --add-service=high-availability
```

```plaintext

firewall-cmd --permanent --add-service=nginx
```

```plaintext
firewall-cmd --reload
```

  
Ubuntu Users

```plaintext
sudo apt update
sudo apt install pcs pacemaker corosync nginx -y
systemctl start/enable pcsd nginx
sudo ufw allow 5405/udp
sudo ufw allow 2224/tcp
sudo ufw allow 3121/tcp
sudo ufw allow 21064/tcp
```

After installing these packages a user hacluster will be created automatically in both machines, now set the password for that user.

```plaintext
passwd hacluster
```

Now run auth command for authentication which is needed by pcs-

```plaintext
pcs cluster auth node1 node2 -u hacluster -p <password> --force
```

Now create a cluster and add both nodes in it.

```plaintext
pcs cluster setup --name mycluster node1 node2
or 
pcs cluster setup name=mycluster node1 node2 --force
```

Now enable the cluster on boot and start the service.

```plaintext
pcs cluster start --all
```

```plaintext
pcs cluster enable --all
```

To check cluster status

```plaintext
pcs status
```

Configure Cluster options-

The first option is to disable STONITH (or Shoot The Other Node In The Head), the fencing implementation on Pacemaker.

This helps to protect your data from being corrupted by access. Right now, we will disable it since we have not configured the node.

To turn off STONITH, run the following command

```plaintext
pcs property set stonith-enabled=false
```

Next, also ignore the Quorum policy by running the following command:

```plaintext
pcs property set no-quorum-policy=ignore
```

To verify the configuration run following command-

```plaintext
pcs property list
```

Now it's time to add resources in the cluster-

In this section, we will look at how to add a cluster resource. We will configure a floating IP which is the IP address that can be instantly moved from one server to another within the same network or data centre. In short, a floating IP is a technical common term, used for IPs that are not bound strictly to one single interface.

```plaintext
pcs resource create floating_ip ocf:heartbeat:IPaddr2 ip=172.16.0.250 cidr_netmask=24 op monitor interval=60s
```

Note:- “ocf:heartbeat:IPaddr2”: tells Pacemaker which script to use, IPaddr2 in this case, which namespace it is in (pacemaker) and what standard it conforms to ocf.

“op monitor interval=60s”: instructs Pacemaker to check the health of this service every one minute by calling the agent’s monitor action.

If you want to add more resources you can add like this but right now I’m going with only one.

To check resource properties run following command-

```plaintext
pcs status resources
```

After that add example page in both Nginx servers and try to access with floating\_ip which you configured.

Now if your one system goes down secondary will take over.
