Keepalived安装
# centos 7
tar -xzvf keepalived-1.2.1.tar.gz
cd keepalived-1.2.1
./configure
make
make install
mkdir -p /etc/keepalived
cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
配置Keepalived
vi /etc/keepalived/keepalived.conf
##########################################
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
# 可设置多 vip
vrrp_instance VI_1 {
# VRRP 为主节点
state BACKUP # MASTER
# 绑定网卡
interface ens33
# VRRP 组名 节点须一致
virtual_router_id 51
# 权重
priority 50
# 组播信息发送间隔,节点须一致
advert_int 1
# 设置验证信息, 节点须一致
authentication {
auth_type PASS
auth_pass 1111
}
# 设置虚拟ip 节点须一致
virtual_ipaddress {
192.168.28.100
}
}
######################
# 配合负载均衡使用
# vip端口映射
virtual_server 192.168.28.100 80 {
delay_loop 6 #轮询次数
lb_algo rr #调度算法
lb_kind NAT#lvs 模式
persistence_timeout 50 # 会话保持时间
protocol TCP #协议类型
real_server 192.168.28.2 80 {
weight 1 # 权重
}
real_server 192.168.28.11 80{
weight 1 # 权重
TCP_CHECK {
connect_timeout 10 # 连接超时时间
nb_get_retry 3 # 重试次数
delay_before_retry 3 #重连间隔
connect_port 80 #检查端口
}
}
}
##################################
验证
# 防火墙放行 vrrp
firewall-cmd --direct --permanent --add-rule ipv4 filter INPUT 0 --protocol vrrp -j ACCEPT
firewall-cmd --reload
# 查看日志 默认
/var/log/messages
# 进行主从切换测试