先安装各种包
将keepalived-2.0.10.tar.gz上传到服务器/usr/local/下。
[root@localhost ~]# yum install -y curl gcc openssl-devel libnl3-devel net-snmp-devel
yum install -y keepalived
注意必须安装此依赖包,否则会出现 error code错误
cd /usr/local
tar -zxvf keepalived-2.0.10.tar.gz
cd keepalived-2.0.10
#执行配置命令
./configure --prefix=/usr/local/keepalived
#编译
make
#安装
make install
gcc openssl-devel libnl3-devel net-snmp-devel libnfnetlink-devel -y
interface ens33 表示当前使用的网卡,通过ifconfig可以查看到,这我用的是ens33。
virtual_router_id 100 这个是个分组标记,在一个网内,所有的virtual_router_id为100的服务器自动分到一个组里面,由于这里面我把两台服务器的status都设置成为了BACKUP,那么这两台服务器就会利用priority这个值来决定谁是主服务器,谁是备用服务器,高的那个会抢占当前的vip,也就是它就会变成主服务器。
Keepalived.conf 所在目录
root@localhost keepalived]# pwd
/usr/local/keepalived/etc/keepalived
配置systemctl 和 keepalived 服务相关命令
重新加载
systemctl daemon-reload
设置开机自动启动
systemctl enable keepalived.service
取消开机自动启动
systemctl disable keepalived.service
启动
systemctl start keepalived.service
停止
systemctl stop keepalived.service
用压缩包安装的keepalived会自带keepalived.conf 最好是使用yum安装,默认配置文件:/etc/keepalived/keepalived.conf
Keepalived启动不成功 inactive
使用ps -ef | grep keepalived查询进程 kill -9 pid杀死,再重启