In today’s digital age, having a highly available web server is crucial for any organization. With the help of Pacemaker and Corosync, system administrators can set up a high availability (HA) cluster for their web server to ensure maximum uptime and minimal downtime. In this article, we will walk through the process of configuring an Apache web server to work with a Pacemaker and Corosync HA cluster, using advanced level command line examples.
Prerequisites: Before we begin, we need to make sure that the following packages are installed on our Linux-based system:
- pacemaker
- corosync
- apache2
If any of these packages are not installed, we can use the following command to install them:
sudo apt-get install pacemaker corosync apache2
Configuring Pacemaker and Corosync:
First, we need to configure Pacemaker and Corosync to work together. We can do this by creating a Corosync configuration file:
sudo nano /etc/corosync/corosync.conf
In this file, we will define the Pacemaker cluster name, the IP address of each node in the cluster, and other configuration options. Once we have saved the file, we can start the Corosync service:
sudo service corosync start
Next, we need to create a Pacemaker resource agent for Apache:
sudo nano /usr/lib/ocf/resource.d/apache2/apache
In this file, we will define the start, stop, and monitor functions for the Apache resource agent. Once we have saved the file, we can start the Pacemaker service:
sudo service pacemaker start
Configuring the Apache Web Server:
Now that Pacemaker and Corosync are set up, we need to configure Apache to work with them. We can do this by creating a configuration file for Apache:
sudo nano /etc/apache2/conf.d/ha.conf
An example configuration file for Apache that can be used with Pacemaker and Corosync:
# Define the virtual IP address that will be used by the HA cluster
<VirtualHost 192.168.0.100:80>
ServerAdmin [email protected]
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html
# Define any other configuration options for Apache that we need
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# Enable server-side includes
AddOutputFilter INCLUDES .shtml
AddType text/html .shtml
AddHandler server-parsed .shtml
# Enable gzip compression
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
DeflateCompressionLevel 9
</IfModule>
</VirtualHost>
In this file, we will define the virtual IP address that will be used by the HA cluster. We can also define any other configuration options for Apache that we need. Once we have saved the file, we can restart the Apache service:
sudo service apache2 restart
Testing the HA Cluster:
Now that everything is set up, we can test the HA cluster to make sure it is working properly. We can do this by stopping the Apache service on one node and verifying that the other node takes over:
sudo service apache2 stop
We can then check the status of the Pacemaker cluster to make sure that the other node has taken over:
sudo crm_mon
Conclusion:
In this article, we have seen how to configure an Apache web server with Pacemaker and Corosync HA cluster. By following these steps, system administrators can ensure maximum uptime and minimal downtime for their web server.
YouTube channel: https://www.youtube.com/@trainbrain007