{"id":1033,"date":"2024-05-10T09:06:50","date_gmt":"2024-05-10T07:06:50","guid":{"rendered":"https:\/\/www.gonscak.sk\/?p=1033"},"modified":"2024-05-10T09:06:50","modified_gmt":"2024-05-10T07:06:50","slug":"centos-9-and-keeplived","status":"publish","type":"post","link":"https:\/\/www.gonscak.sk\/?p=1033","title":{"rendered":"Centos 9 and keeplived"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">What is Keepalived ?<\/h3>\n\n\n\n<p>Keepalived is a routing software written in C. The main goal of this project is to provide simple and robust facilities for loadbalancing and high-availability to Linux system and Linux based infrastructures. Loadbalancing framework relies on well-known and widely used <a href=\"http:\/\/www.linux-vs.org\">Linux Virtual Server (IPVS)<\/a> kernel module providing Layer4 loadbalancing. Keepalived implements a set of checkers to dynamically and adaptively maintain and manage loadbalanced server pool according their health. On the other hand high-availability is achieved by <a href=\"http:\/\/datatracker.ietf.org\/wg\/vrrp\/\">VRRP<\/a> protocol. VRRP is a fundamental brick for router failover. In addition, Keepalived implements a set of hooks to the VRRP finite state machine providing low-level and high-speed protocol interactions. In order to offer fastest network failure detection, Keepalived implements <a href=\"http:\/\/datatracker.ietf.org\/wg\/bfd\/\">BFD<\/a> protocol. VRRP state transition can take into account BFD hint to drive fast state transition. Keepalived frameworks can be used independently or all together to provide resilient infrastructures.<\/p>\n\n\n\n<p>As always, start with installint the software:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dnf install keepalived -y<\/pre>\n\n\n\n<p>Now, move original configuration file and create you own and insert values like below. This is configuration for primary (master) server1:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mv \/etc\/keepalived\/keepalived.conf \/etc\/keepalived\/keepalived.conf.original<br>vim \/etc\/keepalived\/keepalived.conf<br><br>global_defs {<br>  # Keepalived process identifier<br>  router_id apache<br>}<br><br># Script to check whether apache is running or not<br>vrrp_script check_httpd {<br>  script \"\/bin\/check_httpd.sh\"<br>  interval 2<br>  weight 50<br>}<br><br># Virtual interface - The priority specifies the order in which the assigned interface to take over in a failover<br>vrrp_instance apache {<br>  state MASTER<br>  interface ens18<br>  virtual_router_id 151<br>  priority 110<br><br>  # The virtual ip address shared between the two apache Web Servers which will float<br>  virtual_ipaddress {<br>    192.168.1.10\/24<br>  }<br>  track_script {<br>    check_httpd<br>  }<br>  authentication {<br>    auth_type PASS<br>    auth_pass secret<br>  }<br>}<\/pre>\n\n\n\n<p>Save and close the file when you are finished.<\/p>\n\n\n\n<p>On the secondary (slave) server2, edit the keepalived.conf file, very similar to our first:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mv \/etc\/keepalived\/keepalived.conf \/etc\/keepalived\/keepalived.conf.original<br>vim \/etc\/keepalived\/keepalived.conf<br><br>global_defs {<br>  # Keepalived process identifier<br>  router_id apache<br>}<br><br># Script to check whether apache is running or not<br>vrrp_script check_httpd {<br>  script \"\/bin\/check_httpd.sh\"<br>  interval 2<br>  weight 50<br>}<br><br># Virtual interface - The priority specifies the order in which the assigned interface to take over in a failover<br>vrrp_instance apache {<br>  state BACKUP<br>  interface ens18<br>  virtual_router_id 151<br>  priority 100<br><br>  # The virtual ip address shared between the two apache Web Servers which will float<br>  virtual_ipaddress {<br>    192.168.1.10\/24<br>  }<br>  track_script {<br>    check_httpd<br>  }<br>  authentication {<br>    auth_type PASS<br>    auth_pass secret<br>  }<br>}<\/pre>\n\n\n\n<p>Now we will need to create a script to check whether the apache service is running or not. You can create it using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">vim \/bin\/check_httpd.sh<br><br>#!\/bin\/sh<br>if [ -z \"`pidof httpd`\" ]; then<br>  exit 1<br>fi<\/pre>\n\n\n\n<p>Now we set proper permission with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">chmod 755 \/bin\/check_httpd.sh<\/pre>\n\n\n\n<p>Before we start keeplived daemon, if we have (I believe, you have) firewall enabled, enable vrrp protocol:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">firewall-cmd --add-protocol=vrrp  --permanent<br>firewall-cmd --add-protocol=vrrp<\/pre>\n\n\n\n<p>Finally, start keepalived service and enable it to start at system reboot using the following command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl enable keepalived --now<\/pre>\n\n\n\n<p>We can also check the status of keepalived service using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl status keepalived<\/pre>\n ","protected":false},"excerpt":{"rendered":"<p>What is Keepalived ? Keepalived is a routing software written in C. The main goal of this project is to provide simple and robust facilities for loadbalancing and high-availability to Linux system and Linux based infrastructures. Loadbalancing framework relies on well-known and widely used Linux Virtual Server (IPVS) kernel module providing Layer4 loadbalancing. Keepalived implements &hellip; <a href=\"https:\/\/www.gonscak.sk\/?p=1033\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Centos 9 and keeplived<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[149,94,151,152],"class_list":["post-1033","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-centos-9","tag-httpd","tag-keeplived","tag-vrrp"],"_links":{"self":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts\/1033","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1033"}],"version-history":[{"count":1,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts\/1033\/revisions"}],"predecessor-version":[{"id":1034,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=\/wp\/v2\/posts\/1033\/revisions\/1034"}],"wp:attachment":[{"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1033"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1033"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gonscak.sk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1033"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}