zoukankan      html  css  js  c++  java
  • 9-lvs-lvs集群-及keepalived健康检查

    注意: 配置前需要将上一篇的配置都清除掉

    ifconfig eth1:1 down
    service ipvsadm restart

    nginx作为请求分发服务器时, 有健康检查机制, 挂了的服务器不会在分发请求

    但lvs没有, 需要keepalived进行健康检查, 否则仍然将请求分发过去, 造成无法访问

    安装keepalived高可用的lvs集群

    1, 安装 ipvsadm

      上篇(http://www.cnblogs.com/wenbronk/p/6618230.html)讲过, 不说, 安装好就可以, 不需要配置

    2, 安装keepalived

      上上篇讲过(http://www.cnblogs.com/wenbronk/p/6597286.html),,, yum 安装

    3, 配置keepalived的配置文件

     vim /etc/keepalived/keepalived.conf

    keepalived.con (更多参数可通过 man keepalived.conf 进行查看)

    ! Configuration File for keepalived
    
    global_defs {
       notification_email {
        root@localhost  # 发生故障时, 发送到的邮箱
       }
       notification_email_from wenbronk@localhost  #从哪发送
       smtp_server 127.0.0.1              #配置邮件服务器, linux这个只能发本机
       smtp_connect_timeout 30             # 链接超时
       router_id LVS_DEVEL
    }
    
    vrrp_instance VI_1 {
        state MASTER   {  # 配置为主机, 从机配置为 BACKUP
        interface eth1    # 为自己的网卡名字
        virtual_router_id 51  #统一集群中的keepalived相同
        priority 100      # 主比从多50
        advert_int 1
        authentication {
            auth_type P{SS
            auth_pass 1111
        }
        }irtual_ipaddress {
            192.168.208.12{/24 dev eth1 label eth1:1  # 配置虚拟ip地址, label为别名
        }
    }
    
    virtual_server 192.168.208.126 80 {    # 配置虚拟ip
        delay_loop 6
        lb_algo wlc    #采用wlc的调度模式
        lb_kind DR    #DR动态调度
        nat_mask 255.255.255.0
        persistence_timeout 50  # 超时内, 同一客户端分配到一个real_server上
        protocol TCP
    
        real_server 192.168.208.104 80 {  # real_server, 有几个配置几个
            weight 1    # 配置权重
            HTTP_GET {    # 使用HTTP_GET模式判断存活
                url {    # 请求的url
                  path /
                  status_code 200  # 判断的依据
                }
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 3
            }
        }
    
    
        real_server 192.168.208.105 80 {
            weight 1
            HTTP_GET {
                url {
                  path /
                  status_code 200
                }
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 3
            }
        }
    }

    从机的配置和主机大体相似, 需要将

    state BACKUP
    priority 50

    然后启动keepalived即可

    service keepalived start

    可通过将主机, 从机等关闭, 自动漂移VIP, 即配置可用

    系列来自尚学堂

  • 相关阅读:
    HTML元素解释
    Java命名规范
    HDU 1058 Humble Numbers(DP,数)
    HDU 2845 Beans(DP,最大不连续和)
    HDU 2830 Matrix Swapping II (DP,最大全1矩阵)
    HDU 2870 Largest Submatrix(DP)
    HDU 1421 搬寝室(DP)
    HDU 2844 Coins (组合背包)
    HDU 2577 How to Type(模拟)
    HDU 2159 FATE(二维完全背包)
  • 原文地址:https://www.cnblogs.com/wenbronk/p/6618799.html
Copyright © 2011-2022 走看看