keepalived的实验:主主模型

修改配置文件

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

! Configuration File for keepalived

 

global_defs {

notification_email {

root@localhost

}

notification_email_from keepalived@localhost

smtp_server 127.0.0.1

smtp_connect_timeout 30

router_id proxy1

vrrp_mcast_group4 224.1.1.1

}

 

vrrp_instance VI_1 {

state MASTER

interface ens33

virtual_router_id 66

priority 100

advert_int 1

authentication {

auth_type PASS

auth_pass 123456

}

virtual_ipaddress {

172.18.101.100/16

}

}

vrrp_instance VI_2 {

state BACKUP

interface ens33

virtual_router_id 88

priority 80

advert_int 1

authentication {

auth_type PASS

auth_pass 654321

}

virtual_ipaddress {

172.18.101.200/16

}

}

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

! Configuration File for keepalived

 

global_defs {

notification_email {

root@localhost

}

notification_email_from keepalived@localhost

smtp_server 127.0.0.1

smtp_connect_timeout 30

router_id proxy2

vrrp_mcast_group4 224.1.1.1

}

 

vrrp_instance VI_1 {

state BACKUP

interface ens33

virtual_router_id 66

priority 80

advert_int 1

authentication {

auth_type PASS

auth_pass 123456

}

virtual_ipaddress {

172.18.101.100/16

}

}

vrrp_instance VI_2 {

state MASTER

interface ens33

virtual_router_id 88

priority 90

advert_int 1

authentication {

auth_type PASS

auth_pass 654321

}

virtual_ipaddress {

172.18.101.200/16

}

}

 

启动服务

[root@proxy1 ~]# systemctl start keepalived

[root@proxy2 ~]# systemctl start keepalived

 

查看绑定的地址

[root@proxy1 ~]# ip a

2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

link/ether 00:0c:29:97:37:50 brd ff:ff:ff:ff:ff:ff

inet 172.18.101.101/16 brd 172.18.255.255 scope global ens33

valid_lft forever preferred_lft forever

inet 172.18.101.100/16 scope global ens33

valid_lft forever preferred_lft forever

inet6 fe80::e23e:b5ac:1372:e2c9/64 scope link

valid_lft forever preferred_lft forever

 

[root@proxy2 ~]# ip a

2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

link/ether 00:0c:29:19:6e:40 brd ff:ff:ff:ff:ff:ff

inet 172.18.101.104/16 brd 172.18.255.255 scope global ens33

valid_lft forever preferred_lft forever

inet 172.18.101.200/16 scope global ens33

valid_lft forever preferred_lft forever

inet6 fe80::a9dc:91cc:e2f3:6d34/64 scope link

valid_lft forever preferred_lft forever

 

如果坏掉一台服务器,另一台机器应该接管两个地址

[root@proxy1 ~]# systemctl stop keepalived

 

[root@proxy2 ~]# ip a

2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

link/ether 00:0c:29:19:6e:40 brd ff:ff:ff:ff:ff:ff

inet 172.18.101.104/16 brd 172.18.255.255 scope global ens33

valid_lft forever preferred_lft forever

inet 172.18.101.200/16 scope global ens33

valid_lft forever preferred_lft forever

inet 172.18.101.100/16 scope global ens33

valid_lft forever preferred_lft forever

inet6 fe80::a9dc:91cc:e2f3:6d34/64 scope link

valid_lft forever preferred_lft forever

 

 

服务器修复后,会重新接管自己的地址

 

 

写的子网掩码有问题

修改

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

virtual_ipaddress {

172.18.101.200/16

}

 

这就是主主模型

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/92063

联系我们

400-080-6560

在线咨询

工作时间:周一至周五,9:30-18:30,节假日同时也值班

QR code