LVS+keepalived负载均衡CentOS 5.6环境下布署(32位)V2版(2)

echo “======================= 配置keepalived ===========================”
[root@master ~]#  cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
[root@master ~]#  cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
[root@master ~]#  mkdir /etc/keepalived
[root@master ~]#  cp /usr/local/sbin/keepalived /usr/sbin/
[root@master ~]# vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
 
global_defs {
   notification_email {
      jimmy.li@linuxidc.com
   }
   notification_email_from jimmy.li@linuxidc.com  #
   smtp_server smtp.linuxidc.com
  # smtp_connect_timeout 30
   router_id LVS_DEVEL
}
 
# VIP1
vrrp_instance VI_1 {
    state MASTER             #备份服务器上将MASTER改为BACKUP  
    interface eth0
    lvs_sync_daemon_inteface eth0
    virtual_router_id 51
    priority 100    # 备份服务上将100改为90
    advert_int 5
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.9.200  
        #(如果有多个VIP,继续换行填写.)
    }
}
 
virtual_server 192.168.9.200 80 {
    delay_loop 6                  #(每隔6秒查询realserver状态)
    lb_algo wlc                  #(lvs 算法)
    lb_kind DR                  #(Direct Route)
    persistence_timeout 60        #(同一IP的连接60秒内被分配到同一台realserver)
    protocol TCP                #(用TCP协议检查realserver状态)
 
    real_server 192.168.9.203 80 {
        weight 100               #(权重)
        TCP_CHECK {
        connect_timeout 10       #(10秒无响应超时)
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
    }
    real_server 192.168.9.204 80 {
        weight 100
        TCP_CHECK {
        connect_timeout 10
        nb_get_retry 3
        delay_before_retry 3
        connect_port 80
        }
     }
}
[root@master ~]#  service keepalived start|stop
[root@master ~]# chkconfig –level 2345 keepalived on

echo “====================== 配置realserver =========================”
[root@web_1 ~]# vi /root/lvs_real.sh
#!/bin/bash
#
#Config realserver

SNS_VIP=192.168.9.200
 
/etc/rc.d/init.d/functions
 
case "$1" in
start)
       /sbin/ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP
       /sbin/route add -host $SNS_VIP dev lo:0
       echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
       echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
       echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
       echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
       sysctl -p >/dev/null 2>&1
       echo "RealServer Start OK"
 
       ;;
stop)
       /sbin/ifconfig lo:0 down
       /sbin/route del $SNS_VIP >/dev/null 2>&1
       echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
       echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
       echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
       echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
       echo "RealServer Stoped"
       ;;
*)
       echo "Usage: $0 {start|stop}"
       exit 1
esac
 
exit 0

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/wyyzzp.html