码迷,mamicode.com
首页 > 其他好文 > 详细

【转】使用keepalived设置虚拟IP环境

时间:2019-02-22 21:23:46      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:lower   不包含   配置   eve   查看   chkconfig   ip地址   ever   tps   

准备

  准备两台机器,IP地址信息如下:

host1: 192.168.56.103
host2: 192.168.56.104

  为了测试需要,分别在两台机器上安装apache并启动httpd服务,使下面两个url均可访问:

  •   http://192.168.56.103
  •   http://192.168.56.104

安装keepalived

  在两台机器上分别安装keepalived

sudo yum install -y keepalived

配置keepalived

host1上keepalived 配置

$ cat /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
    state MASTER
    interface eth2
    virtual_router_id 51
    priority 101
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 123456
    }
    virtual_ipaddress {
        192.168.56.105
    }
}

host2上keepalived 配置

$ cat /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
    state MASTER
    interface eth2
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 123456
    }
    virtual_ipaddress {
        192.168.56.105
    }
}

启动keepalived 服务

$ sudo service keepalived start
$ sudo chkconfig keepalived on

测试

  服务启动后,先访问下面的虚拟地址访问http服务器

http://192.168.56.105

查看IP地址信息

host1上IP地址信息

$ ip addr show eth2
3: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:32:83:82 brd ff:ff:ff:ff:ff:ff
    inet 192.168.56.103/24 brd 192.168.56.255 scope global eth2
    inet 192.168.56.105/32 scope global eth2
    inet6 fe80::a00:27ff:fe32:8382/64 scope link
       valid_lft forever preferred_lft forever

  其中可以看到inet 192.168.56.105/32 scope global eth2,说明现在host1是作为虚拟IP的master来运行的。

host2上IP地址信息

$ ip addr show eth2
3: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:ec:90:7b brd ff:ff:ff:ff:ff:ff
    inet 192.168.56.104/24 brd 192.168.56.255 scope global eth2
    inet6 fe80::a00:27ff:feec:907b/64 scope link
       valid_lft forever preferred_lft forever

  此时host2上ip地址信息中不包含虚拟IP"192.168.56.105"信息。

验证IP地址Failover

  现在手动停止host1上的keepalived服务

$ sudo service keepalived stop

host1上IP地址信息

$ ip addr show eth2
3: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:32:83:82 brd ff:ff:ff:ff:ff:ff
    inet 192.168.56.103/24 brd 192.168.56.255 scope global eth2
    inet6 fe80::a00:27ff:fe32:8382/64 scope link
       valid_lft forever preferred_lft forever

  此时host1上ip地址信息中不再包含虚拟IP"192.168.56.105"信息。

host2上IP地址信息

$ ip addr show eth2
3: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:ec:90:7b brd ff:ff:ff:ff:ff:ff
    inet 192.168.56.104/24 brd 192.168.56.255 scope global eth2
    inet 192.168.56.105/32 scope global eth2
    inet6 fe80::a00:27ff:feec:907b/64 scope link
       valid_lft forever preferred_lft forever

  现在可以看到host2上ip地址信息中已经包含虚拟IP"192.168.56.105"信息了。

  此时如果再把host1上的keepalived服务启动,会发现虚拟IP"192.168.56.105"又重新绑定到host1上了。

 

转载自《使用 keepalived 设置虚拟 IP 环境

  

 

【转】使用keepalived设置虚拟IP环境

标签:lower   不包含   配置   eve   查看   chkconfig   ip地址   ever   tps   

原文地址:https://www.cnblogs.com/codingmengmeng/p/10420575.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!