Chinaunix首页 | 论坛 | 博客
  • 博客访问: 11492461
  • 博文数量: 48
  • 博客积分: 7017
  • 博客等级: 少将
  • 技术积分: 2073
  • 用 户 组: 普通用户
  • 注册时间: 2006-08-24 09:50
文章分类

全部博文(48)

文章存档

2011年(4)

2010年(15)

2009年(15)

2008年(14)

我的朋友

分类: LINUX

2009-06-30 22:52:04

有个项目可能用到,因此研究了一下。
Keepalived是Linux下面实现VRRP 备份路由的高可靠性运行件。基于Keepalived设计的服务模式能够真正做到主服务器和备份服务器故障时IP瞬间无缝交接。
网络环境:
三台服务器:
VIP:192.168.1.30
realserver1:192.168.1.22
realserver2:192.168.1.23
安装步骤:
前提条件需要有安装如下组件:
 openssl-devel-0.9.8a-18.26.i586.rpm
 popt-devel-1.7-271.27.i586.rpm
keepalived的安装比较简单(下载地址:):
在realserver1上操作:
在keepalived的解压目录执行如下命令:
#./configure --prefix=/usr/local/keepalived
#make
#make install
主要是修改配置文件(/usr/local/keepalived/etc/keepalived/keepalived.conf):
! Configuration File for keepalived
vrrp_script chk_http_port {
       script "       interval 1                      # check every second
       weight -2                       # default prio: -2 if connect fails
}
global_defs {
   notification_email {
   

   }
   notification_email_from 

   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id HA_1
}
}
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    mcast_src_ip 192.168.1.22
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass freeke
    }
    virtual_ipaddress {
    192.168.1.30
    }
    track_script {
           chk_http_port
      }
}

在realserver2上执行与realserver1的相同操作,配置文件有点区别,主要体现在state和priority参数上如下:
! Configuration File for keepalived
vrrp_script chk_http_port {
       script "       interval 1                      # check every second
       weight -2                       # default prio: -2 if connect fails
}
global_defs {
   notification_email {
   

   }
   notification_email_from 

   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id HA_1
}
}
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    mcast_src_ip 192.168.1.23
    priority 99
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass freeke
    }
    virtual_ipaddress {
    192.168.1.30
    }
    track_script {
           chk_http_port
    }
}

经过以上的操作只需要执行如下命令即可启动:
#/usr/local/keepalived/sbin/keepalived -f /usr/local/keepalived/etc/keepalived/keepalived.conf -D
查看是否启动成功可按照如下方法操作:
A.  # tail -f /var/log/messages
若有如下内容输出则启动成功:

Jul  1 06:19:29 db Keepalived: Starting Keepalived v1.1.17 (06/28,2009)
Jul  1 06:19:29 db Keepalived: Starting Healthcheck child process, pid=1527
Jul  1 06:19:29 db Keepalived: Starting VRRP child process, pid=1528
Jul  1 06:19:29 db Keepalived_healthcheckers: Using MII-BMSR NIC polling thread...
Jul  1 06:19:29 db Keepalived_vrrp: Using MII-BMSR NIC polling thread...
Jul  1 06:19:29 db Keepalived_healthcheckers: Netlink reflector reports IP 192.168.1.22 added
Jul  1 06:19:29 db Keepalived_healthcheckers: Registering Kernel netlink reflector
Jul  1 06:19:29 db Keepalived_healthcheckers: Registering Kernel netlink command channel
Jul  1 06:19:29 db Keepalived_healthcheckers: Opening file 'etc/keepalived/keepalived.conf'.
Jul  1 06:19:29 db Keepalived_healthcheckers: Configuration is using : 5901 Bytes
Jul  1 06:19:29 db Keepalived_vrrp: Netlink reflector reports IP 192.168.1.22 added
Jul  1 06:19:29 db Keepalived_vrrp: Registering Kernel netlink reflector
Jul  1 06:19:29 db Keepalived_vrrp: Registering Kernel netlink command channel
Jul  1 06:19:29 db Keepalived_vrrp: Registering gratutious ARP shared channel
Jul  1 06:19:29 db Keepalived_vrrp: Opening file 'etc/keepalived/keepalived.conf'.
Jul  1 06:19:29 db Keepalived_vrrp: Configuration is using : 35764 Bytes
Jul  1 06:19:29 db Keepalived_vrrp: VRRP sockpool: [ifindex(2), proto(112), fd(10,11)]
Jul  1 06:19:30 db Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Jul  1 06:19:31 db Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
Jul  1 06:19:31 db Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.
Jul  1 06:19:31 db Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.1.30
Jul  1 06:19:31 db avahi-daemon[2425]: Registering new address record for 192.168.1.30 on eth0.
Jul  1 06:19:31 db Keepalived_healthcheckers: Netlink reflector reports IP 192.168.1.30 added
Jul  1 06:19:31 db Keepalived_vrrp: Netlink reflector reports IP 192.168.1.30 added
Jul  1 06:19:36 db Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.1.30
B. ping 192.168.1.30有返回值则OK。
可以在服务器master服务器上执行:ip add show eth0
看看是否有192.168.1.30的虚拟IP存在,存在则正常。
 
到此完成了keepalived的配置。只要在真实机器上启动相应的服务看看是否正常,有问题记得日志。到此完成了keepalived的双机配置。
 
 
 

 
阅读(3452) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~