{"id":515,"date":"2010-05-19T09:21:48","date_gmt":"2010-05-19T02:21:48","guid":{"rendered":"http:\/\/blog.iwayvietnam.com\/tuanta\/?p=515"},"modified":"2010-05-19T09:21:48","modified_gmt":"2010-05-19T02:21:48","slug":"configuring-a-high-availability-cluster-on-rhel-centos","status":"publish","type":"post","link":"https:\/\/blog.iwayvietnam.com\/tuanta\/2010\/05\/configuring-a-high-availability-cluster-on-rhel-centos\/","title":{"rendered":"Configuring A High Availability Cluster On RHEL\/CentOS"},"content":{"rendered":"<p>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.<\/p>\n<h3>Pre-Configuration Requirements<\/h3>\n<ol>\n<li>Assign hostname nginx-primary to primary node  with IP address 192.168.100.203 to eth0.<\/li>\n<li>Assign hostname nginx-slave to slave node  with IP address 192.168.100.204 to eth0.<\/li>\n<\/ol>\n<p>Note: on nginx-primary<\/p>\n<p><code>uname -n<\/code><\/p>\n<p>must return nginx-primary.<\/p>\n<p>On nginx-slave<\/p>\n<p><code>uname -n<\/code><\/p>\n<p>must return nginx-slave.<\/p>\n<p>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).<\/p>\n<p>Assume that Nginx web server has been installed and configured correctly on both nodes.<\/p>\n<h3>Configuration<\/h3>\n<ol>\n<li>Download and install the heartbeat package on both nodes. In our case we are  using RHEL\/CentOS so we will install heartbeat with yum:<\/li>\n<p><code>yum install heartbeat<\/code><\/p>\n<li>Now we have to configure heartbeat on our two node cluster. We  will deal with three files. These are:<\/li>\n<p><code>authkeys<br \/>\nha.cf<br \/>\nharesources<\/code><\/p>\n<li>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:<\/li>\n<p><code>cp \/usr\/share\/doc\/heartbeat-2.1.4\/authkeys \/etc\/ha.d\/<br \/>\ncp \/usr\/share\/doc\/heartbeat-2.1.4\/ha.cf \/etc\/ha.d\/<br \/>\ncp \/usr\/share\/doc\/heartbeat-2.1.4\/haresources \/etc\/ha.d\/<br \/>\n<\/code><\/p>\n<li>Now let&#8217;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.<\/li>\n<p><code>vi \/etc\/ha.d\/authkeys<\/code><\/p>\n<p>Then add the following lines:<\/p>\n<pre>auth 2\r\n2 sha1 test-nginx-ha<\/pre>\n<p>Change the permission of the authkeys  file:<\/p>\n<p><code>chmod 600 \/etc\/ha.d\/authkeys<\/code><\/p>\n<li>Moving to our second file (ha.cf)  which is the most important. So edit the ha.cf  file with vi:<\/li>\n<p><code>vi \/etc\/ha.d\/ha.cf<\/code><\/p>\n<p>Add the following lines in the ha.cf  file:<\/p>\n<pre>logfile \/var\/log\/ha-log\r\nlogfacility local0\r\nkeepalive 2\r\ndeadtime 30\r\ninitdead 120\r\nbcast eth0\r\nudpport 694\r\nauto_failback on\r\nnode nginx-primary\r\nnode nginx-slave<\/pre>\n<p>Note: nginx-primary and nginx-slave  is the output generated by<\/p>\n<p><code>uname -n<\/code><\/p>\n<li>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:<\/li>\n<p><code>vi \/etc\/ha.d\/haresources<\/code><\/p>\n<p>Add the following line:<\/p>\n<pre>nginx-primary 192.168.100.9 nginx<\/pre>\n<li>Copy the \/etc\/ha.d\/ directory from nginx-primary to nginx-slave:<\/li>\n<p><code>scp -r \/etc\/ha.d\/ root@nginx-slave:\/etc\/<\/code><\/p>\n<li>Create the file index.html on both nodes:<\/li>\n<p>On nginx-primary:<\/p>\n<p><code>echo \"nginx-primary test server\" &gt; \/usr\/html\/index.html<\/code><\/p>\n<p>On nginx-slave:<\/p>\n<p><code>echo \"nginx-slave test server\" &gt; \/usr\/html\/index.html<\/code><\/p>\n<li>Now start heartbeat on the primary nginx-primary  and slave nginx-slave:<\/li>\n<p><code>\/etc\/init.d\/heartbeat start<\/code><\/p>\n<li>Open web-browser and type in the URL:<\/li>\n<p><code>http:\/\/192.168.100.9<\/code><\/p>\n<p>It will show &#8220;nginx-primary test server&#8221;.<\/p>\n<li>Now stop the hearbeat daemon on nginx-primary:<\/li>\n<p><code>\/etc\/init.d\/heartbeat stop<\/code><\/p>\n<p>In your browser type in the URL http:\/\/192.168.100.9  and press enter.<\/p>\n<p>It will show &#8220;nginx-slave test server&#8221;.<\/p>\n<li>We don&#8217;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&#8217;t worry about this.\n<p>Don&#8217;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!!!<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>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 Assign hostname nginx-primary to primary node with IP address 192.168.100.203 to eth0. Assign hostname nginx-slave to slave node with IP address 192.168.100.204 to<a class=\"more-link\" href=\"https:\/\/blog.iwayvietnam.com\/tuanta\/2010\/05\/configuring-a-high-availability-cluster-on-rhel-centos\/\">Continue reading <span class=\"screen-reader-text\">&#8220;Configuring A High Availability Cluster On RHEL\/CentOS&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,62,34],"tags":[],"class_list":["post-515","post","type-post","status-publish","format-standard","hentry","category-linux","category-nginx","category-weekly-tips","entry"],"_links":{"self":[{"href":"https:\/\/blog.iwayvietnam.com\/tuanta\/wp-json\/wp\/v2\/posts\/515"}],"collection":[{"href":"https:\/\/blog.iwayvietnam.com\/tuanta\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.iwayvietnam.com\/tuanta\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.iwayvietnam.com\/tuanta\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.iwayvietnam.com\/tuanta\/wp-json\/wp\/v2\/comments?post=515"}],"version-history":[{"count":4,"href":"https:\/\/blog.iwayvietnam.com\/tuanta\/wp-json\/wp\/v2\/posts\/515\/revisions"}],"predecessor-version":[{"id":519,"href":"https:\/\/blog.iwayvietnam.com\/tuanta\/wp-json\/wp\/v2\/posts\/515\/revisions\/519"}],"wp:attachment":[{"href":"https:\/\/blog.iwayvietnam.com\/tuanta\/wp-json\/wp\/v2\/media?parent=515"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.iwayvietnam.com\/tuanta\/wp-json\/wp\/v2\/categories?post=515"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.iwayvietnam.com\/tuanta\/wp-json\/wp\/v2\/tags?post=515"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}