1.下载(版本:2.0.6)
cd /home/install/
wget http://124.205.69.170/files/1255000006EF2AA1/www.keepalived.org/software/keepalived-2.0.6.tar.gz
2.解压
tar -zxvf keepalived-2.0.6.tar.gz -C /usr/local/
3.编译安装
1)进入安装目录
cd /usr/local/keepalived-2.0.6/
2)安装
./configure --prefix=/usr/local/keepalived
如果提示 *** WARNING - this build will not support IPVS with IPv6. Please install libnl/libnl-3 dev libraries to support IPv6 with IPVS.
yum -y install libnl libnl-devel
如果提示 configure: error: libnfnetlink headers missing
yum install -y libnfnetlink-devel
再执行 ./configure --prefix=/usr/local/keepalived
无错误提示进行下步
make && make install
查看是否安装成功
4.配置开机启动服务
mkdir /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf#keepalived默认执行/etc/keepalived/keepalived.conf
cp /usr/local/keepalived-2.0.6/keepalived/etc/init.d/keepalived /etc/rc.d/init.d/keepalived
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/keepalived
cd /usr/lib/systemd/system/#编译安装成功后,会自动在该路径下生成keepalived.service文件
启动
systemctl start keepalived
状态(dead不要慌,下面的keepalived.conf配置正确就好了)
systemctl status keepalived
停止
systemctl stop keepalived
重启
systemctl restart keepalived
开机启动
systemctl enable keepalived.service
查看是否开机启动
systemctl is-enabled keepalived.service
5.虚拟IP测试
vim /etc/keepalived/keepalived.conf
谨记:该配置慎用空格,可以使用TAB或回车排版,空格会被识别为赋值,导致keepalived运行失败
替换为如下内容
! Configuration File for keepalived
vrrp_instance VI_1 {
state MASTER#两个值(主:MASTER 备:BACKUP),必须大写
interface ens33#网卡接口,ip a查看,上面主备搭建教程有讲
virtual_router_id 51#虚拟路由ID,主备或多主多备,需要全部设置一样
priority 101#优先级,越高越优先使用该服务
advert_int 1#多个keepalived的通讯检测间隔,单位秒
authentication {#认证类型与密码,主备或多主多备需要设置一样
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.159.110#定义虚拟IP,换行可以定义多个
}
}
重启keepalived、查看IP
systemctl restart keepalived
ip add