节点一上的配置:
切到配置文件的目录下:
[root@host1 ~]#cd /etc/keepalived
[root@host1 keepalived]#cp keepalived.conf{,.bak} <--备份
配置文件
vim keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email { <--真正能接收邮件的邮箱地址
ngt@mgl.com <--邮件地址
}
notification_email_from grh_ngt@mgl.com <--能发邮件的邮箱地址
smtp_server 127.0.0.1 <--邮件服务器
smtp_connect_timeout 30 <--smtp链接超时时间,超了就不发了
router_id host1 <--五里路由器的服务器的ID,直接写上主机名更好
vrrp_mcast_group4 224.89.51.18 <--ipv4多播地址(默认是224.0.0.18)
}
vrrp_instance VI_1 { <--真正的虚拟路由器的配置
state MASTER <--或状态BACKUP
interface ens33 <--配置的接口网卡
virtual_router_id 89 <-- 虚拟路由ID0-255
priority 100 <--当前虚拟路由器之间的优先级
advert_int 1 <--每个多长时间传递优先级
authentication { <--认证
auth_type PASS <--认证方法,简单字符串密码认证,不能超过8位
auth_pass 12345678 <--认证的值,也就是密码(可以用openssl rand -base64 8 命令生成)
}
virtual_ipaddress { <--虚拟地址
192.168.10.66
}
}
vim /keepalived.conf
[root@host1 keepalived]#vim keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
ngt@mgl.com
}
notification_email_from grh_ngt@mgl.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id host1
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 89
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass nQyVIaY1
}
virtual_ipaddress {
192.168.10.66
}
}
"keepalived.conf" 151L, 3560C written
[root@host1 keepalived]#scp keepalived.conf host2:/etc/keepalived/ <--发送到节点2 上
The authenticity of host 'host2 (192.168.10.12)' can't be established.
ECDSA key fingerprint is ed:c4:6c:43:77:9b:ab:a4:d9:64:fb:37:4c:cf:0f:7f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'host2' (ECDSA) to the list of known hosts.
root@host2's password:
keepalived.conf 100% 3560 3.5KB/s 00:00
[root@host1 keepalived]#
节点二上的配置:
节点二的keepalived.conf配置两个节点上分别启动服务:
[root@host1 keepalived]#systemctl start keepalived.service
[root@host2 keepalived]#systemctl start keepalived.service
测试:
-
首先分别在两个节点上查看状态是否正常,尤其注意节点一的状态;
节点1上,也是主节点
节点一:
节点二:
节点二也正常 -
把节点一的服务停掉,再在节点二上查看状态以及IP地址,查看是否转移;
关掉服务之后,作为MASTER的节点一失去了虚拟IP地址
节点一:
节点二:
-
再把节点一的服务启动起来,并查看状态和IP;
节点一:
节点一
节点二:
至此,关于keepalived的vrrp实现地址转移已经结束了;
网友评论