ookkl 发表于 2017-2-20 10:37:09

keepalived实现高可用负载均衡DR模式

#################################################################
keepalived master eth0: 192.168.108.18
keepalived slave eth0: 192.168.108.19
real server 1 eth0: 192.168.108.10
real server 1 eth0: 192.168.108.21
vip: 192.168.108.17
real server 1 & 2: 安装nginx 开启80端口
test server eth0: 192.168.108.25
#################################################################

##################### keepalived master ##########################
global_defs {
    notification_email {
      ****@****.com
    }
    notification_email_from keepalived@localhost.com
    smtp_server ********
    smtp_connect_timeout 30
    router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state BACKUP
    nopreempt
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 1111
    }
    virtual_ipaddress {
      192.168.108.17
    }
}

virtual_server 192.168.108.17 80 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    persistence_timeout 0
    protocol TCP

    real_server 192.168.108.10 80 {
      weight 100
      TCP_CHECK {
            connect_timeout 10
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
      }
    }

    real_server 192.168.108.21 80 {
      weight 100
      TCP_CHECK {
            connect_timeout 10
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
      }
    }
}
##################### keepalived master ##########################

##################### keepalived slave ##########################
global_defs {
    notification_email {
      ****@****.com
    }
    notification_email_from keepalived@localhost.com
    smtp_server ********
    smtp_connect_timeout 30
    router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 99
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 1111
    }
    virtual_ipaddress {
      192.168.108.17
    }
}

virtual_server 192.168.108.17 80 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    persistence_timeout 0
    protocol TCP

    real_server 192.168.108.10 80 {
      weight 100
      TCP_CHECK {
            connect_timeout 10
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
      }
    }

    real_server 192.168.108.21 80 {
      weight 100
      TCP_CHECK {
            connect_timeout 10
            nb_get_retry 3
            delay_before_retry 3
            connect_port 80
      }
    }
}
##################### keepalived slave ##########################

###################### real server 1 & 2 ########################
#!/bin/bash
#/usr/local/sbin/lvs_rs.sh

vip=192.168.108.17
ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up
route add -host $vip 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
###################### real server 1 & 2 ########################

################## real server 1 & 2 setting###################
ifconfig lo:0 down
systemctl start nginx
sh /usr/local/sbin/lvs_dr.sh
################## real server 1 & 2 setting###################

################## keepalived master & slave setting###########
#服务器上开启路由转发功能:
echo 1 > /proc/sys/net/ipv4/ip_forward

ipvsadm -C
systemctl start keepalived
################## keepalived master & slave setting###########

######################## test server###########################
curl 192.168.108.17
#分别关闭重启 keepalived master & salve 的keepalvied
systemctl stop keepalvide
systemctl restart keepalvide
#分别关闭 real server 1 & 2 nginx
systemctl stop nginx
######################## test server###########################



页: [1]
查看完整版本: keepalived实现高可用负载均衡DR模式