ddewe 发表于 2016-9-7 14:36:46

LVS+Keepalived

使用keepalived的情况下,就不需要在dir上执行/usr/local/sbin/lvs_dr.sh脚本了,只需在rs上执行/usr/local/sbin/lvs_rs.sh,与ipvsadm无关了

为了防止其中一台rs宕机而造成无法访问的情况,就需要有一个程序去监测,当一台宕机后,立马就可以把请求调度到其余机器上去,那就是keepalived,相当于是负载均衡和高可用的集合体,非常优秀;keepalived --> HA+LB
需要有4台机器,在dir上做一主一备用于高可用,也就是说有两台负载均衡机器

在dir上:
首先清空ipvsadm规则:ipvsadm -C
在dir上安装keepalived:但是yum安装前需要关闭虚拟IP:ifconfig eth0:0 down, 因为有一个虚拟ip存在
yum install -y keepalived
修改keepalived配置文件:
vim /etc/keepalived/keepalived.conf
主上:
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
      auth_type PASS
      auth_pass 1111
    }
    virtual_ipaddress {
      192.168.237.100
    }
}

virtual_server 192.168.237.100 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 0
    protocol TCP

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

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

从上:
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.237.100
    }
}

virtual_server 192.168.237.100 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 0
    protocol TCP

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

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


启动前的执行命令
dir上:
ipvsadm -C
iptables -t nat -F
echo 1 > /proc/sys/net/ipv4/ip_forward
/etc/init.d/keepalived start

rs上:
sh /usr/local/sbin/lvs_rs.sh

启动后在dir上用ip addr看dir上的IP


页: [1]
查看完整版本: LVS+Keepalived