因業務需求,需要把lvs備機也使用上,故! 使用雙主,相互是主的同時也相互是備機。本人用nat測試發現RS無法實現負載均衡,故採用DR模式來實現非web端的負載均衡 lvs1: DIP 10.60.196.183 VIP 10.60.196.185 lvs2:DIP 10.60.196.184 VI ...
因業務需求,需要把lvs備機也使用上,故! 使用雙主,相互是主的同時也相互是備機。本人用nat測試發現RS無法實現負載均衡,故採用DR模式來實現非web端的負載均衡
lvs1: DIP 10.60.196.183
VIP 10.60.196.185
lvs2:DIP 10.60.196.184
VIP 10.60.196.186
DR1:10.60.196.181
DR2:10.60.196.182
--------------------------------------------------------
我這裡TCP和UDP同時使用
LVS:需要開啟IP轉發
vim /etc/sysctl.conf
keepalive配置:
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from admin@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP #另外一臺keepalive這裡換成MASTER
interface eth0
virtual_router_id 51
priority 98 #這裡100
advert_int 1
authentication {
auth_type PASS
auth_pass 11112222
}
virtual_ipaddress {
10.60.196.186/32 label eth0:0
}
}
vrrp_instance VI_2 {
state MASTER #另一臺BUCKUP
interface eth0
virtual_router_id 150
priority 100 # 這裡99
advert_int 1
authentication {
auth_type PASS
auth_pass 11112222
}
virtual_ipaddress {
10.60.196.185/32 label eth0:1
}
}
virtual_server 10.60.196.186 33001 {
delay_loop 6
lb_algo rr
lb_kind DR
protocol TCP
persistence_timeout 0
real_server 10.60.196.181 33001 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 10.60.196.182 33001 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
virtual_server 10.60.196.186 33001 {
delay_loop 6
lb_algo rr
lb_kind DR
protocol UDP
persistence_timeout 0
real_server 10.60.196.181 33001 {
weight 1
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
real_server 10.60.196.182 33001 {
weight 1
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
virtual_server 10.60.196.185 33001 {
delay_loop 6
lb_algo rr
lb_kind DR
protocol TCP
persistence_timeout 0
real_server 10.60.196.181 33001 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 10.60.196.182 33001 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
virtual_server 10.60.196.185 33001 {
delay_loop 6
lb_algo rr
lb_kind DR
protocol UDP
persistence_timeout 0
real_server 10.60.196.181 33001 {
weight 1
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
real_server 10.60.196.182 33001 {
weight 1
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
配置好以後添加路由
route add -host 10.60.196.185 dev eth0:1
route add -host 10.60.196.186 dev eth0:0
rs:需要添加路由同時綁定VIP
RS1和RS2配置相同
ifconfig eth0:0 10.60.196.186 netmask 255.255.255.0
ifconfig eth0:1 10.60.196.185 netmask 255.255.255.0
route add -host 10.60.196.185 dev eth0:1
route add -host 10.60.196.186 dev eth0:0
如果還需要外網可以通過另外搭建搭建兩台機器做iptables轉發 上面需要有一個公網IP和一個內網IP,通過iptables把外網請求全部轉發到VIP上面,一臺做一個VIP轉發 (iptables這裡就不寫了),這樣就可以實現跨網段的通訊了! 不同網段原因一樣