高可用lvs dr模式配置文件

本文档展示了如何在两台服务器上配置Keepalived,以实现VIP漂移和负载均衡。配置包括设置VRRP实例,定义虚拟IP地址,以及配置NAT规则来检查后端服务器的TCP连接。同时,还指导了在Nginx服务器上添加回环IP和调整ARP设置以避免广播域问题。
摘要由CSDN通过智能技术生成

两台 yum  -y  install ipvsadm keepalived

! Configuration File for keepalived

global_defs {
   router_id lvs-keepalived-master
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 80
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.180.199/24
    }
}

virtual_server 192.168.180.199 80 {
        delay_loop 3
        lb_algo rr
        lb_kind DR
        nat_mask 255.255.255.0
        protocol TCP
        real_server 192.168.180.236 80 {
                weight 1
                inhibit_on_failure
                TCP_CHECK {
                        connect_port 80
                        connect_timeout 3
                        }
         }
        real_server 192.168.180.237 80 {
                weight 1
                inhibit_on_failure
                TCP_CHECK {
                        connect_timeout 3
                        connect_port 80
                        }
                }
}


backup


! Configuration File for keepalived

global_defs {
   router_id lvs-keepalived-slave
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    nopreempt
    virtual_router_id 80
    priority 50
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.180.199/24
    }
}
virtual_server 192.168.180.199 80 {
        delay_loop 3
        lb_algo rr
        lb_kind DR
        nat_mask 255.255.255.0
        protocol TCP
        real_server 192.168.180.236 80 {
                weight 1
                inhibit_on_failure
                TCP_CHECK {
                        connect_port 80
                        connect_timeout 3
                        }
                }
        real_server 192.168.180.237 80 {
                weight 1
                inhibit_on_failure
                TCP_CHECK {
                        connect_timeout 3
                        connect_port 80
                        }
                }

两台nginx添加回环ip

ip a add dev lo 192.168.180.199/32

两台nginx上配置忽略广播域

[root@localhost ~]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@localhost ~]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值