7.Nginx与keepalived实验二

2017-12-19  本文已影响0人  经纶先生

环境说明:

实际使用方式:
两台设备上的应用服务A同时开启,只让有VIP的一端的服务器提供服务,若主的宕机,VIP会自动漂移到备的上面去,因此用户的请求就直接发送到备服务器上去了

两台设备:

10.1.13.4 MASTER
10.1.13.5 BACKUP

10.1.13.4 MASTER的配置

[root@bogon keepalived]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
     845105563@qq.com
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id lb01
   vrrp_skip_check_adv_addr
   #vrrp_strict  #这条一定要注释,不然VIP 无法被ping通
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state MASTER
    interface bond0
    virtual_router_id 51
    priority 150
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.1.13.200    
        
    }
}

启动keepalived

ip addr 

4: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
    link/ether 0c:c4:7a:28:2f:50 brd ff:ff:ff:ff:ff:ff
    inet 10.1.13.4/24 brd 10.1.13.255 scope global bond0
       valid_lft forever preferred_lft forever
    inet 10.1.13.200/32 scope global bond0
       valid_lft forever preferred_lft forever
    inet6 fe80::ec4:7aff:fe28:2f50/64 scope link 
       valid_lft forever preferred_lft forever

你发现多了一行:inet 10.1.13.200/32 scope global bond0

10.1.13.5 BACKUP配置

[root@bogon keepalived]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
     845105563@qq.com
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id lb02                        #不同
   vrrp_skip_check_adv_addr
   #vrrp_strict  #这条一定要注释,不然VIP 无法被ping通
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state BACKUP                     #不同
    interface bond0                  #不同
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.1.13.200    
        
    }
}

ip addr 发现backup没有这个10.1.13.200 IP地址

主备切换实验

停掉主服务器的keepalived服务,检查 10.1.13.200 VIP的位置
我们发现10.1.13.200 切换到 10.1.13.5 上面去了
此时我们再启动主服务器的keepalived服务,发现10.1.13.200 又回来了
这就是不抢占原则

上一篇 下一篇

猜你喜欢

热点阅读