KeepAlived安装
可以使用rpm安装,自动寻找依赖,简化安装流程。
源码安装:
需要先安装openssl-devel
安装openssl-devel出现冲突问题:
initscripts conflicts with redhat-release-server-7.2-9.el7.x86_64
解决:卸载冲突包
参考:
http://www.mamicode.com/info-detail-2369782.html
http://blog.51cto.com/2484643/2140696
http://www.cnblogs.com/LHXW/p/9593520.html
./configure配置KeepAlived出现configure: error: libnfnetlink headers missing问题:
yum install -y libnfnetlink-devel
安装相关依赖
参考:
https://blog.yoodb.com/yoodb/article/detail/1378
https://www.cnblogs.com/succeed/p/6697185.html
安装KeepAlived及常见问题:
https://www.cnblogs.com/linuxlinuxlinux/p/7699771.html
https://blog.csdn.net/liupeifeng3514/article/details/79018116
https://blog.csdn.net/xyang81/article/details/52554398
https://www.cnblogs.com/dcrq/p/5642680.html
配置完成后,需要使用systemctl enable keepalived.service加为开机启动系统服务,实际是建立一个到启动目录的链接,原理详见rhel7开机启动服务一篇。
然后,service keepalived start,发现不管用:
[root@localhost sbin]# service keepalived start
Starting keepalived (via systemctl): [ OK ]
[root@localhost sbin]# systemctl status keepalived.service
● keepalived.service - LVS and VRRP High Availability Monitor
Loaded: loaded (/usr/lib/systemd/system/keepalived.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Thu 2018-12-20 23:09:17 EST; 2s ago
Process: 9681 ExecStart=/usr/local/keepalived/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 9682 (code=exited, status=0/SUCCESS)
Dec 20 23:09:11 localhost.localdomain Keepalived_healthcheckers[9683]: Openin...
Dec 20 23:09:11 localhost.localdomain Keepalived_vrrp[9684]: (VI_1): No VIP s...
Dec 20 23:09:11 localhost.localdomain Keepalived_healthcheckers[9683]: Activa...
Dec 20 23:09:11 localhost.localdomain Keepalived_healthcheckers[9683]: Activa...
Dec 20 23:09:11 localhost.localdomain Keepalived_healthcheckers[9683]: Activa...
Dec 20 23:09:11 localhost.localdomain Keepalived_healthcheckers[9683]: Activa...
Dec 20 23:09:11 localhost.localdomain Keepalived_healthcheckers[9683]: Activa...
Dec 20 23:09:12 localhost.localdomain Keepalived_vrrp[9684]: Stopped
Dec 20 23:09:12 localhost.localdomain Keepalived[9682]: Keepalived_vrrp exite...
Dec 20 23:09:12 localhost.localdomain Keepalived[9682]: Stopping
Hint: Some lines were ellipsized, use -l to show in full.
所以要用systemctl命令启动:
[root@localhost sbin]# systemctl enable keepalived.service
[root@localhost sbin]# systemctl restart keepalived.service
[root@localhost sbin]# systemctl status keepalived.service
● keepalived.service - LVS and VRRP High Availability Monitor
Loaded: loaded (/usr/lib/systemd/system/keepalived.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2018-12-20 23:10:04 EST; 3s ago
Process: 9755 ExecStart=/usr/local/keepalived/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 9756 (keepalived)
CGroup: /system.slice/keepalived.service
└─9756 /usr/local/keepalived/sbin/keepalived -D
Dec 20 23:10:04 localhost.localdomain Keepalived_vrrp[9758]: Registering grat...
Dec 20 23:10:04 localhost.localdomain Keepalived_vrrp[9758]: Opening file '/e...
Dec 20 23:10:04 localhost.localdomain Keepalived_vrrp[9758]: Cant find interf...
Dec 20 23:10:04 localhost.localdomain Keepalived_vrrp[9758]: Default interfac...
Dec 20 23:10:04 localhost.localdomain systemd[1]: Started LVS and VRRP High A...
Dec 20 23:10:04 localhost.localdomain Keepalived_vrrp[9758]: Default interfac...
Dec 20 23:10:04 localhost.localdomain Keepalived_vrrp[9758]: Default interfac...
Dec 20 23:10:04 localhost.localdomain Keepalived_vrrp[9758]: (VI_1): No VIP s...
Dec 20 23:10:05 localhost.localdomain Keepalived[9756]: Keepalived_vrrp exite...
Dec 20 23:10:05 localhost.localdomain Keepalived[9756]: Stopping
Hint: Some lines were ellipsized, use -l to show in full.
服务启动报错问题:
Job for keepalived.service failed because a configured resource limit was exceeded. See "systemctl status keepalived.service" and "journalctl -xe" for details.
解决:(注意完全按照下文操作,看全做全每个步骤!!)
https://blog.csdn.net/zsg88/article/details/76690847
需要注意的是在修改了启动脚本后,需要使用systemctl daemon-reload重新载入systemd,扫描新的或有变动的单元
否则修改的脚本无法生效!!一般也是启动报错原因。
启动前配置必要文件,拷贝必要文件问题:
https://blog.csdn.net/weixin_40885374/article/details/81018645
https://blog.csdn.net/dingsai88/article/details/51015681
缺少的必要文件(脚本)编写参照:
http://www.mamicode.com/info-detail-1181951.html
注意:脚本配置问题,脚本文件也可以直接去keepalived源码目录keepalived/etc子目录拷贝,注意修改脚本文件中配置的pid位置,配置文件位置,sysconfig脚本位置,
把源码目录拥有的这些文件拷贝到脚本中配置的对应位置,注意访问权限问题
脚本参考:
#!/bin/sh
#
#Startup script for the Keepalived daemon
#
# processname: keepalived
# pidfile: /var/run/keepalived.pid
# config: /etc/keepalived/keepalived.conf
# chkconfig: - 21 79
# description: Start and stop Keepalived
# Source function library
. /etc/rc.d/init.d/functions
# Source configuration file (we set KEEPALIVED_OPTIONS there)
. /usr/local/keepalived/etc/sysconfig/keepalived
RETVAL=0
prog="keepalived"
start() {
echo -n $"Starting $prog: "
daemon keepalived ${KEEPALIVED_OPTIONS}
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
}
这个脚本实际上不全,缺少restart,stop等功能脚本内容,具体脚本参照源码包目录keepalived-1.3.5/keepalived/etc/init.d下面的keepalived脚本文件!!
配置注意
虚拟机设置KeepAlived的VIP,需要设置和虚拟网关同一网段的,才可通过外网访问(虚拟机内网则无所谓)。这里设置和172.20.10.30同一网段的比如172.20.10.150,172.20.10.151,可以外网访问。如果设置成如192.168.xxx则无法外网访问!!这时虚拟机设置的限制。
双主配置:
https://www.cnblogs.com/mmdln/p/8988951.html
vim块(列)操作:
https://blog.csdn.net/MrJonathan/article/details/51887980