keepalived之vrrp实现地址转移

2017-09-05  本文已影响0人  Sainbyno

节点一上的配置:
切到配置文件的目录下:

[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

测试:

节点二:

虚拟IP地址已经成功转移到节点二上了 查看节点二的IP地址能看到虚拟IP地址已经成功转移过来了

节点二:

节点二

至此,关于keepalived的vrrp实现地址转移已经结束了;

上一篇下一篇

猜你喜欢

热点阅读