keepalived的使用与安装
keepalived主要用作RealServer的健康状态检查以及LoadBalance主机和BackUP主机之间failover的实现。
官方网站
http://www.keepalived.org/
ubuntu安装首先要有gcc,openssl,libpopt-dev,libssl-dev
设置库环境变量
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
nonstandard directory <lib dir>
CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
you have headers in a nonstandard directory <include dir>
export LDFLAGS="-L/root/openssl-0.9.8x/lib"
export CPPFLAGS="-I/root/openssl-0.9.8x/include"
export LD_LIBRARY_PATH=/root/openssl-0.9.8x/lib:$LD_LIBRARY_PATH
configure: error: Popt libraries is required
【centos】yum install popt-devel
【ubuntu】apt-get install libpopt-dev
./configure --prefix=/root/keepalived-1.2.7
make
make install
【全局,邮件通知可选】
global_defs {
router_id app_dev
}
【检查,可选】
vrrp_script chk_haproxy { # Requires keepalived-1.1.13
script "killall -0 haproxy"
interval 1 # check every 10 seconds
weight -20 # if failed, decrease 40 of the priority
fall 1 # require 2 failures for failures
rise 1 # require 1 sucesses for ok
}
【主】
vrrp_instance VI_1 {
state MASTER #MASTER/BACKUP
interface eth1
virtual_router_id 51 #如果1个配置文件里,配置了多个virtual_ipaddress,则不能一样,例如vrrp_instance ip_253
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.56.254
}
#可选
track_script {
chk_haproxy
}
}
vrrp_instance ip_253 {
state BACKUP
interface eth1
virtual_router_id 52
priority 70
advert_int 1
authentication {
auth_type PASS
auth_pass open
}
virtual_ipaddress {
192.168.56.253
}
}
【备】
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 51
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.56.99
192.168.56.100
}
}
【ubuntu增加日志输出】
echo "local0.debug /var/log/keepalived.log">> /etc/rsyslog.conf
重启
service rsyslog stop
service rsyslog start
查看日志
tail -f -n 100 /var/log/keepalived.log
启动
./sbin/keepalived -f /root/keepalived-1.2.7/etc/keepalived/keepalived.conf -D -S 0
-D是让keepalived详细记录log
-d是在日志里打出keepalived读到的配置信息
-S 0是到会将日志发送给syslog,且日志定为LOCAL0
附录
安装错误调试参考
http://www.ttlsa.com/html/299.html
# 包扫描
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/root/openssl-0.9.8x/lib/pkgconfig
共享库解决参考
http://blog.sina.com.cn/s/blog_54f82cc201011ve4.html
如有问题请跟帖留言,本人比较忙不支持QQ交流,谢谢理解。