zoukankan      html  css  js  c++  java
  • keepalived 实现LVS的高可用性-配置简介

    常用参数
      delay_loop <INT>:检查后端服务器的时间间隔
      lb_algo rr|wrr|lc|wlc|lblc|sh|dh:定义调度方法
      lb_kind NAT|DR|TUN:集群的类型
      persistence_timeout <INT>:持久连接时长
      protocol TCP:服务协议,仅支持TCP
      sorry_server <IPADDR> <PORT>:所有RS故障时,备用服务器地址
      real_server <IPADDR> <PORT>
    {
    weight <INT> RS权重
    notify_up <STRING>|<QUOTED-STRING> RS上线通知脚本
    notify_down <STRING>|<QUOTED-STRING> RS下线通知脚本
    HTTP_GET|SSL_GET|TCP_CHECK|SMTP_CHECK|MISC_CHEC K { ... }:定义当前主机的健康状态检测方法
    }

    HTTP_GET|SSL_GET:应用层检测
      HTTP_GET|SSL_GET {
        url {
          path <URL_PATH>:定义要监控的URL
          status_code <INT>:判断上述检测机制为健康状态的响应码
          digest <STRING>:判断为健康状态的响应的内容的校验码
        }
      connect_timeout <INTEGER>:连接请求的超时时长
      nb_get_retry <INT>:重试次数
      delay_before_retry <INT>:重试之前的延迟时长
      connect_ip <IP ADDRESS>:向当前RS哪个IP地址发起健康状态检测请求
      connect_port <PORT>:向当前RS的哪个PORT发起健康状态检测请求
      bindto <IP ADDRESS>:发出健康状态检测请求时使用的源地址
      bind_port <PORT>:发出健康状态检测请求时使用的源端口
    }

    一、从模板文件中复制

    virtual_server 10.10.10.2 1358 {
        delay_loop 6
        lb_algo rr
        lb_kind NAT
        persistence_timeout 50
        protocol TCP
    
        sorry_server 192.168.200.200 1358
    
        real_server 192.168.200.2 1358 {
            weight 1
            HTTP_GET {
                url {
                  path /testurl/test.jsp
                  digest 640205b7b0fc66c1ea91c463fac6334d
                }
                url {
                  path /testurl2/test.jsp
                  digest 640205b7b0fc66c1ea91c463fac6334d
                }
                url {
                  path /testurl3/test.jsp
                  digest 640205b7b0fc66c1ea91c463fac6334d
                }
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 3
            }
        }

    二、修改配置文件

      1、virtual_server 修改为VIP地址

    virtual_server 192.168.1.100 80 {

      2、轮循

      lb_algo rr

      3、DR模型

     lb_kind DR

      4、持久连接

     persistence_timeout 50

      5、提供道歉页面的服务器地址,本机地址

     sorry_server 127.0.0.1 80

      6、RS信息

    real_server 192.168.1.5 80 {

      7、权重1

    weight 1

      8、访问根,返回状态码200

    url {
                  path /
                  status_code 200
                }

      9、超时时间

    connect_timeout 3

      10、重连次数

    nb_get_retry 3

      11、重试之前的延迟时长

    delay_before_retry 3

      12、主服务器的完整的配置

    cat /etc/keepalived/keepalived.conf
    ! Configuration File for keepalived global_defs { notification_email { root@2382990774@qq.com } notification_email_from keepalived@2382990774@qq.com smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id ka1 vrrp_mcast_group4 224.100.100.100 } vrrp_instance VI_1 { state MASTER interface ens33 virtual_router_id 88 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 123456 } virtual_ipaddress { 192.168.1.100/24 dev ens33 label ens33:1 } notify_master "/etc/keepalived/notify.sh master" notify_backup "/etc/keepalived/notify.sh backup" notify_fault "/etc/keepalived/notify.sh fault" } virtual_server 192.168.1.100 80 { delay_loop 6 lb_algo rr lb_kind DR protocol TCP sorry_server 127.0.0.1 80 real_server 192.168.1.5 80 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } } real_server 192.168.1.6 80 { weight 1 HTTP_GET { url { path / status_code 200 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } }

      13、从服务器的配置文件

    cat keepalived.conf 
    ! Configuration File for keepalived
    
    global_defs {
       notification_email {
        root@localhost
       }
       notification_email_from keepalived@localhost
       smtp_server 127.0.0.1
       smtp_connect_timeout 30
       router_id ka2
       vrrp_mcast_group4 224.100.100.100
    }
    
    vrrp_instance VI_1 {
        state BACKUP
        interface ens33
        virtual_router_id 88
        priority 90
        advert_int 1
        authentication {
            auth_type PASS
            auth_pass 123456
        }
        virtual_ipaddress {
        192.168.1.100/24 dev ens33 label ens33:1
        }    
        notify_master "/etc/keepalived/notify.sh master"
        notify_backup "/etc/keepalived/notify.sh backup"
        notify_fault "/etc/keepalived/notify.sh fault"
    }
    virtual_server 192.168.1.100 80 {
        delay_loop 6
        lb_algo rr
        lb_kind DR
        protocol TCP
        sorry_server 127.0.0.1 80
    
        real_server 192.168.1.5 80 {
            weight 1
            HTTP_GET {
                url {
                  path /
                  status_code 200
                }
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 3
            }
        }
    
     real_server 192.168.1.6 80 {
            weight 1
            HTTP_GET {
                url {
                  path /
                  status_code 200
                }
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 3
            }
        }
    ------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------- 博客均为个人笔记,无所追求,仅供参考~~~ QQ--2382990774
  • 相关阅读:
    计算机网络 其他1
    C++ part9
    C++ part8
    操作系统 part5
    C++ part7
    MyXls导出Excel的各种设置
    C# excel操作
    Castle
    C# Keycode对照表
    IEnumerable.Select和SelectMany的区别
  • 原文地址:https://www.cnblogs.com/alexlv/p/14814652.html
Copyright © 2011-2022 走看看