LVS cluster for Centos

An other cluster solution for Linux is LVS. I im testing to use LVS cluster for some cloud server. My cloudserver has one external ip and i want all traffic to come to that ip and after that be redirected to my web nodes. Witch LVS i will redirect all traffic to that ip and load balance it between my nodes. When i set up HAProxy i only loadbalanse webb traffic. In this guide i load balanse my ssh server between my two web nodes. (I already have Haproxy load balance my web)

So install the directory witch will receive and spreed the traffic.

# modprobe ip_vs
# cat /proc/net/ip_vs
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weghit ActiveConn InActConn


Install ipvsadm tool

yum install ipvsadm

I have an eth alias called and will use that to receive all my incoming traffic. Then i will have two nodes behind my directory that will do the work and ( is my heartbeat ip and will go to my secondary server for HA)

Enable packet forwarding
# echo 1 > /proc/sys/net/ipv4/ip_forward

Set up the director for round robin traffic

/sbin/ipvsadm -C
/sbin/ipvsadm -A -t -s rr
/sbin/ipvsadm -a -t -r -g
/sbin/ipvsadm -a -t -r -g

You can change the -g against -m -w 1

-m Using NAT load balancing -w 1 is the wight of the server
-r is for direct load balancing

read more here


The -rr tels witch type of load balasing you want to use

  • Round Robin (RR): New incoming connections are assigned to each realserver in turn.
  • Weighted Round Robin (WRR): RR scheduling with additional weighting factor to compensate for differences in realserver capabilities such as additional CPUs, more memory, and so on.
  • Least Connected (LC): New connections go to the realserver with the least number of connections. This is not necessarily the least-busy realserver, but it is a step in that direction.
  • Weighted Least Connection (WLC): LC with weighting.

List the config

/sbin/ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
 -> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP rr
 -> Local 1 0 0 
 -> Route 1 0 0

Now the director is done and its time to fix the real server (my direktor and realserver are the same )

The Realservers

start by altering some network settings .

Add this at the bottom of the file /etc/sysctl.conf

net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2

Reload the settings

sysctl -p


I have both my real server and directory on the same server so this is now working for me. I can now ssh to my ip and get round robin between the servers.
If you planning on using more servers ore NAT then you want to setup route rules.
See links for more info.