Keepalived高可用

VRRP

Keepalived高可用_第1张图片
image

1.准备环境

  1. 准备机器lb01 lb02 web01 web02
  2. lb01 lb02 安装软件
    yum install keepalived -y
[root@lb01 nginx]# rpm -qa keepalived 
keepalived-1.3.5-8.el7_6.x86_64

[root@lb02 ~]# rpm -qa keepalived 
keepalived-1.3.5-8.el7_6.x86_64

2.开启服务与自启动

lb01:
[root@lb01 nginx]# systemctl start keepalived.service 
[root@lb01 nginx]# systemctl enable keepalived.service 

lb02:
[root@lb02 ~]# systemctl start keepalived.service 
[root@lb02 ~]# systemctl enable keepalived.service 

2.利用Wireshark抓包

Keepalived高可用_第2张图片
image

随便抓个包看看:

Keepalived高可用_第3张图片
image

3.配置文件

/etc/keepalived/keepalived.conf

Keepalived高可用_第4张图片
image

配置文件格式:

修改前将源配置文件备份

[root@lb01 nginx]# vim  /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
    router_id lb01
}

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

4.lb01与lb02的keepalived配置文件

Keepalived高可用_第5张图片
image
Keepalived高可用_第6张图片
image

测试一下

主关闭后,备接管
主恢复后,优先级高于备,自动跳转回来

image

Keepalived高可用_第7张图片
image

Keepalived高可用_第8张图片
image

你可能感兴趣的:(Keepalived高可用)