Setup Load-Balancing Cluster with LVS and Piranha on Centos 6

Published December 3, 2013 by Siva

Terminology:

piranha – This is a package that provides a configuration interface for setting up LVS.

ipvs The name of the module that allows a load-balancing on Linux.

ipvsadm – A package (and a command) that makes administrating ipvs possible. Be aware, you either user piranha-gui or /etc/sysconfig/ipvsadm to configure ipvs.

LVS Linux Virtual Server – the project name of all tools used in this document.

pulse – A service (/etc/init.d/pulse) that runs on both active and backup machine and opens a port to make checking possible. piranha-gui configures everything, pulse actually activates all configurations.

nanny A process started by pulse to monitor the realservers.

nat – Network Address Translation. A common combination with LVS. In case NAT is uses, the loadbalancer/director/LVS accepts traffic on one the VIP and sends traffic to the realservers. Be aware, the current implementation of ipvsadm does not properly use Source NAT, it currently does not rewrite the source address.

direct routing – A method of routing available in LVS. Traffic is received on the VIP, sent through to the realservers. The realservers receive the traffic as if it was sent to the VIP, so the VIP must be configured on the realservers. To avoid arp-caches to register the wrong MAC-address-IP-address combination, a few “tricks” must be done.

wlc – Weighted Least Connections, an algorithm to balance load to realservers.

VIP Virtual IP. – The IP-address the service is configured on.

RIP Real server IP. – The IP-address of a real-server.

realserver – The server providing the actual service. This can be Linux, Windows, whatever.

This setup guide is about building web cluster with a pair of Linux loadbalancers as frontend.
It uses Linux Virtual Server(LVS) and Piranha. Piranha is a web-based gui installed in LVS Routers primarily to generating a valid /etc/lvs.cf file.

Start by installing LVS on LVS Router.

[root@lvsrouter ~]# yum groupinstall “Load Balancer”
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
ipvsadm x86_64 1.25-10.el6 base 41 k
piranha x86_64 0.8.6-2.el6_4.1 updates 623 k
Installing for dependencies:
libedit x86_64 2.11-4.20080712cvs.1.el6 base 74 k
libnl x86_64 1.1-14.el6 base 121 k
php x86_64 5.3.3-22.el6 base 1.1 M
php-cli x86_64 5.3.3-22.el6 base 2.2 M
php-common x86_64 5.3.3-22.el6 base 524 k

Transaction Summary
================================================================================
Install 7 Package(s)

Total download size: 4.7 M
Installed size: 18 M
Is this ok [y/N]: y

Start piranha and pulse services on reboot.

chkconfig piranha-gui on
chkconfig pulse on

Set a password for piranha web

/usr/sbin/piranha-passwd

Allow ports in iptables

vi /etc/sysconfig/iptables
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3636 -j ACCEPT

Edit piranha config

vi /etc/sysconfig/ha/conf/httpd.conf

Start the piranha gui service

service piranha-gui start

For LVS router to forward network packets properly to real servers, each LVS router node must have IP forwarding turned on. Turn on packet forwarding by editing sysctl.conf:

vi /etc/sysctl.conf
net.ipv4.ip_forward = 1

Reload sysctl

sysctl -p /etc/sysctl.conf

Start http services on the Real Servers

service httpd start

On the LVS Router, log in to the Piranha web ui to begin configuration.

Enter Primary Router’s IP address in “Global Settings”->”Primary server public IP:”.
CENTOS Piranha Global Settings

Enter Redundant Router’s IP address in “Redundancy”->”Redundant server public IP:”.
CENTOS Piranha Redundancy

Enter Virtual Server settings in “Virtual Servers”->”Virtual Server”.
CENTOS Piranha Virtual Servers

Include Real Server settings in “Virtual Servers”->”Real Server”.
CENTOS Piranha Real Server

On each time the Piranha Gui was changed, have to sync the settings to Backup Routers,
and restart the pulse service on both routers.

service pulse restart

To see the virtual server’s statistics, use “watch ipvsadm”.


[root@lvsrouter ~]# watch ipvsadm

Courtesy : http://iomeweekly.blogspot.in/2013/04/setup-load-balancing-cluster-with-lvs.html

Advertisements

One comment on “Setup Load-Balancing Cluster with LVS and Piranha on Centos 6

  • Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s

    %d bloggers like this: