Configuring A High Availability Cluster On RHEL/CentOS

This guide shows how you can set up a two node, high-availability HTTP cluster with heartbeat on RHEL/CentOS. Both nodes use the Nginx web server to serve the same content.

Pre-Configuration Requirements

  1. Assign hostname nginx-primary to primary node with IP address 192.168.100.203 to eth0.
  2. Assign hostname nginx-slave to slave node with IP address 192.168.100.204 to eth0.

Note: on nginx-primary

uname -n

must return nginx-primary.

On nginx-slave

uname -n

must return nginx-slave.

192.168.100.9 is the virtual IP address that will be used for our Nginx webserver (i.e., Nginx will listen on that address).

Assume that Nginx web server has been installed and configured correctly on both nodes.

Configuration

  1. Download and install the heartbeat package on both nodes. In our case we are using RHEL/CentOS so we will install heartbeat with yum:
  2. yum install heartbeat

  3. Now we have to configure heartbeat on our two node cluster. We will deal with three files. These are:
  4. authkeys
    ha.cf
    haresources

  5. Now moving to our configuration. But there is one more thing to do, that is to copy these files to the /etc/ha.d directory. In our case we copy these files as given below:
  6. cp /usr/share/doc/heartbeat-2.1.4/authkeys /etc/ha.d/
    cp /usr/share/doc/heartbeat-2.1.4/ha.cf /etc/ha.d/
    cp /usr/share/doc/heartbeat-2.1.4/haresources /etc/ha.d/

  7. Now let’s start configuring heartbeat. First we will deal with the authkeys file, we will use authentication method 2 (sha1). For this we will make changes in the authkeys file as below.
  8. vi /etc/ha.d/authkeys

    Then add the following lines:

    auth 2
    2 sha1 test-nginx-ha

    Change the permission of the authkeys file:

    chmod 600 /etc/ha.d/authkeys

  9. Moving to our second file (ha.cf) which is the most important. So edit the ha.cf file with vi:
  10. vi /etc/ha.d/ha.cf

    Add the following lines in the ha.cf file:

    logfile /var/log/ha-log
    logfacility local0
    keepalive 2
    deadtime 30
    initdead 120
    bcast eth0
    udpport 694
    auto_failback on
    node nginx-primary
    node nginx-slave

    Note: nginx-primary and nginx-slave is the output generated by

    uname -n

  11. The final piece of work in our configuration is to edit the haresources file. This file contains the information about resources which we want to highly enable. In our case we want the webserver (nginx) highly available:
  12. vi /etc/ha.d/haresources

    Add the following line:

    nginx-primary 192.168.100.9 nginx
  13. Copy the /etc/ha.d/ directory from nginx-primary to nginx-slave:
  14. scp -r /etc/ha.d/ root@nginx-slave:/etc/

  15. Create the file index.html on both nodes:
  16. On nginx-primary:

    echo "nginx-primary test server" > /usr/html/index.html

    On nginx-slave:

    echo "nginx-slave test server" > /usr/html/index.html

  17. Now start heartbeat on the primary nginx-primary and slave nginx-slave:
  18. /etc/init.d/heartbeat start

  19. Open web-browser and type in the URL:
  20. http://192.168.100.9

    It will show “nginx-primary test server”.

  21. Now stop the hearbeat daemon on nginx-primary:
  22. /etc/init.d/heartbeat stop

    In your browser type in the URL http://192.168.100.9 and press enter.

    It will show “nginx-slave test server”.

  23. We don’t need to create a virtual network interface and assign an IP address (192.168.100.9) to it. Heartbeat will do this for you, and start the service (nginx) itself. So don’t worry about this.

    Don’t use the IP addresses 192.168.100.203 and 192.168.100.204 for services. These addresses are used by heartbeat for communication between nginx-primary and nginx-slave. When any of them will be used for services/resources, it will disturb hearbeat and will not work. Be carefull!!!

5 comments to Configuring A High Availability Cluster On RHEL/CentOS

  • Jithin

    Hai,

    Greate info. I would like to configure HA in my Webserver (Apache 2.2,Ubuntu Server 9.10). MySQl 5.0, VSFTPD also configured in the same server.

    I want to highly available apache and FTP. And i would like to know how the data will be shared in each nodes. ie
    if anybody upload some data to my FTP (Primary nod) so how the replication happening or how the data available to secondary node.

    Regards

    jithin k

  • Christian

    if I create an account in the primary will automatically zimbra
    zimbra created in the secondary ??

  • This article is just a sample. Actual implementation should be different among cases.
    Please give me your detailed requirements if you would like to have a support.

  • Outlaw Ever

    Salut,
    j’essaye d’installer un serveur de messagerie zimbra sous cente OS en clustering HA, avec Windows server 2008 en tant que contrôleur de domaine et serveur DNS.

    ma question c’est concernant le LDAP : comment faire pour importer les utilisateur Active Directory à fin de créer des comptes mail sur l’interface admin sous zimbra?

    merci d’avance.

  • In your case, you can configure Zimbra to authenticate user via Active Directory.
    You can see a lot of useful information by googling the phrase “zimbra active directory”.

    Please contact back to me at tuanta@iwayvietnam.com if you need any further support.

Leave a Reply

  

  

  


+ three = 7

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

AddThis Social Bookmark Button
AddThis Feed Button
Gop da xay Truong Sa

464
Unique Visitors
TODAY
Powered By Google Analytics

Get Zimbra email and collaboration server, hosted business email
This work is licensed under a

Creative Commons License