配置环境
node1:192.168.1.72
node2:192.168.1.73
1、node1、node2配置主机名、同步时间、通过hosts文件解析各主机名
2、各节点安装keepalived
yum -y install keepalived
3、配置node1
[[email protected] ~]# cd /etc/keepalived/
[[email protected] keepalived]# cp keepalived.conf{,.bak}
[[email protected] keepalived]# vim keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id node1
vrrp_mcast_group4 224.18.0.100
}
vrrp_script chk_mantaince {
script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"
interval 1
weight -2
}
vrrp_instance VI_1 {
state MASTER
interface eno16777736
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 3b8fd970
}
virtual_ipaddress {
192.168.1.80/24
}
track_script {
chk_maintanance
}
}
4、配置node2
[[email protected] keepalived]# scp keepalived.conf node2:/etc/keepalived/
[[email protected] ~]# cd /etc/keepalived/
[[email protected] keepalived]# vim keepalived.conf
1、修改
router_id node1
为
router_id node2
2、修改
state MASTER
为
state BACKUP
3、修改
priority 100
为
priority 99
5、启动
[[email protected] keepalived]# systemctl start keepalived.service
[[email protected] keepalived]# systemctl start keepalived.service
6、添加日志储存文件
[[email protected] keepalived]# vim /etc/sysconfig/keepalived
修改
KEEPALIVED_OPTIONS="-D"
为
KEEPALIVED_OPTIONS="-D -S 3"
[[email protected] keepalived]# vim /etc/rsyslog.conf
添加一行
local3.* /var/log/keepalived.log
[[email protected] keepalived]# systemctl restart rsyslog.service
[[email protected] keepalived]# systemctl restart keepalived.service