Ubuntu下部署Keepalived
Keepalived是一种防止单点故障的高可用解决方案。
首先下载:
cd /usr
wget http://www.keepalived.org/software/keepalived-1.2.7.tar.gz
解压: www.zhishiwu.com
tar zxvf keepalived-1.2.7.tar.gz
编译之前需要安装几个程序库
[plain]
apt-get install libssl-dev
apt-get install openssl
apt-get install libpopt-dev
然后运行
[plain]
./configure --prefix=/usr
得到如下结果:
[plain]
Keepalived configuration
------------------------
Keepalived version : 1.2.7
Compiler : gcc
Compiler flags : -g -O2
Extra Lib : -lpopt -lssl -lcrypto
Use IPVS Framework : Yes
IPVS sync daemon support : Yes
IPVS use libnl : No
Use VRRP Framework : Yes
Use VRRP VMAC : Yes
SNMP support : No
Use Debug flags : No
编译吧:
make
make install
程序安装到下面几个目录:
/usr/sbin中包含可执行程序keepalived
www.zhishiwu.com
/usr/etc/keepalived/ 中包含了配置文件和例子
/usr/etc/rc.d/init.d/keepalived 是可以作为service的脚本文件,复制到/etc/init.d目录下
修改三处:
[plain]
#. /etc/rc.d/init.d/functions
. /lib/lsb/init-functions
[plain]
#. /etc/sysconfig/keepalived
. /usr/etc/sysconfig/keepalived
因为redhat之外的Linux没有上面两处目录。 www.zhishiwu.com
下面也要修改,将${..} 直接用start替换。
[plain]
start() {
echo -n $"Starting $prog: "
#daemon keepalived ${KEEPALIVED_OPTIONS}
daemon keepalived start
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
}
还要创建目录
[plain]
mkdir -p /var/lock/subsys
现在设置为系统服务
[plain]
update-rc.d keepalived default
安装daemon服务。
apt-get install daemon
好了,终于可以正常启动了。
service keepalived start
关闭用
service keepalived stop