Centos6.8编译安装keepalived-1.3.5步骤
keepalived-1.3.5 下载 http://keepalived.org/software/keepalived-1.3.5.tar.gz
一 首先安装依赖和编译器
yum -y update kernel kernel-headers #升级内核
reboot #重新启动电脑
yum -y install gcc make kernel-devel
yum -y install curl libnl3-devel iptables-devel libnfnetlink-devel ipset-devel openssl-devel net-snmp-devel
二 编译keepalived
#安装在/usr/local/keepalived目录
./configure --prefix=/usr/local/keepalived \
--with-kernel-dir=/usr/src/kernels/`uname -r`
make
三 安装keepalived
make install
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
mkdir /etc/keepalived
ln -s /usr/local/keepalived/sbin/keepalived /usr/sbin/
touch /etc/init.d/keepalived
chmod +x /etc/init.d/keepalived
vi /etc/init.d/keepalived
keepalived脚本内容如下
#!/bin/sh
#
# keepalived High Availability monitor built upon LVS and VRRP
#
# chkconfig: - 86 14
# description: Robust keepalive facility to the Linux Virtual Server project \
# with multilayer TCP/IP stack checks.
### BEGIN INIT INFO
# Provides: keepalived
# Required-Start: $local_fs $network $named $syslog
# Required-Stop: $local_fs $network $named $syslog
# Should-Start: smtpdaemon httpd
# Should-Stop: smtpdaemon httpd
# Default-Start:
# Default-Stop: 0 1 2 3 4 5 6
# Short-Description: High Availability monitor built upon LVS and VRRP
# Description: Robust keepalive facility to the Linux Virtual Server
# project with multilayer TCP/IP stack checks.
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
exec="/usr/sbin/keepalived"
prog="keepalived"
config="/etc/keepalived/keepalived.conf"
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
lockfile=/var/lock/subsys/keepalived
start() {
[ -x $exec ] || exit 5
[ -e $config ] || exit 6
echo -n $"Starting $prog: "
daemon $exec $KEEPALIVED_OPTIONS
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
reload() {
echo -n $"Reloading $prog: "
killproc $prog -1
retval=$?
echo
return $retval
}
force_reload() {
restart
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status &>/dev/null
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
esac
exit $?
四 配置和运行keepalived
vi /etc/keepalived/keepalived.conf #配置正确
chkconfig --add keepalived
chkconfig keepalived on
service keepalived start
五 查看keepalived运行日志
more /var/log/messages |grep -E "\\[" |grep keepalived