高可用集群技术之Keepalived实现LVS高可用并负载均(3)

(9)LVS+keepalived配置ipvs规则实现负载均衡高可用
配置如下:
virtual_server 172.16.100.99 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    nat_mask 255.255.0.0
    # persistence_timeout 50
    protocol TCP
    sorry_server 127.0.0.1 80        #如果所有节点都down机,将转向本地web服务
 
    real_server 172.16.100.8 80 {
        weight 1
        HTTP_GET {                    #web健康状态检测
            url {
              path /
              status_code 200 
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 172.16.100.9 80 {
        weight 1
        HTTP_GET {                    #web健康状态检测
            url {
              path /
              status_code 200 
            }
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

最后查询ipvs规则,如下所示:
# ipvsadm -L -n --stats
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port              Conns  InPkts  OutPkts  InBytes OutBytes
  -> RemoteAddress:Port
TCP  172.16.100.99:80                    3      22        0    4657        0
  -> 172.16.100.8:80                    0        0        0        0        0
  -> 172.16.100.9:80                    0        0        0        0        0

以上为keepalived+lvs+web服务实现所有内容。

keepalived双主模型配置案例如下:
master1为:
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 101
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass keepalivedpass
    }
    virtual_ipaddress {
    172.16.100.99 dev eth0 label eth0:0
    }
    track_script {
    chk_downfile
    }
    track_script {
    chkngx
    }
    notify_master "/etc/keepalived/notify.sh master"
    notify_backup "/etc/keepalived/notify.sh backup"
    notify_fault "/etc/keepalived/notify.sh fault"
    notify "/etc/keepalived/notify.sh"
}
vrrp_instance VI_2 {
    state BACKUP
    interface eth0
    virtual_router_id 52
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass keepalivedpass
    }
    virtual_ipaddress {
        172.16.100.98 dev eth0 label eth0:1
    }
    track_script {
        chk_downfile
    }
    track_script {
        chkngx
    }
        notify_master "/etc/keepalived/notify.sh master"
        notify_backup "/etc/keepalived/notify.sh backup"
        notify_fault "/etc/keepalived/notify.sh fault"
        notify "/etc/keepalived/notify.sh"
}

master2为:
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass keepalivedpass
    }
    virtual_ipaddress {
    172.16.100.99 dev eth0 label eth0:0
    }
    track_script {
    chk_downfile
    chkngx
    }
    track_script {
    chkngx
    }
    notify_master "/etc/keepalived/notify.sh master"
    notify_backup "/etc/keepalived/notify.sh backup"
    notify_fault "/etc/keepalived/notify.sh fault"
    notify "/etc/keepalived/notify.sh"
}
vrrp_instance VI_2 {
    state MASTER
    interface eth0
    virtual_router_id 52
    priority 101
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass keepalivedpass
    }
    virtual_ipaddress {
        172.16.100.98 dev eth0 label eth0:1
    }
    track_script {
        chk_downfile
    }
    track_script {
        chkngx
    }
        notify_master "/etc/keepalived/notify.sh master"
        notify_backup "/etc/keepalived/notify.sh backup"
        notify_fault "/etc/keepalived/notify.sh fault"
        notify "/etc/keepalived/notify.sh"
}

学习LVS+Keepalived必须阅读的三个文档。

1、  《Keepalived权威指南》下载见

2、  《LVS手册》

3、  《Red_Hat_Enterprise_Linux-5-Virtual_Server_Administration-zh-CN》

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/c3eaad57fdfc31c753133af855c939c2.html