Showing posts with label LoadBalancer. Show all posts
Showing posts with label LoadBalancer. Show all posts

Monday 9 March 2015

Setup HAProxy (loadbalancing) on CentOS7

This guide looks into how to setup HAProxy on CentOS7. HAProxy offers load balanced services to HTTP and TCP-based services, such as internet-connected services and web-based applications.

In Apr 2013, we looked into how to Setup Load-Balancing Cluster with LVS and Piranha on Centos 6. This time round for CentOS7, we will setup HAProxy Loadbalancing Cluster as this is shipped with CentOS7.

Setup:
1. HAProxy Server at 192.168.1.3
2. LB Virtual IP to use 192.168.1.3
3. Web1 at 192.168.1.9
4. Web2 at 192.168.1.10

For all the servers, lets (temporary) remove the firewall and selinux.
systemctl stop firewalld
systemctl disable firewalld
vi /etc/selinux/config
disabled
reboot
Lets start, login to HAProxy Server:
yum install haproxy
vi /etc/haproxy/haproxy.cfg
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
    # to have these messages end up in /var/log/haproxy.log you will
    # need to:
    #
    # 1) configure syslog to accept network log events.  This is done
    #    by adding the '-r' option to the SYSLOGD_OPTIONS in
    #    /etc/sysconfig/syslog
    #
    # 2) configure local2 events to go to the /var/log/haproxy.log
    #   file. A line like the following can be added to
    #   /etc/sysconfig/syslog
    #
    #    local2.*                       /var/log/haproxy.log
    #
    log         127.0.0.1 local2

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon

    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend LB
   bind 192.168.1.3:80
   reqadd X-Forwarded-Proto:\ http
   default_backend LB

#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend LB 192.168.1.3:80
   mode http
   stats enable
   stats hide-version
   stats uri /stats
   stats realm Haproxy\ Statistics
   stats auth admin:pass4325    # HAProxy Statistic username/password
   balance roundrobin           # Load balancing to use round-robin
   option httpchk
   option httpclose
   option forwardfor
   cookie LB insert
   server web1 192.168.1.9:80  check  # backend server.
   server web2 192.168.1.10:80 check  # backend server.
We shell enable the service and start the service:
systemctl enable haproxy
systemctl start haproxy
At Webserver create a test page.
vi /var/www/html/p.html
192.168.1.9 (To display Webserver IP address)
systemctl restart httpd
To access the statistic page, navigate to the HAProxy ip/stats,login with the username and pass as states in haproxy.cfg.

Monday 20 May 2013

ZEN Loadbalancer


Recently I just came across an article on Zen loadbalancer. Its a Debian ISO, ready to install. The installation and configuration is easy, and straight forward. Below is the feature list taken from its website. After installation, you can configure the LB from its https gui page. Config and testing can be done within minutes after installation.

Features
 Advanced Layer7 load balancing
 Max 30000 concurrent connections in TCP. *
 sNAT load balancing load balancing
 Balance TCP or UDP services
 Balance dataline communications
 HTTP and HTTPS services special options
 HTTP/S persistence client session enabled through cookie, header, basic, ip, url
 SSL wrapper / offload
 Wide range of load balance algorithms like: round robin, weight, priority or hash
 Persistence client sessions
 VLAN Tagging (802.1Q)
 Advanced network configuration for physical, virtual or VLAN interfaces
 Independent route tables for every physical or VLAN NICs
 Advanced checking for backend servers through FarmGuardian
 High availability load balancer service through an active-pasive cluster
 Optional configuration backups system
 Advanced global status with graphs
 Easy administration over https GUI and ssh
 Virtual service configurations can be edited and tuned on-the-fly
 Use NTP sync
 Easy and free updates over APT repositories
 Configure virtual servers and farms as your hardware allows
 Advanced system monitoring with graphs
 Management of SSL certificates
 Real Time syncronization between cluster nodes

*hardware depend

Sunday 28 April 2013

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

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. (eg http://(loadbalancer-ip):3636). Using "piranha" as user name, and key in the newly setup password. 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 
Create arptables entry for each Virtual IP address on each Real Server(eg Webserver). You can add below command to /etc/rc.local to start on every reboot. If the network adaptor on Real Server is eth0, refer to below, if not change as according:
ip addr add (virtual ip) dev eth0:1
Direct Routing with arptables_jf. To configure each real server to ignore ARP requests for each of the virtual IP addresses the Piranha cluster services:
yum install arptables_jf
arptables -A IN -d (virtual_ip) -j DROP
arptables -A OUT -d (virtual_ip) -j mangle --mangle-ip-s (real_ip)
chkconfig arptables_jf on
service arptables_jf save
service arptables_jf restart
Create a loopback on each Real Server for monitoring Virtual IP.
vi /etc/sysconfig/network-scripts/ifcfg-lo:0

DEVICE=lo:0
IPADDR=(Virtual IP)
NETMASK=255.255.255.255
NETWORK=192.168.0.0
ONBOOT=yes
NAME=loopback

search iomeweekly