安装keepalived、系统服务、开机自启
安装步骤
- 下载安装包
下载地址:https://www.keepalived.org/download.html
- 解压安装
- 解压:tar -zxvf keepalived-2.2.7.tar.gz && cd keepalived-2.2.7
- 预配置并设置安装目录:./configure --prefix=/opt/server/keepalived(如果不指定安装目录,默认安装在/usr/local)
- 安装:make && make install (安装好后便是系统服务了)
- 启动前设置
keepalived启动后默认去这个(/etc/keepalived/keepalived.conf)位置读取配置文件,除非另行制定,否则需要将安装文件下带的配置文件拷贝过去
- 将配置文件拷贝过去到(/etc/keepalived/keepalived.conf)
cp /opt/server/keepalived/etc/keepalived/keepalived.conf.sample /etc/keepalived/keepalived.conf
- 指定配置文件
vim /opt/server/keepalived/etc/sysconfig/keepalived
在KEEPALIVED_OPTIONS添加 -f /opt/server/keepalived/etc/keepalived/keepalived.conf 指定配置文件路径
KEEPALIVED_OPTIONS="-D -f /opt/server/keepalived/etc/keepalived/keepalived.conf"
- 启动、结束、状态、重启
systemctl enable keepalived.service 设置开机自动启动
systemctl disable keepalived.service 取消开机自动启动
systemctl daemon-reload 重新加载
systemctl start keepalived.service 启动
systemctl stop keepalived.service 结束
tail -f /var/log/messages 新开窗口执行上面命令,在另一个窗口中操作keepalived,可实时查看keepalived的日志,如果启动异常,日志会打印失败的信息
ip a 设置成功后查看虚拟ip
注意
启动脚本文件:源码解压包下,例如:/opt/server/keepalived-2.2.7/keepalived/etc/init.d/keepalived
启动参数文件:安装包下,例如:/opt/server/keepalived/etc/sysconfig/keepalived
启动文件:安装包下,例如:/opt/server/keepalived/sbin/keepalived
配置文件:默认加载位置/etc/keepalived/keepalived.conf,可以通过 -f 指定配置文件路径
keepalived 的启动脚本文件、启动参数文件、配置文件keepalived.conf、启动文件的执行关系是 启动脚本文件 -> 找到启动参数文件 -> 启动参数文件里描述了keepalived.conf的路径和日志等指令 -> 然后交给启动文件执行(真实启动)。
参考
https://blog.51cto.com/u_11868971/2998864
https://www.jianshu.com/p/fdc0a788f55a/
碰到问题
- 执行./configure 时报错 OpenSSL is not properly installed on your system
- 方式一
yum -y install openssl-devel
- 方式二
tar -xvf openssl-x.x.x.tar.gz cd openssl-x.x.x ./config shared zlib make depend make && make install