keepalived双主配置

基础的已经在前一篇文章介绍过,链接如下:
https://blog.csdn.net/qq_39567748/article/details/100180809

服务器名称IP地址VIP网卡名称备注
local-100-101172.20.100.101172.20.100.250eth0
docker-100-108172.20.100.108172.20.100.251eth0

1、配置如下:

双主模式
[root@localhost-100-101 keepalived]# cat keepalived.conf 
! Configuration File for keepalived

global_defs {
   notification_email {
   15321375963@139.com
   }
   notification_email_from 15321375963@189.cn 
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id 172.20.100.101
   #vrrp_skip_check_adv_addr
   #vrrp_strict
   #vrrp_garp_interval 0
   #vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    lvs_sync_daemon_inteface eth0
    virtual_router_id 51
    nopreempt
    preempt delay 60
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass rongkang
    }
    virtual_ipaddress {
        172.20.100.250/24
    }
}

vrrp_instance VI_2 {
    state BACKUP
    interface eth0
    lvs_sync_daemon_inteface eth0
    virtual_router_id 52
    nopreempt
    preempt delay 60
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass rongkang
    }
    virtual_ipaddress {
        172.20.100.251/24
    }
}




[root@docker-100-108 ~]# cat /etc/keepalived/keepalived.conf 
! Configuration File for keepalived

global_defs {
   notification_email {
   15321375963@139.com
   }
   notification_email_from 15321375963@189.cn
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id 172.20.100.108
   #vrrp_skip_check_adv_addr
   #vrrp_strict
   #vrrp_garp_interval 0
   #vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    lvs_sync_daemon_inteface eth0
    virtual_router_id 51
    nopreempt
    preempt delay 60
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass rongkang
    }
    virtual_ipaddress {
        172.20.100.250/24
    }
}

vrrp_instance VI_2 {
    state MASTER
    interface eth0
    lvs_sync_daemon_inteface eth0
    virtual_router_id 52
    nopreempt
    preempt delay 60
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass rongkang
    }
    virtual_ipaddress {
        172.20.100.251/24
    }
}
[root@docker-100-108 ~]# 

2、启动服务

systemctl start keepalived
systemctl enable keepalived

3、查看网卡
localhost-100-101

[root@localhost-100-101 ~]# ip add
eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether fa:c6:4d:82:b3:00 brd ff:ff:ff:ff:ff:ff
    inet 172.20.100.101/24 brd 172.20.100.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet 172.20.100.250/24 scope global secondary eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::c14a:4493:465b:199b/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

docker-100-108

eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether fa:ca:f2:59:ee:00 brd ff:ff:ff:ff:ff:ff
    inet 172.20.100.108/24 brd 172.20.100.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 172.20.100.251/24 scope global secondary eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::a21e:eb94:4c03:739f/64 scope link 
       valid_lft forever preferred_lft forever
    inet6 fe80::c14a:4493:465b:199b/64 scope link tentative dadfailed 
       valid_lft forever preferred_lft forever

4、抓包查看

[root@localhost-100-101 ~]# tcpdump -i eth0 vrrp -n
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
10:56:06.681265 IP 172.20.100.101 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 100, authtype simple, intvl 1s, length 20
10:56:06.683314 IP 172.20.100.108 > 224.0.0.18: VRRPv2, Advertisement, vrid 52, prio 100, authtype simple, intvl 1s, length 20
10:56:07.682486 IP 172.20.100.101 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 100, authtype simple, intvl 1s, length 20
10:56:07.684963 IP 172.20.100.108 > 224.0.0.18: VRRPv2, Advertisement, vrid 52, prio 100, authtype simple, intvl 1s, length 20
10:56:08.683899 IP 172.20.100.101 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 100, authtype simple, intvl 1s, length 20
10:56:08.685145 IP 172.20.100.108 > 224.0.0.18: VRRPv2, Advertisement, vrid 52, prio 100, authtype simple, intvl 1s, length 20
10:56:09.685109 IP 172.20.100.101 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 100, authtype simple, intvl 1s, length 20
10:56:09.687187 IP 172.20.100.108 > 224.0.0.18: VRRPv2, Advertisement, vrid 52, prio 100, authtype simple, intvl 1s, length 20
10:56:10.686365 IP 172.20.100.101 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 100, authtype simple, intvl 1s, length 20
10:56:10.687348 IP 172.20.100.108 > 224.0.0.18: VRRPv2, Advertisement, vrid 52, prio 100, authtype simple, intvl 1s, length 20
10:56:11.687684 IP 172.20.100.101 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 100, authtype simple, intvl 1s, length 20
10:56:11.690099 IP 172.20.100.108 > 224.0.0.18: VRRPv2, Advertisement, vrid 52, prio 100, authtype simple, intvl 1s, length 20
10:56:12.688996 IP 172.20.100.101 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 100, authtype simple, intvl 1s, length 20
10:56:12.690150 IP 172.20.100.108 > 224.0.0.18: VRRPv2, Advertisement, vrid 52, prio 100, authtype simple, intvl 1s, length 20
10:56:13.690279 IP 172.20.100.101 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 100, authtype simple, intvl 1s, length 20
10:56:13.692694 IP 172.20.100.108 > 224.0.0.18: VRRPv2, Advertisement, vrid 52, prio 100, authtype simple, intvl 1s, length 20
10:56:14.691574 IP 172.20.100.101 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 100, authtype simple, intvl 1s, length 20
10:56:14.693902 IP 172.20.100.108 > 224.0.0.18: VRRPv2, Advertisement, vrid 52, prio 100, authtype simple, intvl 1s, length 20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值