Posted by: kezhong | March 28, 2010

Setup Linux loadbalancer with Piranha and LVS on CentOS 5.4

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


Responses

  1. Thanks for these posts. Enjoyed reading them on the cdot planet.

  2. 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.

    • have you checked the log info?

  3. 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?

  4. 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

  5. […] Setup Linux loadbalancer with Piranha and LVS on CentOS 5.4 […]

  6. Hello, do you use 4 machines? 2 for lvs and other 2 for the server?

  7. Thank you very much. The blog helps me a lot. I really appreciate that.

  8. 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.

  9. hye..i folow this tuto..but why when i run command ipvsadm,the real server not appear in routing table?

    please help me..!

  10. p/s : real server not appear at ipvsadm routing table when i configure for mysql load balancing cluster..

  11. Nice job .. defo way more easier than ldirector and heartbeat

  12. Can i use it to load balance DNS port 53 UDP?

  13. 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..

    • 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

      • 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.. :(

      • 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

      • 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..

      • 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..

      • i just didn’t list /etc/sysctl.conf file

      • owh ok..
        i dont know why it not working on me..
        so frustrated..

    • You just want to add these lines on each real server

      #iptables -t nat -A PREROUTING -p -d –dport -j REDIRECT
      # service iptables save
      # chkconfig –level 2345 iptables on

      the source: http://www.centos.org/docs/5/html/Virtual_Server_Administration/s2-lvs-direct-iptables-VSA.html

  14. 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.

  15. […] 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 […]

  16. 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..

    • try to disable SELinux for httpd and restart httpd service
      # setsebool httpd_disable_trans 1
      # service httpd restart

      • it works..! thanks.. :)

  17. 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 :)

  18. I did all teh tutorial, but I don’t know how to test it, please tell me

  19. I did all teh tutorial, but I don’t know how to test it, please tell me

  20. thank you very much.

  21. I see, you use 4 server,I want load balancing squid but I only have 3 server, and I want all server serve squid, can i install squid+lvs+piranha in all server , so all server have vip? will it load balance?

  22. […] StumbleUpon […]

  23. I have only 2 hardware servers. can I install on both CENTOS and Piranha, so each are at the same time load balancer and web server (Apache)?

  24. simply and very clear. Thank You.

  25. I do not leave a comment, however after reading through some of the comments here Setup Linux loadbalancer with Piranha and LVS on
    CentOS 5.4 | Kezhong’s Weblog. I do have a couple of questions for you if it’s
    allright. Could it be simply me or does it look like like a few of
    the responsses appear aas iff they are left by brain dead visitors?
    :-P And, if you are writing onn additional social sites, I would like to keep up
    with you. Would you post a list of all of your public sites like
    your linkedin profile, Facebook page or twitter feed?

  26. Ӏt’s really a cool and useful piece of informatiοn. І am satisfied
    that you just shaгed thiѕ helpful information with us.
    Please staу us up to date like this. Thank you for sharing.

  27. i cant see Clustering when i try # yum grouplist
    How can i find and install it.Please someone help me

  28. I want to add 2 VIP interface configuration in piranha lvs.cf config file, how can I do that, could you please help me?

    Thanks in advance.


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

Categories

%d bloggers like this: