安装Keepalived
在官网下载Keepalived,https://www.keepalived.org/download.html
将安装包上传到服务器的/mydata/keepalived目录
解压安装包
tar -zxvf keepalived-2.0.18.tar.gz
安装 libnl/libnl-3依赖
yum -y install libnl libnl-devel
解压后进入到解压路径,会看到configure,使用configure命令配置安装目录与核心配置文件所在位置
./configure --prefix=/usr/local/keepalived --sysconf=/etc
prefix:keepalived安装的位置
sysconf:keepalived核心配置文件所在位置,必须指定为/etc,改成其他位置则keepalived启动不了
安装keepalived
make && make install
将Keepalived注册为服务
当前情况下,我们需要进入到keepalived运行目录下才能启动keepalived,需要使用kill -9 停止keepalived,这样很不友好,下面介绍如何将Keepalived注册为服务。
进入Keepalived解压目录(不是安装目录)
拷贝,并覆盖目标目录下的文件
cp init.d/keepalived /etc/init.d/ cp sysconfig/keepalived /etc/sysconfig/
重新加载服务
systemctl daemon-reload
启动服务
systemctl start keepalived.service
停止服务
systemctl stop keepalived.service
重启服务
systemctl reststart keepalived.service