When running a service that is of vital importance to your environment, it’s necessary to protect it using a high-availability...
technique that involves deploying a combination of software and hardware. In this tip, you'll learn how to set up a high-availability (HA) environment on Linux using Corosync and Pacemaker software.
Linux HA software
Corosync and Pacemaker are the de facto standards for Linux HA. Corosync verifies all nodes in the cluster are still available and Pacemaker takes care of the placement of resources in the cluster.
You can install both of these products on virtually all Linux distributions to create a HA stack that can then be used to protect vital services. In this tip, we'll use OpenSUSE as the example distribution, for the simple reason that you can take it for a free test drive. After deciding that OpenSUSE really is what you need to protect services, you can buy a supported version for your enterprise Linux distribution. Both SUSE and Red Hat have HA versions available with additional enterprise-level support.
Let’s take a look at the basic setup and examine some of the capabilities that the software has to offer. Some important items have been left out of the setup, but you can read about these in later articles in this series.
Installing the software
To install the Pacemaker and Corosync software on OpenSUSE, use the following command:
zypper install pacemaker pacemaker-mgmt
This command will install all Pacemaker software that is necessary for running a Linux HA environment to your server. Typically, this command is run on all nodes that are used in the HA cluster, but for setting up a test environment, it is fine to run the command on one node only. Once finished, you can start configuring the software to build your cluster.
The lower layers of the cluster are serviced by the Corosync process, which needs a major configuration file in /etc/corosync/corosync.conf. This file is used to specify how nodes in the cluster should get in touch with each other. The installation will give you a file with the name corosync.conf.example, which contains nearly everything you need to start the cluster. Only one setting needs adjustment, and that is the interface setting, located in the totem section of the configuration file. Use the ip address show command to determine the IP address of each system in the cluster and make sure the network settings that are used correspond to the actual network addresses that you are using:
Listing 1: Make sure to change the interface settings to reflect your current network settings.
After creating the corosync.conf file with the right network settings, it's time to start the openais service, which is responsible for starting Corosync on OpenSUSE . Use the service openais start command:
service openais start
After starting the openais service, you can run the crm_mon command. This command will show you whether a cluster stack is available, and it also gives you the number of nodes currently in the cluster. If you see something else in the output--anything really--it's okay to continue, even if the nodes in the cluster are marked as currently being offline.
Figure 1: Make sure that the Corosync layer is up before continuing.
Configuring Linux HA for services
Once the Corosync layer is up, you can continue creating HA for a service. To make this example easy to understand, I'll show you how to create a high-availability IP address. The first step in doing this is to create a password for the user hacluster--the default user account that is used in a cluster environment. To do this, use the command passwd hacluster and enter the password of your choice.
At this point, you can start the Pacemaker graphical management client using the crm_gui command. From the graphical interface, select Connection login and authenticate as the hacluster user. You now see the contents of your cluster with just the nodes that you've added to the cluster being displayed in it. To start adding your HA IP address, click Configuration, then click Resources and next click Add. From the Add window, select Primitive to add a normal service as a resource and click OK. Now you'll see the Add Primitive window, from which you can enter an ID. Next, make sure the following parameters are entered:
Also, make sure that the initial state of the resource is set to Started. Next, click Forward, which brings you to the interface where you can add the attributes for the resource you've just created. From here, click ip and select Edit to enter a new and unique IP address that you want to add as the highly available IP address. Typically, this could be the unique IP address on which your services can be reached. Now, click OK to add the IP address, and then click Apply to write it to the cluster.
Normally, you would also need to set up STONITH to guarantee integrity of the nodes in the cluster. As this topic will be discussed in the next part of this article, you can now skip this step by selecting Configuration, then CRM Configure and deselecting the Stonith Enabled option. Click Apply to save this change, and that should give you a highly available IP address. You can confirm this by selecting Configuration, then click Management from the graphical interface.
Figure 2: After configuring a resource for HA, you can confirm that it has succeeded from the Management part of crm_gui.
Now it's time for a final test: The IP address you've just configured should be managed by the cluster, which means that the cluster has to start the IP address after it has been stopped running. You can test this by disabling the IP address manually. For example, if you've used the address 192.168.1.169, which is bound to the interface eth0, use ip addr del dev eth0 192.168.1.169. After a few seconds, check the existence of the IP address using ip addr show. The cluster should have restarted the node at that IP address once again.
In this tip, you've read how to set up a basic HA cluster. This cluster is in no way ready for production, as you haven't taken care of vital services, such as STONITH and shared storage, but it does give a good impression on the required steps to set up a Linux HA cluster. In the next tip in this series about clustering, you'll read how to use a shared file system in your Linux HA cluster.
About the author: Sander van Vugt is an independent trainer and consultant living in the Netherlands. Van Vugt is an expert in Linux high availability, virtualization and performance and has completed several projects that implement all three. Sander is also a regular speaker on many Linux conferences all over the world. He is also the writer of various Linux-related books, such as Beginning the Linux Command Line, Beginning Ubuntu Server Administration and Pro Ubuntu Server Administration.