跳转至

LVS UDP服务测试


2014-04-22 by dongnan

开始之前

此次测试的是两个常用的udp协议服务,dnsntp 其中:

  • dns服务使用udp/tcp 双协议 端口号53linux系统下dns软件为常用的bind-9
  • ntp服务使用 udp/tcp 双协议 端口号123linux系统下ntp软件为ntpd

环境

LVS 与 Keepalived 安装请参考以下文章:

基于LVS的DNS集群

DNS安装配置请参考这里

配置文档

配置DNS虚拟服务

cat /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
   router_id lvs-test
}

#
vrrp_sync_group VG1 {
    group {
        VI_1
    }
}

vrrp_instance VI_1 {
    state BACKUP
    nopreempt
    interface eth0
    track_interface {
        eth0
        eth1
    }

    virtual_router_id 45
    priority 150
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass dongnan
    }

    virtual_ipaddress {
        172.27.233.45/24 dev eth0 scope global
    }
}

# ipvs
virtual_server 172.27.233.45 53 {
    delay_loop 5
    lb_algo wrr 
    lb_kind DR
    #persistence_timeout 10
    protocol UDP

    real_server 172.27.233.43 53 {
    weight 1
    MISC_CHECK {
                  misc_path "/usr/bin/dig @172.27.233.43 zongming.net +time=1 > /dev/null && exit 0 || exit 1"
                  misc_timeout 6
                  nb_get_retry 3
                  delay_before_retry 3
               }
    }

    real_server 172.27.233.44 53 {
    weight 1
    MISC_CHECK {
                  misc_path "/usr/bin/dig @172.27.233.44 zongming.net +time=1 > /dev/null && exit 0 || exit 1"
                  misc_timeout 6
                  nb_get_retry 3
                  delay_before_retry 3
               }
    }
}

测试DNS

模拟客户端向VIP 172.27.233.45 请求10DNS解析:

for((i=1;i<=10;i++));do dig @172.27.233.45 zongming.net;done

LVS 状态:

ipvsadm -Ln --stats

IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port               Conns   InPkts  OutPkts  InBytes OutBytes
  -> RemoteAddress:Port
UDP  172.27.233.45:53                   10      10        0      580        0
  -> 172.27.233.43:53                    5        5        0      290        0
  -> 172.27.233.44:53                    5        5        0      290        0

其中一台服务器的DNS请求日志:

tail -f /usr/local/named/log/queries.log

03-Apr-2014 16:17:42.774 queries: info: client 172.27.233.130#53823 (zongming.net): query: zongming.net IN A + (172.27.233.45)
03-Apr-2014 16:17:42.849 queries: info: client 172.27.233.130#57952 (zongming.net): query: zongming.net IN A + (172.27.233.45)
03-Apr-2014 16:17:42.912 queries: info: client 172.27.233.130#56767 (zongming.net): query: zongming.net IN A + (172.27.233.45)
03-Apr-2014 16:17:43.009 queries: info: client 172.27.233.130#57767 (zongming.net): query: zongming.net IN A + (172.27.233.45)
03-Apr-2014 16:17:43.083 queries: info: client 172.27.233.130#50026 (zongming.net): query: zongming.net IN A + (172.27.233.45)

请求1W次DNS解析

客户端:

time for((i=1;i<=10000;i++)) ;do dig @172.27.233.45 zongming.net > /dev/null || echo "failed" ;done

real    0m40.437s
user    0m1.108s
sys    0m1.456s

LVS状态:

ipvsadm -Ln --stats

IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port               Conns   InPkts  OutPkts  InBytes OutBytes
  -> RemoteAddress:Port
UDP  172.27.233.45:53                 8408    10000        0   580000        0
  -> 172.27.233.43:53                 4204     5005        0   290290        0
  -> 172.27.233.44:53                 4204     4995        0   289710        0

基于LVS的NTP集群

NTP安装配置请参考这里

配置文档

配置NTP虚拟服务

cat /etc/keepalived/keepalived.conf

! Configuration File for keepalived
global_defs {
   router_id lvs-test
}

#
vrrp_sync_group VG1 {
    group {
        VI_1
    }
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    track_interface {
        eth0
        eth1
    }
    virtual_router_id 45
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass dongnan
    }
    virtual_ipaddress {
        172.27.233.45/24 dev eth0 scope global
    }
}

# ipvs
virtual_server 172.27.233.45 123 {
    delay_loop 5
    lb_algo wrr
    lb_kind DR
    #persistence_timeout 10
    protocol UDP

    real_server 172.27.233.43 123 {
    weight 1
    MISC_CHECK {
                  misc_path "/usr/sbin/ntpdate -t 0.2 172.27.233.43 > /dev/null && exit 0 || exit 1"
                  misc_timeout 3
                  nb_get_retry 3
                  delay_before_retry 3
               }
    }

    real_server 172.27.233.44 123 {
    weight 1
    MISC_CHECK {
                  misc_path "/usr/sbin/ntpdate -t 0.2 172.27.233.44 > /dev/null && exit 0 || exit 1"
                  misc_timeout 3
                  nb_get_retry 3
                  delay_before_retry 3
               }
    }

}

测试NTP

模拟客户端向VIP 172.27.233.45 发送10次同步时间请求:

for((i=1;i<=10;i++));do /usr/sbin/ntpdate -q -t 0.2 172.27.233.45 ;done

LVS 状态:

ipvsadm -Ln --stats

IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port               Conns   InPkts  OutPkts  InBytes OutBytes
  -> RemoteAddress:Port
UDP  172.27.233.45:123                 10       40        0     3040        0
  -> 172.27.233.43:123                  5       20        0     1520        0
  -> 172.27.233.44:123                  5       20        0     1520        0

ipvsadm -Lnc

IPVS connection entries
pro expire state       source             virtual            destination
UDP 03:02  UDP         172.27.233.46:123  172.27.233.45:123  172.27.233.44:123

欢迎关注微信公众号: 运维录

Back to top