6月 23

keepalived 实现 HA || AS

【整理人:张子萌 2010-06-23】
使用keepalived实现HA(High Availability)的架构,解决双机热备工作。

keepalived进行简单配置后即可使用。对nginx、tomcat、nfs和ssh的服务进行了测试运行正常。使用ping命令测试切换,效果也比较理想。

1。环境介绍

操作系统使用CentOS5。
使用两台服务器,两台的基础IP为192.168.1.3和192.168.1.4,使用vip地址为192.168.1.10。

2。准备工作。

keepalived官方网站http://www.keepalived.org/

下载源码后编译需要使用gcc,如果系统没有需要安装。

3。编译安装

# tar zxvf keepalived-1.1.20.tar.gz
# cd keepalived-1.1.20
# ./configure –prefix=/ –mandir=/usr/local/share/man/ –with-kernel-dir=/usr/src/kernels/2.6.18-164.el5-x86_64
# make
# make install

4。配置部分

使用!和#做为注释符号。

主机部分
# vi /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
notification_email {
simon-zzm@163.com #发送告警的邮件
}
notification_email_from keepalived@liaojie.com
smtp_server 172.0.0.1 #如果本地安装sendmail,可以填写本地IP
smtp_connect_timeout 30
router_id liaojie_devel
}

vrrp_instance VI_1 {
state BACKUP
interface eth0 #绑定vip地址的网卡
garp_master_delay 10
smtp_alert
virtual_router_id 61
priority 150 #vrrp路由竞争级别
advert_int 1
authentication {
auth_type PASS
auth_pass abcd
}
virtual_ipaddress {
192.168.1.10
192.168.1.10 label eth0:1
}
}

备机部分
配置和主机一样 priority的值不一样,主备机之间数据推荐相距50以上。

问题1
在make时报错如下:
/usr/src/kernels/2.6.9-89.0.25.EL-i686/include/linux/types.h:158: error: syntax error before “__sum16”
/usr/src/kernels/2.6.9-89.0.25.EL-i686/include/linux/types.h:158: warning: type defaults to `int’ in declaration of `__sum16′
/usr/src/kernels/2.6.9-89.0.25.EL-i686/include/linux/types.h:158: warning: data definition has no type or storage class
/usr/src/kernels/2.6.9-89.0.25.EL-i686/include/linux/types.h:159: error: syntax error before “__wsum”
/usr/src/kernels/2.6.9-89.0.25.EL-i686/include/linux/types.h:159: warning: type defaults to `int’ in declaration of `__wsum’
/usr/src/kernels/2.6.9-89.0.25.EL-i686/include/linux/types.h:159: warning: data definition has no type or storage class
make[2]: *** [check_daemon.o] 错误 1
make[2]: Leaving directory `/usr/local/src/keepalived-1.1.20/keepalived/check’
make[1]: *** [all] 错误 1
make[1]: Leaving directory `/usr/local/src/keepalived-1.1.20/keepalived’
make: *** [all] 错误 2

解决方案如下:
将types.h调用的部分注释掉
vi /usr/src/kernels/2.6.9-89.0.25.EL-i686/include/linux/types.h
到158行操作如下
#endif /* __KERNEL_STRICT_NAMES */
/*
typedef __u16 __bitwise __sum16;
typedef __u32 __bitwise __wsum;
*/

注:编译没有报错,建议编译完成将注释去掉。