Debian: Install and Configure VRRP with KeepAlived

Debian: Install and Configure VRRP with KeepAlived

A quick and easy guide on how to implement VRRP between two servers using the KeepAlived daemon

Scenario Diagram

vrrp

Server 1: 192.168.1.3

Install and download Keepalived

apt-get install -y keepalived

Create a new config file

nano /etc/keepalived/keepalived.conf

Add some global Params to config file

global_defs {
# Email Alert Configuration
notification_email {
# Email To Address
admin@example.com
}
# Email From Address
notification_email_from noreply@example.com
# SMTP Server Address / IP
smtp_server 127.0.0.1
# SMTP Timeout Configuration
smtp_connect_timeout 60
router_id Example-Router-01
}

Add a VRRP sync group

vrrp_sync_group VG1 {
group {
Example_Inst
}
}

Create a VRRP Instance

vrrp_instance Example_Inst {
# State = Master or Backup
state MASTER
# Interface ID for VRRP to run on
interface eth0
# VRRP Router ID
virtual_router_id 10
# Highest Priority Wins
priority 250
# VRRP Advert Intaval 1 Second
advert_int 1
# Basic Inter Router VRRP Authentication
authentication {
auth_type PASS
auth_pass ChangeMeTestPassword123456789
}
# VRRP Virtual IP Address Config
virtual_ipaddress {
192.168.1.2/24 dev eth0
}
}

Once config file has been built save the file

Start KeepAlived Service

service keepalived start

Check Service Status

service keepalived status

Server 2: 192.168.1.4

Install and download Keepalived

apt-get install -y keepalived

Create a new config file

nano /etc/keepalived/keepalived.conf

Add some global Params to config file

global_defs {
 notification_email {
 admin@example.com
 }
 notification_email_from noreply@example.com
 smtp_server 127.0.0.1
 smtp_connect_timeout 60
 router_id Example-Router-02
}

Add a VRRP sync group

vrrp_sync_group VG1 {
 group {
 Example_Inst
 }
}

Create a VRRP Instance

vrrp_instance Example_Inst {
# State = Master or Backup
 state BACKUP
# Interface ID for VRRP to run on
 interface eth0
# VRRP Router ID
 virtual_router_id 10
# Highest Priority Wins
 priority 150
# VRRP Advert Intaval 1 Second
 advert_int 1
# Basic Inter Router VRRP Authentication
 authentication {
 auth_type PASS
 auth_pass ChangeMeTestPassword123456789
 }
# VRRP Virtual IP Address Config
 virtual_ipaddress {
 192.168.1.2/24 dev eth0
 }
}
 

Once config file has been built save the file

Start KeepAlived Service

service keepalived start

Check Service Status

service keepalived status

Verify VRRP

Perform a ping to the VRRP VIP

ping 192.168.1.2

On the master server check IP address list to see whether the VIP is active on the master host

ip addr list
Advertisements