keepalived 做全端口映射
global_defs {
lvs_id BACKUP
}
vrrp_sync_group VGM {
group {
VI_1
}
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 80
priority 50
advert_int 5
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.16.254.16
}
}
virtual_server 172.16.254.16 0 { //0代表映射所有端口
delay_loop 3
lb_algo wrr //定义负载均衡算法,这里是权重轮训
lb_kind DR //定义模式,这里是Direct route
persistence_timeout 50 //会话保存时长(秒),0表示不使用stickyness会话 (重要)
protocol TCP
// 后端服务器定义
real_server 172.16.2.10 0 { //0代表映射所有端口
weight 1 //权重
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
用一个例子来演示会更加清晰