Operations 7 min read

Master Keepalived: Install, Configure, and Optimize High‑Availability Load Balancing

This guide walks you through installing Keepalived via yum or source, explains the main configuration sections—including global definitions, VRRP instances, and virtual servers—and details each directive’s purpose, enabling you to set up reliable high‑availability load balancing on Linux systems.

Open Source Linux
Open Source Linux
Open Source Linux
Master Keepalived: Install, Configure, and Optimize High‑Availability Load Balancing

In the previous article we gave a brief introduction to Keepalived; today we continue learning how to use the Keepalived service.

Installation of Keepalived Service

There are two installation methods:

(1) Install via yum

yum -y install keepalived

# View installation files
rpm -ql keepalived

(2) Install from source

1) Install dependencies
yum -y install gcc openssl-devel libnfnetlink-devel

2) Download source
wget https://www.keepalived.org/software/keepalived-1.4.5.tar.gz

3) Extract
tar -zxvf keepalived-1.4.5.tar.gz -C /usr/src

4) Compile and install
cd /usr/src/keepalived-1.4.5/
./configure && make -j 4 && make install

Keepalived Configuration File Analysis

The main configuration file is located at

/etc/keepalived/keepalived.conf

. A typical configuration contains three sections:

! Configuration File for keepalived
# Global definition block
global_defs {
   ...
}

# VRRP instance definition block
vrrp_instance VI_1 {
   ...
}

# Virtual server definition block
virtual_server 10.10.10.2 1358 {
   ...
}
Note: The global definition block is mandatory; the virtual server block is optional if Keepalived is used only for HA.

1) Global Definition Block

This block sets the fault‑notification mechanism and the router ID. Example:

Parameter explanations:

First line is a comment.

Lines 4‑8 configure email notifications for fault alerts (optional, not recommended; requires sendmail, third‑party monitoring such as Nagios is preferred).

Line 9 specifies the sender address (optional).

Line 10 specifies the SMTP server address (optional).

Line 11 specifies the SMTP connection timeout (optional).

Line 12 identifies the node name, usually the hostname.

2) VRRP Instance Definition Block

Parameter explanations:

Line 15 defines a VRRP instance named

VI_1

.

Line 16 sets the role state, either

MASTER

or

BACKUP

.

Line 17 specifies the external network interface (e.g., eth0, ens33).

Line 18 defines the virtual router ID; IDs must match across instances to avoid split‑brain.

Line 19 sets the priority; higher numbers mean higher priority.

Line 20 sets

advert_int

, the synchronization interval (default 1 s).

Lines 21‑24 configure authentication.

Lines 25‑29 list virtual IP addresses; multiple IPs can be configured, each on its own line, and these IPs are the ones bound to the domain for HA services.

3) Virtual Server Definition Block

Parameter explanations:

virtual_server

: defines a virtual server using one of the IPs from

virtual_address

. Syntax:

ip port

.

Line 58:

delay_loop 6

– health‑check interval in seconds.

Line 59:

lb_algo rr

– load‑balancing algorithm, round‑robin.

Line 60:

lb_kind NAT

– forwarding method; options are DR, NAT, TUN (DR is commonly used).

Line 61:

persistence_timeout 50

– session persistence timeout in seconds.

Line 62:

protocol TCP

– forwarding protocol (TCP or UDP).

real_server

: defines real server IP and port; multiple entries are allowed.

Line 67:

weight 1

– load weight; higher weight gives higher priority.

Line 81:

connect_timeout 3

– connection timeout in seconds.

Line 82:

nb_get_retry 3

– number of retry attempts.

Line 83:

delay_before_retry 3

– interval between retries in seconds.

high availabilityLoad BalancingconfigurationLinuxkeepalived
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.