KeepAlived is a useful module that allows you to setup a high availability cluster for proxy servers such as NGINX, HAProxy, etc. It also supports load balancing & node monitoring, and automatically fails over in case one of the cluster nodes goes down. In this article, we will look at how to install KeepAlived in CentOS 7 from source.
Install KeepAlived in CentOS 7
Here are the steps to install KeepAlived in CentOS 7.
1. Install Prerequisites
Open terminal and run the following command to install couple of prerequisites for KeepAlived.
$ sudo yum -y install kernel-headers kernel-devel
2. Download KeepAlived Source
Go to KeepAlived website and download the latest version of source code. At the time of writing this article, v2.2.2 is the latest version so we will proceed with that.
$ sudo wget https://www.keepalived.org/download.html
3. Extract tarball
The source code is present in a .tar.gz file so we will extract using tar command
$ sudo tar -xvf keepalived-2.2.2.tar.gz
4. Compile & Install
The above command will create a folder keepalived-2.2.2 in your present working directory. cd to that folder, compile & install keepalived with the following commands.
$ cd keepalived-2.0.13 $ ./configure $ make && make install
5. Copy configuration file
Keepalived comes with a default configuration file that is good enough for most cases. We will copy that file and add it to init services.
$ sudo cp ./keepalived/keepalived /usr/sbin/ $ sudo cp ./keepalived/etc/init.d/keepalived /etc/init.d/ $ mkdir /etc/keepalived $ sudo cp ./keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf $ sudo cp ./keepalived/etc/sysconfig/keepalived /etc/sysconfig/keepalived
6. Enable & Start KeepAlived
Next, enable service to auto-start on system reboot, and also start the service right now.
$ sudo service enable keepalived $ sudo service start keepalived
The main configuration file for KeepAlived in /usr/local/etc/keepalived/keepalived.conf.
KeepAlived is a great load balancing and cluster monitoring tool for popular reverse proxy servers such as NGINX, HAProxy and lighttpd. It allows you to create a high availability cluster by assigning 2 or more nodes a virtual IP address. It monitors those nodes and fails over in case one of the nodes goes down. It implements a set of health checkers to dynamically maintain and manage load load balancer server pools, based on their performance. It is a good asset in a distributed server environment.