今天看啥
热点:

利用Keepalvied实现负载均衡和和高可用性


1.在lvs的master节点上设置:
[[email protected] ~]# yum install keepalived -y
[[email protected] ~]# vim /etc/keepalived/keepalived.conf
  1. ! Configuration File for keepalived

  2. global_defs {
  3. notification_email {
  4. [email protected]
  5. }
  6. notification_email_from [email protected]
  7. smtp_server 127.0.0.1
  8. # smtp_connect_timeout 30
  9. router_id LVS_DEVEL
  10. }

  11. #written by :netseek
  12. # VIP1
  13. vrrp_instance VI_1 {
  14. state MASTER #备份服务器上将MASTER改为BACKUP
  15. interface eth0
  16. virtual_router_id 51
  17. priority 100 # 备份服务上将100改为99
  18. advert_int 1
  19. authentication {
  20. auth_type PASS
  21. auth_pass 1111
  22. }
  23. virtual_ipaddress {
  24. 192.168.1.188
  25. #(如果有多个VIP,继续换行填写.)
  26. }
  27. }

  28. virtual_server 192.168.1.188 80 {
  29. delay_loop 6 #(每隔10秒查询realserver状态)
  30. lb_algo wrr #(lvs 算法)
  31. lb_kind DR #(Direct Route)
  32. persistence_timeout 60 #(同一IP的连接60秒内被分配到同一台realserver)
  33. protocol TCP #(用TCP协议检查realserver状态)

  34. real_server 192.168.1.121 80 {
  35. weight 3 #(权重)
  36. TCP_CHECK {
  37. connect_timeout 10 #(10秒无响应超时)
  38. nb_get_retry 3
  39. delay_before_retry 3
    connect_port 80
    }
    }
    real_server 192.168.1.122 80 {
    weight 3
    TCP_CHECK {
    connect_timeout 10
    nb_get_retry 3
    delay_before_retry 3
    connect_port 80
    }
    }
    }
[[email protected] ~]# /etc/init.d/keepalived start

2.在lvs的backup节点上设置:
[[email protected] ~]# yum install keepalived -y
[[email protected] ~]# vim /etc/keepalived/keepalived.conf
  1. ! Configuration File for keepalived

    global_defs {
    notification_email {
    [email protected]
    }
    notification_email_from [email protected]
    smtp_server 127.0.0.1
    # smtp_connect_timeout 30
    router_id LVS_DEVEL
    }

    #written by :netseek
    # VIP1
    vrrp_instance VI_1 {
    state BACKUP #备份服务器上将MASTER改为BACKUP
    interface eth0
    virtual_router_id 51
    priority 99 # 备份服务上将100改为99
    advert_int 1
    authentication {
    auth_type PASS
    auth_pass 1111
    }
    virtual_ipaddress {
    192.168.1.188
    #(如果有多个VIP,继续换行填写.)
    }
    }

    virtual_server 192.168.1.188 80 {
    delay_loop 6 #(每隔10秒查询realserver状态)
    lb_algo wrr #(lvs 算法)
    lb_kind DR #(Direct Route)
    persistence_timeout 60 #(同一IP的连接60秒内被分配到同一台realserver)
    protocol TCP #(用TCP协议检查realserver状态)

    real_server 192.168.1.121 80 {
    weight 3 #(权重)
    TCP_CHECK {
    connect_timeout 10 #(10秒无响应超时)
    nb_get_retry 3
    delay_before_retry 3
    connect_port 80
    }
    }
    real_server 192.168.1.122 80 {
    weight 3
    TCP_CHECK {
    connect_timeout 10
    nb_get_retry 3
    delay_before_retry 3
    connect_port 80
    }
    }
    }

下面我们做个测试:
配置完成后我们停掉master上的keepalived服务然后去查看日志文件,看看backup节点是否接管服务:
[[email protected] ~]# /etc/init.d/keepalived stop
Stopping keepalived: [ OK ]
[[email protected] ~]# tail -f /var/log/messages
Apr 20 07:05:43 vm1 Keepalived_vrrp[1163]: VRRP_Instance(VI_1) Transition to MASTER STATE
Apr 20 07:05:44 vm1 Keepalived_vrrp[1163]: VRRP_Instance(VI_1) Entering MASTER STATE
Apr 20 07:05:44 vm1 Keepalived_vrrp[1163]: VRRP_Instance(VI_1) setting protocol VIPs.
Apr 20 07:05:44 vm1 Keepalived_vrrp[1163]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.1.188
Apr 20 07:05:49 vm1 Keepalived_vrrp[1163]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.1.188
Apr 20 07:08:10 vm1 Keepalived[1160]: Stopping Keepalived v1.2.7 (09/26,2012)
Apr 20 07:08:10 vm1 Keepalived_vrrp[1163]: VRRP_Instance(VI_1) sending 0 priority
Apr 20 07:08:10 vm1 Keepalived_vrrp[1163]: VRRP_Instance(VI_1) removing protocol VIPs.
Apr 20 07:08:10 vm1 Keepalived_healthcheckers[1162]: Netlink reflector reports IP 192.168.1.188 removed
Apr 20 07:08:10 vm1 kernel: IPVS: __ip_vs_del_service: enter
我们可以看到keepalived健康检查已经被移除。
再来看看backup的日志文件:
[[email protected] ~]# tail -f /var/log/messages
Apr 20 07:05:58 vm4 Keepalived_healthcheckers[1180]: IPVS: Destination already exists
Apr 20 07:05:58 vm4 Keepalived_healthcheckers[1180]: IPVS: Destination already exists
Apr 20 07:05:58 vm4 Keepalived_healthcheckers[1180]: Using LinkWatch kernel netlink reflector...
Apr 20 07:05:58 vm4 Keepalived_healthcheckers[1180]: Activating healthchecker for service [192.168.1.121]:80
Apr 20 07:05:58 vm4 Keepalived_healthcheckers[1180]: Activating healthchecker for service [192.168.1.122]:80
Apr 20 07:08:10 vm4 Keepalived_vrrp[1181]: VRRP_Instance(VI_1) Transition to MASTER STATE
Apr 20 07:08:11 vm4 Keepalived_vrrp[1181]: VRRP_Instance(VI_1) Entering MASTER STATE
Apr 20 07:08:11 vm4 Keepalived_vrrp[1181]: VRRP_Instance(VI_1) setting protocol VIPs.
Apr 20 07:08:11 vm4 Keepalived_vrrp[1181]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.1.188
Apr 20 07:08:16 vm4 Keepalived_vrrp[1181]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.1.188
之前backup节点一直在监视master的keepalived服务的状态,当master节点上健康检查出现故障的时候,backup自动接管服务。

www.bkjia.comtruehttp://www.bkjia.com/xtzh/986913.htmlTechArticle利用Keepalvied实现负载均衡和和高可用性 1.在lvs的master节点上设置: [[email protected] ~]# yum install keepalived -y [[email protected] ~]# vim /etc/keepalived/keepalived.conf !...

相关文章

相关搜索: android

帮客评论

视觉看点