Building Two-Node Directors/Real Servers using LVS and Keepalived

From LVSKB
Jump to: navigation, search

Introduction

This guide is a brief explanation on getting a two node director/real server setup going using LVS and keepalived.

This is an adaptation of the information at Ultra Monkey: Streamline High Availablility and Load Balancing to work with keepalived.

It is primarily targeted at RHEL3/4 (RedHat Enterprise Linux).

Goals

Setup a two node LVS cluster with Apache as the virtualised services, with both nodes operating as both directors and real servers.
Setup healthchecking of services (httpd).
Setup lvs-syncing of connections (ipvsadm sync daemon).

Knowledge Required

Understanding of Layer 3 load balancing.
Understanding of Linux LVS.
Understanding of Apache configuration.

Components Required

Base installation of RHEL3/4.
RPM Packages for httpd.
RPM Packages for keepalived.
RPM Packages for ipvsadm.

Instructions

Install keepalived and IPVSADM on both servers.

On the first server create the file /etc/keepalived/keepalived.conf :

global_defs {
  router_id DEV 
}
vrrp_instance VI_1 {
   state MASTER
   interface eth0
   virtual_router_id 51
   priority 100
   advert_int 10
   authentication {
       auth_type PASS
       auth_pass 1111
   }
   virtual_ipaddress {
      192.168.6.240
  }
}
virtual_server 192.168.6.240 80 {
   delay_loop 10
   lb_algo rr
   lb_kind DR
   persistence_timeout 5
   protocol TCP
   real_server 192.168.6.4 80 {
       TCP_CHECK {
       }
   }
   real_server 192.168.6.5 80 {
       TCP_CHECK {
       }
   }
 }
}

On the second server create the file /etc/keepalived/keepalived.conf :

global_defs {
  router_id DEV
}
vrrp_instance VI_1 {
   state BACKUP
   interface eth0
   virtual_router_id 51
   priority 99
   advert_int 10
   authentication {
       auth_type PASS
       auth_pass 1111
   }
   virtual_ipaddress {
      192.168.6.240
   }
}
virtual_server 192.168.6.240 80 {
   delay_loop 10
   lb_algo rr
   lb_kind DR
   persistence_timeout 5
   protocol TCP
   real_server 192.168.6.5 80 {
       TCP_CHECK {
       }
   }
}

On both servers create the file /etc/sysconfig/network-scripts/ifcfg-lo:0

DEVICE=lo:0
IPADDR=192.168.6.240
NETMASK=255.255.255.255
ONBOOT=yes
NAME=loopback

In order to avoid warning messages, we explicitly say that our gateway is on eth0. Add in /etc/sysconfig/network

GATEWAYDEV=eth0

Add in /etc/sysctl.conf :

net.ipv4.conf.eth0.arp_ignore = 1
net.ipv4.conf.eth0.arp_announce = 2
# Enables packet forwarding
net.ipv4.ip_forward = 1
ifup lo
sysctl -p

Architecture

Sl-ha-lb-eg.jpg


LVS.png "Building Two-Node Directors/Real Servers using LVS and Keepalived" is an LVS Example related stub. You can help LVSKB by expanding it