Red hat linux

How to Set up Nginx High Availability with Pacemaker and Corosync


  • 2 or more CentOS 7 Serverpre
    • web01
    • web02
    • web03
  • Floating IP Address
  • Root Privileges

What we will do:

  1. Map the Host File
  2. Install Epel Repository and Nginx
  3. Install and Configure Pacemaker, Corosync, and Pcsd
  4. Create and Configure the Cluster
  5. Disable STONITH and Ignore the Quorum Policy
  6. Add the Floating-IP and Resources
  7. Add Rules to the Cluster
  8. Configure Firewalld
  9. Test the setup

Update Host files in all servers

Paste the following configuration there.

Install Epel Repository ,Nginx and pacemaker

Change hacluster user password

Create and Configure the Cluster

Now it’s time set up the cluster. Define the cluster name and all servers that will be part of the cluster.

Now start all cluster services and also enable them.

Disable STONITH and Ignore the Quorum Policy

Add the Floating-IP and Resources

If you want, add a new resource for the Nginx ‘webserver’.

Add Constraint Rules to the Cluster
In this step, we will setup High Availability Rules, and will setup resource constraint with the pcs command line interface.

Set the collation constraint for webserver and virtual_ip resources with score ‘INFINITY’. Also, setup the webserver and virtual_ip resources as same on all server nodes.

Set the ‘virtual_ip’ and ‘webserver’ resources always on same node servers.

Next, stop the cluster and then start again.


Now, check again the resources and you will see their status as ‘Started’ on the same server ‘web01’.

virtual_ip and webserver resources have been started on the same server/node ‘web01’.

Configure Firewalld
The HA-Cluster will run under the firewall configuration firewalld – install it if you do not have the package.

Start firewalld and enable it to run automatically every time at system boot using following systemctl commands.

Next, add new services to the firewalld with firewall-cmd commands – add high-availability service, HTTP, and HTTPS services for Nginx.

Reload the firewall configuration, and check all services.

Make sure ha service with HTTP and https is there on the list.
In this step, we’re gonna do some test for the cluster. Test the node status (‘Online’ or ‘Offline’), test the corosync members and status, and then test the high-availability of the Nginx webserver by accessing the Floating IP address.

Test node status with the following command.

All nodes are up ‘Online’.

Test the corosync members.

You will get Corosync members IP address.

Check the Corosync members, and you will see the result as shown below.

And lastly, check the webserver High Availability. Open your web browser and type the Floating IP address ‘’.

You will see the web page from the ‘web01’ server.
Next, stop the cluster on the ‘web01’ server with the command below.

And check again the page, and you will get the page from the ‘web02’ server as below.


Check the cluster status with the command below.

And you will get the result as shown below.

Setup of Nginx webserver High Availability with Pacemaker, Corosync, and Pcsd on CentOS 7 server has been completed successfully.

Leave a Reply

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