本节内容:
Ubuntu下编译安装Keepalived
说明:Keepalived是一种防止单点故障的高可用解决方案。
有关keepalived的详细介绍,可以参考文章:
lvs与keepalived 完全安装
keepalived 配置文件的中文注解
keepalived双机热备的简单配置实例
nginx+keepalived配置高可用的负载均衡
lvs+keepalived配置高可用的负载均衡
haproxy+keepalived配置高可用负载均衡
haproxy+keepalived负载均衡之主备切换(centos)
下面说说具体的编译安装步骤。
首先,下载Keepalived:
复制代码 代码示例:
cd /usr
wget http://www.keepalived.org/software/keepalived-1.2.7.tar.gz
使用linuxjishu/14048.html target=_blank class=infotextkey>tar命令解压缩:
复制代码 代码示例:
tar zxvf keepalived-1.2.7.tar.gz
编译之前需要安装几个程序库:
复制代码 代码示例:
apt-get install libssl-dev
apt-get install openssl
apt-get install libpopt-dev
然后运行:
复制代码 代码示例:
./configure --prefix=/usr
得到如下结果:
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
/usr/etc/keepalived/ 中包含了配置文件和例子
/usr/etc/rc.d/init.d/keepalived 是可以作为service的脚本文件,复制到/etc/init.d目录下
修改三处:
复制代码 代码示例:
#. /etc/rc.d/init.d/functions
. /lib/lsb/init-functions
#. /etc/sysconfig/keepalived
. /usr/etc/sysconfig/keepalived
因为redhat之外的Linux没有上面两处目录。
下面也要修改,将${..} 直接用start替换。
复制代码 代码示例:
start() {
echo -n $"Starting $prog: "
#daemon keepalived ${KEEPALIVED_OPTIONS}
daemon keepalived start
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
}
创建目录:
复制代码 代码示例:
mkdir -p /var/lock/subsys
设置为系统服务:
复制代码 代码示例:
update-rc.d keepalived default
安装daemon服务:
复制代码 代码示例:
apt-get install daemon
启动keepalived:
复制代码 代码示例:
service keepalived start
关闭keepalived:
复制代码 代码示例:
service keepalived stop