keepalived+LVS高可用、负载均衡

keepalived安装见上一篇。

lvs安装

检查是否安装了IPVS模块: 注:LVS已经是Linux标准内核的一部分,直接被编译在内核中!

方法1: 查看IPVS模块是否真的编译到内核中去了,如下图所示:

配置文件:

! Configuration File for keepalived

global_defs {
   notification_email {
     #acassen@firewall.loc
     #failover@firewall.loc
     #sysadmin@firewall.loc
   }
   #notification_email_from Alexandre.Cassen@firewall.loc
   #smtp_server 192.168.200.1
   #smtp_connect_timeout 30
   router_id master-node
   #vrrp_skip_check_adv_addr
   #vrrp_strict
   #vrrp_garp_interval 0
   #vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33
    mcast_src_ip 192.168.1.78
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.1.88
        
    }
}
#vrrp_script chk_nginx {
#    script "/etc/keepalived/check_nginx.sh"
#    interval 2
#    weight 2
#}

#track_script {
#    chk_nginx
#}
virtual_server 192.168.1.88 80 {
    delay_loop 6
    lb_algo wlc
    lb_kind DR
    nat_mask 255.255.255.0
    persistence_timeout 50
    protocol TCP
    real_server 192.168.1.78 80 {
        weight 1
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
                }
    }
    real_server 192.168.1.79 80 {
        weight 1
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
                }
    }    

}

realserver.sh,两台服务器上都执行。

#add for chkconfig  
#chkconfig: 2345 70 30  #234都是文本界面,5就是图形界面X,70启动顺序号,30系统关闭,脚本  
#止顺序号  
#description: RealServer's script  #关于脚本的简短描述  
#processname: realserver.sh       #第一个进程名,后边设置自动时会用到  
#!/bin/bash  
VIP=192.168.1.88
source /etc/rc.d/init.d/functions  
case "$1" in  
start)  
       ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP  
       /sbin/route add -host $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  
       echo "RealServer Start OK"  
       ;;  
stop)  
       ifconfig lo:0 down  
       route del $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  

 

posted @ 2017-06-08 11:07  杯中红茶  阅读(305)  评论(0编辑  收藏  举报