1. 下载源码包
cd /root
wget https://www.keepalived.org/software/keepalived-2.0.20.tar.gz
2. 解压安装
[/root#]tar -zxf keepalived-2.0.20.tar.gz
[/root#] cd keepalived-2.0.20
[/root/keepalived-2.0.20#] ./configure --prefix=/usr/local/keepalived
[/root/keepalived-2.0.20#] make && make install
3. 修改配置文件路径
[/root/keepalived-2.0.20#] mkdir /etc/keepalived
[/root/keepalived-2.0.20#] cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf
[/root/keepalived-2.0.20#] mkdir /etc/sysconfig
[/root/keepalived-2.0.20#] cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/keepalived#
[/root/keepalived-2.0.20#] cp /usr/local/keepalived/sbin/keepalived /usr/sbin/keepalived
[/root/keepalived-2.0.20#] cp /root/keepalived-2.0.20/keepalived/etc/init.d/keepalived /etc/init.d/keepalived
4. 修改配置内容
由于 ubuntu下没有 /etc/rc.d/init.d/functions需要为其建立软链
[/root/keepalived-2.0.20#] mkdir -p /etc/rc.d/init.d
[/root/keepalived-2.0.20#] ln -s /lib/lsb/init-functions /etc/rc.d/init.d/functions
修正相关配置问题
修改/etc/init.d/keepalived文件
[/root/keepalived-2.0.20#] apt install daemon
修改为daemon -- keepalived ${KEEPALIVED_OPTIONS} # 加了一个“--”
加载配置,启动keepalived
#systemctl daemon-reload #重新加载服务
#/etc/init.d/keepalived start #启动keealived服务
#######service keepalived start #启动keealived服务
#service keepalived status #可以查看运行状态
p a #查看是否占用了VIP,只有主服务器可以占用,主有问题时,才会漂移到从服务器,并且从服务器状态变为MASTER
如果启动出现问题,除了这里的输出信息,还可以通过 /var/log/syslog来查看问题
参考文档: