一、環境規劃
1)master:node1,centos7.5,eth0:192.168.1.11,eht1:10.10.1.11,keepalive
2)backup:node1,centos7.5,eth0:192.168.1.12,eth1:10.10.1.12,keepalive
二、搭建步驟
1)node1,node2上都以mini方式安裝CentOS 7.5 64-bit,並按照規劃配置IP地址;
2)node1,node2的/etc/hosts中添加以下內容。
192.168.1.11 node1.xx.xxx.com node1
10.10.1.11 node1.xx.xxx.com node1
192.168.1.12 node2.xx.xxx.com node2
10.10.1.12 node2.xx.xxx.com node2
3)node1,node2安裝keepalive1.3.5
#yum install keeplived
4)配置node1上的keepalive
vi /etc/keepalived/keepalived.conf #進行以下修改
vrrp_instance VI_1 {
state MASTER #設置節點node1爲MASTER角色
interface enp11s0f0 #配置eth0網卡enp11s0f0爲節點node1的系統IP
virtual_router_id 51 #master和backup一致
priority 100 #數字越大,等級越高,保證master比任何backup高
advert_int 1
authentication {
auth_type PASS #vrrp協議,保證master及其餘backup一致
auth_pass 1111 #保證master及其餘backup一致
}node
virtual_ipaddress {
192.168.1.210/24 #VIP
}
5)配置節點node2上的keeplive
vi /etc/keepalived/keepalived.conf #進行以下修改
vrrp_instance VI_1 {
state BACKUP #設置節點node2爲BACKUP角色
interface enp11s0f0 #配置eth0網卡enp11s0f0爲節點node2的系統IP
virtual_router_id 51 #master和backup一致
priority 99 #數字越大,等級越高,保證比master低
advert_int 1
authentication {
auth_type PASS #vrrp協議,保證master及其餘backup一致
auth_pass 1111 #保證master及其餘backup一致
}centos
virtual_ipaddress {
192.168.1.210/24 #VIP
}測試
6)啓動和配置keepalive
systemctl start keepalived.service
systemct enable keepalived.service
三、驗證
1)查看master上keepalive及ip
ps -ef|grep keepalive
ip addr
2)keepalived高可用測試
#關閉node1上的keepalived
systemctl stop keepalived.service
#查看node1上的keepalived和ip
ps -ef|grep keepalived
ip addr
#查看node2上的keepalived和ip
ps -ef|grep keepalived
ip addr
centos7