keepalived打算分三篇来写,第一篇为keepalived的安装,第二篇为keepalived+nginx实现主从模式的高可用,第三篇为keepalived+nginx实现双主模式。
本篇为keepalived第一篇:keepalived1.4.0安装启动卸载。(环境为CentOS6.4)
keepalived官网:http://www.keepalived.org/
keepalived1.2 和 keepalived1.4在linux下安装稍有不同。
我安装的版本为keepalived1.4.0。
第一步:下载安装包。
wget http://www.keepalived.org/software/keepalived-1.4.0.tar.gz
第二步:安装环境依赖
yum -y 环境(参考官网)
在实际安装中,可能和官网有所不同,可以根据提示信息在yum相应环境,我在安装环境依赖时遇到了error: libnfnetlink headers missing报错信息,解决方法:yuminstall-y libnfnetlink-devel。
第三步:解压
进入到安装包所在目录,执行: tar -zxvf keepalived-1.4.0.tar.gz
第四步:配置
进入到解压后的目录,执行:./configure --prefix=/usr/local/keepalived
第五步:编译和安装
在第四步基础上,执行:make && make install
第六步:配置为系统服务
keepalived1.2 和 keepalived1.4的不同,就在这一步。1.4的版本编译安装后,在usr/local/keepalived/etc下并没有init.d/keepalived,而1.2版本是有的。当时猜想,1.4版本的init.d/keepalived需要到解压后的目录中找,网上查阅资料后验证了此猜想。
步骤:
cp keepalived-1.4.0/keepalived/etc/init.d/keepalived /etc/init.d/
对于上条命令的说明: keepalived-1.4.0为解压安装包到的目录,init.d/keepalived 为配置成系统服务时供service命令调用的脚本文件,该文件部分内容如下:
由上图可以看出:配置成系统服务还需要三个文件,keepalived/keepalived.conf配置文件、 sysconfig/keepalived一些参数配置,并且这两个文件需要在目录 /etc/keepalived中,此外还需要调用sbin/keepalived命令。因此,需要创建这个目录,并把需要的三个文件拷贝过去。执行如下命令:
mkdir /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp keepalived-1.4.0/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
ln -s /usr/local/keepalived/sbin/keepalived /usr/sbin/
第七步:启动keepalived
Keepalived 服务管理命令:
停止:service keepalived stop
启动: service keepalived start
重启: service keepalived restart
查看状态: service keepalived status
执行service keepalived start启动服务,并验证是否启动成功。
提示:如果服务启动失败,出现如下图所示的信息,原因是keepalived.conf配置文件不正确。
查看虚拟出来的ip,输入ip add
第八步:设置开启启动
chkconfig keepalived on
keepalived的卸载
卸载时,进入keepalived安装包解压后目录,执行:
make uninstall
然后删除相关文件(步骤六中拷贝的几个文件以及创建的软链接)。
完。