KEEPALIVED实验报告

配置虚拟路由器

[root@KA01 ~]# vim /etc/keepalived/keepalived.conf

global_defs {
   notification_email {
        13205140214@163.com
   }
   notification_email_from 13205140214@163.com
   smtp_server 127.0.0.0
   smtp_connect_timeout 30
   router_id KA01
   vrrp_skip_check_adv_addr
   vrrp_garp_interval 1
   vrrp_gna_interval 1
   vrrp_mcast_group4 224.0.0.44
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.168.232.200/24 dev eth0 label eth0:0
    }
}

[root@KA02 ~]# vim /etc/keepalived/keepalived.conf

global_defs {
   notification_email {
        13205140214@163.com
   }
   notification_email_from 13205140214@163.com
   smtp_server 127.0.0.0
   smtp_connect_timeout 30
   router_id KA01
   vrrp_skip_check_adv_addr
#  vrrp_strict
   vrrp_garp_interval 1
   vrrp_gna_interval 1
   vrrp_mcast_group4 224.0.0.44
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 80
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.168.232.200/24 dev eth0 label eth0:0
    }
}

测试KA01/KA02均开启

[root@KA01 ~]#  tcpdump -i eth0 -nn host 224.0.0.44

关闭KA01

实现独立子配置文件

[root@KA01 ~]# vim /etc/keepalived/keepalived.conf

global_defs {
   notification_email {
        13205140214@163.com
   }
   notification_email_from 13205140214@163.com
   smtp_server 127.0.0.0
   smtp_connect_timeout 30
   router_id KA01
   vrrp_skip_check_adv_addr
   vrrp_garp_interval 1
   vrrp_gna_interval 1
   vrrp_mcast_group4 224.0.0.44
}
include /etc/keepalived/conf.d/*.conf

[root@KA01 ~]# mkdir /etc/keepalived/conf.d -p
[root@KA01 ~]# vi /etc/keepalived/conf.d/VI_1.conf
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.168.232.200/24 dev eth0 label eth0:0
    }
}

[root@KA01 ~]# systemctl restart keepalived.service

测试

非抢占模式 nopreempt

[root@KA01 ~]# vim /etc/keepalived/keepalived.conf
global_defs {
   notification_email {
        13205140214@163.com
   }
   notification_email_from 13205140214@163.com
   smtp_server 127.0.0.0
   smtp_connect_timeout 30
   router_id KA01
   vrrp_skip_check_adv_addr
   vrrp_garp_interval 1
   vrrp_gna_interval 1
   vrrp_mcast_group4 224.0.0.44
}
#include /etc/keepalived/conf.d/*.conf
vrrp_instance VI_1 {
    state BCAKUP
    interface eth0
    virtual_router_id 51
    priority 100
    nopreempt
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.168.232.200/24 dev eth0 label eth0:0
    }
}

[root@KA02 ~]# vim /etc/keepalived/keepalived.conf

global_defs {
   notification_email {
        13205140214@163.com
   }
   notification_email_from 13205140214@163.com
   smtp_server 127.0.0.0
   smtp_connect_timeout 30
   router_id KA01
   vrrp_skip_check_adv_addr
   vrrp_garp_interval 1
   vrrp_gna_interval 1
   vrrp_mcast_group4 224.0.0.44
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 80
    nopreempt
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.168.232.200/24 dev eth0 label eth0:0
    }
}

测试

KA01/02均开启

KA01关闭重启

抢占延迟模式 preempt_delay

[root@KA01 ~]# vim /etc/keepalived/keepalived.conf
global_defs {
   notification_email {
        13205140214@163.com
   }
   notification_email_from 13205140214@163.com
   smtp_server 127.0.0.0
   smtp_connect_timeout 30
   router_id KA01
   vrrp_skip_check_adv_addr
   vrrp_garp_interval 1
   vrrp_gna_interval 1
   vrrp_mcast_group4 224.0.0.44
}
#include /etc/keepalived/conf.d/*.conf
vrrp_instance VI_1 {
    state BCAKUP
    interface eth0
    virtual_router_id 51
    priority 100
    preempt_delay 10#延迟10s
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.168.232.200/24 dev eth0 label eth0:0
    }
}

[root@KA02 ~]# vim /etc/keepalived/keepalived.conf

global_defs {
   notification_email {
        13205140214@163.com
   }
   notification_email_from 13205140214@163.com
   smtp_server 127.0.0.0
   smtp_connect_timeout 30
   router_id KA01
   vrrp_skip_check_adv_addr
   vrrp_garp_interval 1
   vrrp_gna_interval 1
   vrrp_mcast_group4 224.0.0.44
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 80
    preempt_delay 10 #延迟10s
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.168.232.200/24 dev eth0 label eth0:0
    }
}

测试

KA01关闭

重新开启

10s后

VIP单播配置

[root@KA01 ~]# vim /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.168.232.200/24 dev eth0 label eth0:0
    }
        unicast_src_ip 172.168.232.204
        unicast_peer {
                172.168.232.205
        }
}

[root@KA02 ~]# vim /etc/keepalived/keepalived.conf

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 80
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.168.232.200/24 dev eth0 label eth0:0
    }
         unicast_src_ip 172.168.232.205
        unicast_peer {
                172.168.232.204
        }
}

测试

实现 master/master 的 Keepalived 双主架构

[root@KA01 ~]# vim /etc/keepalived/keepalived.conf

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.168.232.200/24 dev eth0 label eth0:0
    }
        unicast_src_ip 172.168.232.204
        unicast_peer {
                172.168.232.205
        }
}

vrrp_instance VI_2 {
    state BACKUP
    interface eth0
    virtual_router_id 52
    priority 80
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.168.232.200/24 dev eth0 label eth0:1
    }
        unicast_src_ip 172.168.232.204
        unicast_peer {
                172.168.232.205
        }
}
[root@KA02 ~]# vim /etc/keepalived/keepalived.conf

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 80
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.168.232.200/24 dev eth0 label eth0:0
    }
         unicast_src_ip 172.168.232.205
        unicast_peer {
                172.168.232.204
        }
}

vrrp_instance VI_2 {
    state MASTER
    interface eth0
    virtual_router_id 52
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.168.232.200/24 dev eth0 label eth0:1
    }
        unicast_src_ip 172.168.232.205
        unicast_peer {
                172.168.232.204
        }
}

全部开启

关闭 KA01

实现IPVS的高可用性

[root@KA01 ~]# vim /etc/keepalived/keepalived.conf

virtual_server 172.168.232.200 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    protocol TCP
    real_server 172.168.232.202 80 {
        HTTP_GET {
            url {
              path /
                status_code 200
            }
            connect_timeout 3
            retry 3
            delay_before_retry 3

        }
    }
        real_server 172.168.232.203 80 {
        HTTP_GET {
            url {
              path /
                status_code 200
            }
            connect_timeout 3
            retry 3
            delay_before_retry 3
        }
}

[root@KA02 ~]# vim /etc/keepalived/keepalived.conf

virtual_server 172.168.232.200 80 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    protocol TCP
    real_server 172.168.232.202 80 {
        HTTP_GET {
            url {
              path /
                status_code 200
            }
            connect_timeout 3
            retry 3
            delay_before_retry 3

        }
    }
        real_server 172.168.232.203 80 {
        HTTP_GET {
            url {
              path /
                status_code 200
            }
            connect_timeout 3
            retry 3
            delay_before_retry 3
        }
}

第一台RS1故障,自动切换至RS2

KA01故障,自动切换至KA02

实现HAProxy高可用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值