不急不徐,持之以恒。

http://blog.gopersist.com/

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  24 随笔 :: 0 文章 :: 52 评论 :: 0 Trackbacks
试用Keepalived来做双机热备,服务器信息如下:
服务器 操作系统 IP 虚拟IP
Server 1 Centos 192.168.18.20 192.168.18.22
Server 2 Centos 192.168.18.21 192.168.18.22

1. 安装Keepalived

2台Server都使用下面的命令安装Keepalived:
yum install keepalived -y

2. Server1 Keepalived 配置

$ vi /etc/keepalived/keepalived.conf

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100                   # 优先级
    advert_int 1                 # 心跳间隔(秒)
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.18.22         # 虚拟IP
    }
}

3. Server2 Keepalived 配置

$ vi /etc/keepalived/keepalived.conf

vrrp_instance VI_1 {
    state BACKUP              # 备份机
    interface eth0
    virtual_router_id 51
    priority 99                   # 优先级,比主服务器底
    advert_int 1                 # 心跳间隔(秒)
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.18.22         # 虚拟IP
    }
}

4. 启动Keepalived

$ service keepalived start
启动keepalived后,可看到2台Server都绑定了虚拟IP:
$ ip a

# Server 1:
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:24:8c:8c:67:43 brd ff:ff:ff:ff:ff:ff
    inet 192.168.18.20/24 brd 192.168.18.255 scope global eth0
    inet 192.168.18.22/32 scope global eth0
    inet6 fe80::224:8cff:fe8c:6743/64 scope link 
       valid_lft forever preferred_lft forever

# Server 2:
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:23:54:bf:ab:17 brd ff:ff:ff:ff:ff:ff
    inet 192.168.18.21/24 brd 192.168.18.255 scope global eth0
    inet 192.168.18.22/32 scope global eth0
    inet6 fe80::223:54ff:febf:ab17/64 scope link 
       valid_lft forever preferred_lft forever

5. 测试

浏览器访问http://192.168.18.22,出现 This is Server 1.
将192.168.18.20关闭,再访问http://192.168.18.22,出现This is Server 2.

微信订阅号:
源文地址:http://blog.gopersist.com/2014/09/24/keepalived/
posted on 2014-09-24 11:34 老林 阅读(2031) 评论(2)  编辑  收藏 所属分类: Linux

评论

# re: Linux Keepalived 实现双机热备 2014-09-25 22:21 java论坛
首先说一下,我不会,只是支持一下。我纯软件开发的。很佩服你们网络工程师和安全工程师,我之前觉得只有会代码才牛,现在觉得懂得硬件的是真高手!  回复  更多评论
  

# re: Linux Keepalived 实现双机热备 2014-09-30 09:35 sjxifen
看到了,好东西  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: