I could use LVS, ldirectord, and heartbeat to implement load balancing, but I find there is another more easy way which is Redhat’s piranha. You need not configure four configuration files, instead of only one which can be configured by web-based tool.
My lab environment was similar to my last post.
LVS Router 1: eth0: 192.168.26.201
LVS Router 2: eth0: 192.168.26.202
Real Server 1: eth0: 192.168.26.211
Real Server 2: eth0: 192.168.26.212
VIP: 192.168.26.200
gateway: 192.168.26.1
Install piranha and ipvsadm packages on the LVS Routers
# yum install ipvsadm
# yum install piranha
Configuring Services on the LVS Routers
# chkconfig pulse on
# chkconfig piranha-gui on
# chkconfig httpd on
Setting a Password for the Piranha Configuration Tool
# piranha-passwd
Turning on Packet Forwarding on the LVS Routers
# echo 1 > /proc/sys/net/ipv4/ip_forward
Starting the Piranha Configuration Tool Service
Modify the mode SELinux in permissive mode. If you didn’t do it, it would show the error massage as below when you started the piranha-gui service.
Starting piranha-gui: (13)Permission denied: make_sock: could not bind to address [::]:3636
(13)Permission denied: make_sock: could not bind to address 0.0.0.0:3636
No listening sockets available, shutting down
Unable to open logs
# setenforce 0
# service httpd start
# service piranha-gui start
Configuring the LVS Routers with Piranha Configuration Tool
Open http://192.168.26.201:3636 in a Web browser to access the Piranha Configuration Tool. Click on the Login button and enter piranha for the Username and the administrative password you created in the Password field.
Click on the GLOBAL SETTINGS panel, and input the primary server public IP, and then click the ACCEPT button.
Click on the REDUNDANCY panel, and input the redundant server public IP, and then click the ACCEPT button.
Click on the VIRTUAL SERVERS panel, add a server, edit it, and activate it.
Clicking on the REAL SERVER subsection link at the top of the panel displays the EDIT REAL SERVER subsection. Click the ADD button to add new servers, edit them and activate them.
Copy the lvs.cf file to another LVS router.
# scp /etc/sysconfig/ha/lvs.cf root@192.168.26.202:/etc/sysconfig/ha/lvs.cf
Start the pulse services on the LVS Routers
# service pulse restart
Test
The test way used my last post. You can also use the Apache HTTP server benchmarking tool (ab) to simulate users’ visit.
References
Linux Virtual Server Administration





