# 安装依赖包
yum install -y curl gcc openssl-devel libnl3-devel net-snmp-devel
# 下载tar包
wget http://www.keepalived.org/software/keepalived-2.0.7.tar.gz
# 解压
tar xvf keepalived-2.0.7.tar.gz
cd keepalived-2.0.7
# 配置 生成安装文件
./configure --prefix=/usr/local/keepalived
make && make install
# keepalived 启动脚本变量引用文件,默认文件路径是 /etc/sysconfig/,也可以不做软链接,直接修改启动脚本中文件路径即可(安装目录下)
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/keepalived
# 将keepalived 主程序加入到环境变量(安装目录下)
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/keepalived
# keepalived 启动脚本(源码目录下),放到 /etc/init.d/ 目录下就可以使用 service 命令便捷调用
cp /usr/local/src/keepalived-2.0.7/keepalived/etc/init.d/keepalived /etc/init.d/keepalived
# 将配置文件放到默认路径下
[root@localhost /]# mkdir /etc/keepalived
[root@localhost /]# cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf
# 修改 /etc/keepalived/keepalived.conf
router_id 162.168.64.128 (主机IP)
vrrp_instance VI_1 {
state MASTER
interface ens33 (主机网卡)
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.64.120 (虚拟IP)
}
}
# 启动
systemctl start keepalived
# 查看进程
ps aux|grep keepalived
# 开机启动
systemctl enable keepalived
网友评论