KEEPALIVED+LVS-DR mode configuration high Availability load Balancing cluster

Source: Internet
Author: User
Tags web services

Environment: Virtual machine: VMware Workstation operating system: CentOS 5.5

First, KEEPALIVED+LVS-DR mode configuration high available load balancing

The topology is as follows:


Second, server IP configuration information

1. IP_LB Host (Master):


2.ip_lb_2 Host (Backup)


3.WEB1 Host

4.WEB2 Host



See if Ipvsadm software is available separately in master and backup

1. Check whether the Ipvsadm is installed successfully. can be entered directly

[Root@localhost ~]# ipvsadm IP Virtual Server version 1.2.1 (size=4096) prot localaddress:port Scheduler Flags-> Rem Oteaddress:port Forward Weight activeconn inactconn
2. Check whether the template is added to the kernel
[Root@localhost ~]# lsmod |grep ip_vs ip_vs 78081 0

Four, respectively installs the Apache service on the Web1 and the web2 above.
# Installing the Apache service is not explained. Open ports are: 8099

V. Install keepalived on Master Host (192.168.96.2) and backup host (192.168.96.22)
1. keepalived-1.2.1.tar.gz # Extract this file and install (TAR-ZXVF keepalived-1.2.1.tar.gz)
2./configure--prefix=/home/keepalived/--with-kernel-dir=/usr/src/kernels/2.6.18-164.el5-i686
3.make
4.make Install
5. Path to configuration file
cp/home/keepalived/etc/rc.d/init.d/keepalived/etc/init.d/
cp/home/keepalived/etc/sysconfig/keepalived/etc/sysconfig/
cp/home/keepalived/etc/keepalived/keepalived.conf/etc/keepalived/
cp/home/keepalived/sbin/keepalived/sbin/

6. Configure the keepalived.conf file. (IP_LB host <master>)
Vim/etc/keepalived/keepalived.conf

#global define Global_defs {router_id Lvs_t1} vrrp_sync_group bl_group {group {bl_one}} vrrp_instance Bl_one { State MASTER interface eth0 lvs_sync_daemon_interface eth0 virtual_router_id T_int 3 Authentication {Auth_type pass Auth_pass 1111} virtual_ipaddress {192.168.96. Virtual_server 192.168.96.100 8099 {delay_loop 3 Lb_algo RR lb_kind DR persistence_timeout                                                                                                                                      
        1 Protocol TCP Real_server 192.168.96.33 8099 {weight 1                                                                                                                                   
      Tcp_check {                                                                                                                        
 Connect_timeout 10           Nb_get_retry 3                                                                                                                      
            Delay_before_retry 3                                                                                                                         
        Connect_port 8099                                                                                                                                             
       }                                                                                                                                                 
                                                                       }                                                       
    Real_server 192.168.96.4 8099 {                                                                                                                                      
        Weight 1                                                                                                                                   
            Tcp_check {                                                                                                                        
            Connect_timeout 10                                                                                                                            
            Nb_get_retry 3                                                                                                                      
            Delay_before_retry 3 Co         Nnect_port 8099                                                                                                                
        }                                                                                                                                                 
}                  }

7, configure keepalived.conf files. (ip_lb_2 host <backup>)
Vim/etc/keepalived/keepalived.conf
#global define Global_defs {router_id Lvs_t2} vrrp_sync_group bl_group {group {bl_one}} vrrp_instance Bl_one { State BACKUP interface eth0 lvs_sync_daemon_interface eth0 virtual_router_id T_int 3 Authentication {Auth_type pass Auth_pass 1111} virtual_ipaddress {192.168.96. Virtual_server 192.168.96.100 8099 {delay_loop 3 Lb_algo RR lb_kind DR persistence_timeout                                                                                                                  
        1 Protocol TCP Real_server 192.168.96.33 8099 {                                                                                                                                      
        Weight 1                                                                                                                                   
            Tcp_check { Co        Nnect_timeout 10                                                                                                                
         Nb_get_retry 3                                                                                                                      
            Delay_before_retry 3                                                                                                                         
        Connect_port 8099                                                                                                                                             
               }                                                                                                                               }                  
                                                                                                       Real_server 192.168.96.4 8099 {                                                                                                                                      
        Weight 1 Tcp_chec                                                                                                                                   
            K                                                                                                                        
            Connect_timeout 10                                                                                                                            
            Nb_get_retry 3                                           Delay_before_retry 3                                                                           
            Connect_port 8099                                                                                                                                  }                                                                                                                                                 
}       }

8. Start the keepalived on the main standby separately
[Root@ip_lb home]#/etc/init.d/keepalived start
Starting keepalived: [OK]

[Root@ip_lb home]# tail-f/var/log/message


PS: Here is the LVS. It is not configured with Ipvsadm software, but is controlled directly by keepalived virtual_server configuration items.
# Install IPVSADM only can see the load condition. In fact, only need keepalived can also achieve load Balancing cluster.

Configure the LVS-DR configuration on the Web1 and WEB2 hosts.
1. Vim/etc/init.d/lvsdr_node (Web1 host)
#! /bin/sh 
# Descript:start Real Server Dr.
vip=192.168.96.100
./etc/rc.d/init.d/functions case
"$" in< C4/>start)
             echo "Start LVS of Realserver DR"
             /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
  echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
             echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
               ;;
       Stop)
             /sbin/ifconfig lo:0 down
             echo "Close LVS of Realserver DR"
             echo "0" >/proc/sys/net/ipv4/conf/ All/arp_ignore
             echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
              ;
         *)
              echo "Usage: $ {start|stop}"
              exit 1
Esac

2. Copy this file to the WEB2 host.
3. Start this script separately on Web1 and WEB2:
/etc/init.d/lvsdr_node start

Seven, Web1 and WEB2 host on the Open httpd service.
/ETC/INIT.D/HTTPD start

# ================= TEST =======================================

Test if the load balance can be measured.
To write a test script:
#! /bin/sh for
((i=1;i<=100;i++));d o 
curl http://192.168.96.100:8099 >>/tmp/q;
Done

Results:


IX. Test Disconnect a Web service or join a Web service
Now turn off the WEB2 host (192.168.96.4) Web service.
View the log to see:


Now add the WEB2 host (192.168.96.4) Web services:
View the log to see:


Ten, Test ha
Now simulate Master (Master) 's keepalived host dies.
Log files for the standby machine:


You can see the keepalived of the standby has already begun to work ....

The entire deployment is complete.

Official reference Chinese Document: Http://www.keepalived.org/pdf/sery-lvs-cluster.pdf


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.