Prerequisites
- 2 or more CentOS 7 Serverpre
- web01 10.0.15.10
- web02 10.0.15.11
- web03 10.0.15.12
- Floating IP Address 10.0.15.15
- Root Privileges
What we will do:
- Map the Host File
- Install Epel Repository and Nginx
- Install and Configure Pacemaker, Corosync, and Pcsd
- Create and Configure the Cluster
- Disable STONITH and Ignore the Quorum Policy
- Add the Floating-IP and Resources
- Add Rules to the Cluster
- Configure Firewalld
- Test the setup
Update Host files in all servers
vim /etc/hosts
Paste the following configuration there.
10.0.15.10 web01 10.0.15.11 web02 10.0.15.12 web03
Install Epel Repository ,Nginx and pacemaker
yum -y install epel-release yum -y install nginx yum -y install corosync pacemaker pcs systemctl enable pcsd systemctl enable corosync systemctl enable pacemaker systemctl start pcsd
Change hacluster user password
passwd hacluster
Create and Configure the Cluster
pcs cluster auth web01 web02 web03 Username: hacluster Password: aqwe123@
Now it’s time set up the cluster. Define the cluster name and all servers that will be part of the cluster.
pcs cluster setup --name hakase_cluster web01 web02 web03
Now start all cluster services and also enable them.
pcs cluster start --all pcs cluster enable --all pcs status cluster
Disable STONITH and Ignore the Quorum Policy
pcs property set stonith-enabled=false pcs property set no-quorum-policy=ignore pcs property list
Add the Floating-IP and Resources
pcs resource create virtual_ip ocf:heartbeat:IPaddr2 ip=10.0.15.15 cidr_netmask=32 op monitor interval=30s
If you want, add a new resource for the Nginx ‘webserver’.
pcs resource create webserver ocf:heartbeat:nginx configfile=/etc/nginx/nginx.conf op monitor timeout="5s" interval="5s" pcs status resources
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.
pcs constraint colocation add webserver virtual_ip INFINITY
Set the ‘virtual_ip’ and ‘webserver’ resources always on same node servers.
pcs constraint order virtual_ip then the webserver
Next, stop the cluster and then start again.
pcs cluster stop --all pcs cluster start --all
Now, check again the resources and you will see their status as ‘Started’ on the same server ‘web01’.
pcs status resources
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.
yum -y install firewalld
Start firewalld and enable it to run automatically every time at system boot using following systemctl commands.
systemctl start firewalld systemctl enable firewalld
Next, add new services to the firewalld with firewall-cmd commands – add high-availability service, HTTP, and HTTPS services for Nginx.
firewall-cmd --permanent --add-service=high-availability firewall-cmd --permanent --add-service=http firewall-cmd --permanent --add-service=https
Reload the firewall configuration, and check all services.
firewall-cmd --reload firewall-cmd --list-all
Make sure ha service with HTTP and https is there on the list.
Testing
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.
pcs status nodes
All nodes are up ‘Online’.
Test the corosync members.
corosync-cmapctl | grep members
You will get Corosync members IP address.
Check the Corosync members, and you will see the result as shown below.
pcs status corosync
And lastly, check the webserver High Availability. Open your web browser and type the Floating IP address ‘10.0.15.15’.
You will see the web page from the ‘web01’ server.
Next, stop the cluster on the ‘web01’ server with the command below.
pcs cluster stop web01
And check again the page, and you will get the page from the ‘web02’ server as below.
Additional:
Check the cluster status with the command below.
pcs status
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.