请问用keepalived,LVS有人UDP例子走通过吗?请高手帮忙,救小弟于水深火热之中。

我是想用keepalived+LVS做STUN server负载均衡的,tcp类型的我已经走通了,用apache做real server测试服务的。我的配置如下:

global_defs {
router_id LVS_STUN_1
}

vrrp_instance VI_1 {
state MASTER
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 51
priority 200
advert_int 5
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.19.1.19
}
}

virtual_server 172.19.1.19 80 {
delay_loop 10
lb_algo wrr
lb_kind DR
# persistence_timeout 1
protocol TCP

real_server 172.19.1.15 80 {
weight 1
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
}
}
real_server 172.19.1.16 80 {
weight 1
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
}
}
}
virtual_server 172.19.1.19 34780 {
delay_loop 10
lb_algo wrr
lb_kind DR
persistence_timeout 10
protocol UDP

real_server 172.19.1.15 3478 {
weight 1
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
}
}
real_server 172.19.1.16 3478 {
weight 1
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
}
}
}

virtaul IP都是172.19.1.19,打ipvsadm后显示如下:

[root@loochaxx ~]# ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.19.1.19:http wrr
-> 172.19.1.16:http Route 1 0 0
-> 172.19.1.15:http Route 1 0 0
UDP 172.19.1.19:34780 wrr
-> 172.19.1.16:nat-stun-port Route 1 0 0
-> 172.19.1.15:nat-stun-port Route 1 0 0

2台机器做lvs的,ip分别为172.19.1.13(MASTER)和172.19.1.14(BACKUP),上面的配置是MASTER的配置。
我在172.19.1.13和172.19.1.14上都用tcpdump udp port 34780抓包:
当client往虚拟IP-172.19.1.19发请求的时候, 172.19.1.13和172.19.1.14中会有一台显示client断的数据来到:

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
17:07:56.191717 IP 121.237.175.30.websm > 172.19.1.19.34780: UDP, length 44
17:07:56.424117 IP 121.237.175.30.websm > 172.19.1.19.34780: UDP, length 44
17:07:57.015756 IP 121.237.175.30.xmltec-xmlmail > 172.19.1.19.34780: UDP, length 44
17:07:57.092420 IP 121.237.175.30.xmltec-xmlmail > 172.19.1.19.34780: UDP, length 44
17:07:57.217763 IP 121.237.175.30.xmltec-xmlmail > 172.19.1.19.34780: UDP, length 44
17:07:57.277189 IP 121.237.175.30.xmltec-xmlmail > 172.19.1.19.34780: UDP, length 44
17:07:57.505469 IP 121.237.175.30.6060 > 172.19.1.19.34780: UDP, length 44
17:07:57.531732 IP 121.237.175.30.6060 > 172.19.1.19.34780: UDP, length 44
17:07:57.773465 IP 121.237.175.30.6060 > 172.19.1.19.34780: UDP, length 44
17:07:58.073366 IP 121.237.175.30.6060 > 172.19.1.19.34780: UDP, length 44
17:07:58.288433 IP 121.237.175.30.6061 > 172.19.1.19.34780: UDP, length 44
17:07:58.337446 IP 121.237.175.30.6061 > 172.19.1.19.34780: UDP, length 44
17:07:58.415309 IP 121.237.175.30.6061 > 172.19.1.19.34780: UDP, length 44
17:07:58.911190 IP 121.237.175.30.6061 > 172.19.1.19.34780: UDP, length 44

但是我同样在2台real server上运行tcpdump udp port 3478,结果没有任何数据被抓到。
百思不得其解。

用tcp服务测试时,一切正常,抓包显示也正常。

Forums:

您好,能留个联系方式么,我也在用这个,但是没有整出来,想向您请教请教

udp的服务,realserver 是以自身ip向client返回数据包的,而不是以vip返回的,而client会丢弃非vip返回的数据。

Free knowledge like this doesn't just help, it promote demycraco. Thank you.

用keepalived misc 定义 脚本