各节点时间必须同步:
ntpdate TIME_SERVER_IP (如果没有ntpdate,安装ntp包,或者直接安装ntpdate包)
vim /etc/chrony.conf
server TIME_SERVER_IP iburst
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
systemctl restart chronyd
确保iptables及selinux不会成为阻碍。
各节点之间可通过主机名互相通信(对KA并非必须):建议使用/etc/hosts文件实现(DNS服务如果有问题,还不如hosts文件好用)
确保各节点的用于集群服务的接口支持MULTICAST通信:多播或叫组播,使用D类地址(224-239)。(多播地址最好不要使用默认的,手动修改一下。因为如果好多个集群服务都是用默认的,虽然有认证机制,但是也会互相发送信息,虽然因为认证机制丢弃掉了,但也影响性能,也会产生无用的日志。)
2、在ka1上
#vim keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost(提醒是发送邮件地址)
}
notification_email_from keepalived@localhost(邮件来源)
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id proxy1
vrrp_mcast_group4 224.1.1.1(组播地址与备用ka服务器相同)
}
vrrp_instance VI_1 {
state MASTER
interface eth1(提供服务的网卡名称)
virtual_router_id 66(与备用ka服务器的相同,即表明在同一网段)
priority 100(抢占虚拟IP的优先级)
advert_int 1
authentication {
auth_type PASS (认证方式:PASS为简单字符串密码,推荐使用;AH为IPSEC方式,不推荐使用)
auth_pass 123456
}
virtual_ipaddress {
172.18.0.200/16 (注意掩码,默认为32)
}
}3在ka2上
#vim keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id proxy2 (不能与主ka相同)
vrrp_mcast_group4 224.1.1.1
}
vrrp_instance VI_1 {
state BACKUP (备用模式)
interface eth1
virtual_router_id 66
priority 80 (抢占IP优先级)
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
172.18.0.200/16
}
}启用ka的日志
vim /etc/sysconfig/keepalived
KEEPALIVED_OPTIONS="-D -S 3"
vim /etc/rsyslog.conf
local3.* /var/log/keepalived.log
原文:http://blog.51cto.com/13520924/2094170