Thanks for these posts. Enjoyed reading them on the cdot planet.
By: t0mmyw on March 29, 2010
at 3:47 pm
What about arp requests etc?
I tried the piranha mode but even if I am using the RR algorithm all request are forwarded to server2 (and not randomly to server1).
When I then stop apache on server2 it does not fallback to server1.
Have you tried it and I’ve read that you have to use aprtables or such otherwise things don’t work.
By: Michiel on April 27, 2010
at 7:32 am
have you checked the log info?
By: Anonymous on April 27, 2010
at 10:26 am
I am trying to get mine to work. Question: Do I create the eth0:1 for VIP using the Piranha gui or using the /etc/sysconfig/network-scripts/ifcfg-eth0:1 file?
Then, what about routing from the real servers to the LVS?
By: Willie on June 14, 2010
at 5:07 am
Willie you can create the ifcfg-eth0:1 files on both servers.
And do not for get to change the name on the interface or your netowrk will fobar.
Also you do not need the mac address in the eth0:1 file it uses the parent eth0 mac
By: straighshot on June 19, 2010
at 5:52 pm
[...] Setup Linux loadbalancer with Piranha and LVS on CentOS 5.4 [...]
By: Red Hat Cluster Piranha – Linux Virtual Server安装部署 - 阿泰的菜园 on August 31, 2010
at 12:09 am
Hello, do you use 4 machines? 2 for lvs and other 2 for the server?
By: David on September 2, 2010
at 6:06 pm
Thank you very much. The blog helps me a lot. I really appreciate that.
By: dilmah on October 15, 2010
at 5:55 am
BTW, could you help me about MySQL HA issues (Replication, Mysql Cluster – NDB Cluster, MySQL proxy) combined with Linux loadbalancer with Piranha and LVS? Thank you very much, again.
By: dilmah on October 15, 2010
at 6:02 am
hye..i folow this tuto..but why when i run command ipvsadm,the real server not appear in routing table?
please help me..!
By: nana on November 12, 2010
at 1:22 pm
p/s : real server not appear at ipvsadm routing table when i configure for mysql load balancing cluster..
By: nana on November 12, 2010
at 1:30 pm
Nice job .. defo way more easier than ldirector and heartbeat
By: Simone on February 28, 2011
at 5:59 pm
Can i use it to load balance DNS port 53 UDP?
By: Medo on May 30, 2011
at 7:17 am
nice tutor..
i follow ur tutor but when i tried to launch the web site http://192.168.26.200 through the web browser at another machine i cant access the web server..
im using CentOS for piranha
and using windows for the web server..
and the only changes that i make that that not follow ur tutor is subnetmask for vip to 255.255.255.0…
really need ur help..tq..
By: saiful on June 10, 2011
at 7:54 pm
try to append the following lines to the /etc/sysctl.conf file, and execute “sysctl -p”.
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.eth0.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.eth0.arp_announce = 2
By: kezhong on June 10, 2011
at 8:47 pm
im truly grateful for ur assistant..
i already add the following line that ur mention above on both LVS..
but still give the same result.
because tomorrow will be sunday my university lab will be close. under those circumstance i can only implement this load balancer using VMWare.
maybe using simulation cause it doesn’t .
the gateway 192.168.26.1 gateway is the router ip right?
off topic: did u know how to implement HA load balancer using keepalived on fedora? im asking u because im also try implement load balancing using fedora but got problem same like now cant access VIP from others machine.. :(
By: saiful on June 11, 2011
at 8:11 am
did you check your firewall? when you did lab, you could stop iptables.
as for HA, you can see my past post
Setup Linux loadbalancer with LVS, ldirectord and heartbeat
By: kezhong on June 11, 2011
at 9:32 am
i already disable firewall on both real server..
and set SELinux in permissive mode at the installation proses..
okey, at the lab tomorrow i will stop iptable and give feed back to u again..
the command is /etc/init.d/iptables stop, right??
tq cause helping me..
By: saiful on June 12, 2011
at 8:48 am
i already test at the real environment..
and already stop the iptables..
but like before still cant get web page went browse virtual ip..
question :-
1- suppose if I follow all ur guide above i can view web page if browse using virtual ip right?
2- is there any configuration that i need to do that u dont list at above?
im so sory if i ask u to much, but i really need this load balancer working, because my final year project title about web server load balancer..
By: saiful on June 14, 2011
at 10:31 am
i just didn’t list /etc/sysctl.conf file
By: kezhong on June 14, 2011
at 7:46 pm
owh ok..
i dont know why it not working on me..
so frustrated..
By: saiful on June 15, 2011
at 7:53 am
hellow kezhong.
i follow all your configuration.
at the real server did i need to configure anything?
because i find this note if i set Direct Routing :
http://www.centos.org/docs/5/html/Virtual_Server_Administration/s2-lvs-direct-iptables-VSA.html
Direct Routing and IPTables or Direct Routing and arptables_jf must be set on real server.
By: terminology on June 16, 2011
at 4:49 am
[...] graphical interactivity with the configuration. Kezhong has a very good installation guide on his blog, which we are using to install this portion of the [...]
By: Wordpress in a Commercial Environment « Lord Brockett's Blog on August 25, 2011
at 6:01 pm
hello,,
I have enable config on selinux. I have succesfully execute setenforce 0. But I still have error when execute piranha-gui start.
– Starting piranha-gui: (13)Permission denied: make_sock: could not bind to address [::]:3636
(13)Permission denied: make_sock: could not bind to address 0.0.0.0:3636
No listening sockets available, shutting down
Unable to open logs –
please help..
By: shita on September 27, 2011
at 5:10 am
try to disable SELinux for httpd and restart httpd service
# setsebool httpd_disable_trans 1
# service httpd restart
By: kezhong on September 27, 2011
at 9:43 am
it works..! thanks.. :)
By: shita on September 27, 2011
at 8:50 pm
hello kezhong..
I’ve already installed piranha on server 192.168.10.111 and I have 3 real servers with port 9086,9081,9082…
I input ip 192.168.10.111 on global setting, redundancy blank, and virtual server 192.168.10.111 …
but it didn’t work …
what is the differently between virtual server and LVS router? Where can I setting the virtual server? thanks somuch..
need u r help :)
By: shita on September 27, 2011
at 9:40 pm