在公司推进使用域名过程中,需要搭建一套 dns 系统。说到要搭建一套新系统,那么肯定要对该系统的性能进行测试。在综合考虑 dns 性能测试工具之后,选择使用 dnsperf。

什么是 dnsperf

  dnsperf 是 DNS-OARC 开发的一款免费的,DNS 性能测试工具。官方网站是 https://www.dns-oarc.net/tools/dnsperf。

dnsperf 的安装

  dnsperf 支持源码安装和使用预编译包安装。目前使用较多的系统是 CentOS 7,这里一个 CentOS 7 作为实例。

Yum 安装

  dnsperf 已经放置在了 epel 源中,但是最近版本是 2.7.1。而官方最新版本是 2.9.0。版本 2.7.1 已经满足日常需要了。针对最新版强迫爱好者,这里也提供最新版的安装方式。最近版 dnsperf 官方基于 copr 制作的 rpm 安装包,此时 yum 需要添加 copr 源。

epel 源

  使用 epel 源安装 dnsperf 需要先添加 epel 源(如果没有)。

1
2
[root@performance-tools ~]# yum -y install epel-release
[root@performance-tools ~]# yum -y install dnsperf
copr 源

  使用 copr 源需要下载对应的 repo 文件。

1
2
[root@performance-tools ~]# wget https://copr.fedorainfracloud.org/coprs/g/dnsoarc/dnsperf/repo/epel-7/group_dnsoarc-dnsperf-epel-7.repo
[root@performance-tools ~]# yum -y install dnsperf

源码安装

  dnsperf 还支持使用源码来安装。  dnsperf 源码托管 github,仓库地址 https://github.com/DNS-OARC/dnsperf。当然也可以从官网下载。

  这里以安装版本 2.9.0 为例进行演示安装。

下载安装包
1
[root@performance-tools ~]# wget https://github.com/DNS-OARC/dnsperf/archive/refs/tags/v2.9.0.tar.gz
安装依赖和编译环境

  dnsperf 依赖于 OpenSSL、 Concurrency Kit、LDNS、nghttp2。所以编译安装要提前安装相关依赖。请注意,ck-devel,libnghttp2-devel需要使用epel源

1
[root@performance-tools ~]# yum install -y openssl-devel ldns-devel ck-devel libnghttp2-devel gcc autoconf automake make check libtool
解压安装
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@performance-tools ~]# tar -zxvf v2.9.0.tar.gz
[root@performance-tools ~]# cd dnsperf-2.9.0
[root@performance-tools dnsperf-2.9.0]# ./autogen.sh
configure.ac:27: installing './compile'
configure.ac:28: installing './config.guess'
configure.ac:28: installing './config.sub'
configure.ac:20: installing './install-sh'
configure.ac:20: installing './missing'
src/Makefile.am: installing './depcomp'
parallel-tests: installing './test-driver'
[root@performance-tools dnsperf-2.9.0]# ./configure --prefix=/opt/dnsperf-2.9.0
[root@performance-tools dnsperf-2.9.0]# make && make install
[root@performance-tools dnsperf-2.9.0]# cd /opt/dnsperf-2.9.0
[root@performance-tools dnsperf-2.9.0]# ll
total 0
drwxr-xr-x. 2 root root 58 Dec 28 17:49 bin
drwxr-xr-x. 4 root root 28 Dec 28 17:49 share
[root@performance-tools dnsperf-2.9.0]# cd bin
total 728
-rwxr-xr-x. 1 root root 378552 Dec 28 17:49 dnsperf
-rwxr-xr-x. 1 root root 359720 Dec 28 17:49 resperf
-rwxr-xr-x. 1 root root 2624 Dec 28 17:49 resperf-report
添加环境变量

  添加dnsperf环境变量,以便于直接使用dnsperf命令。

1
2
3
4
[root@performance-tools dnsperf-2.9.0]# cat >> /etc/profile << EOF
export PATH=\${PATH}:/opt/dnsperf-2.9.0/bin
EOF
[root@performance-tools dnsperf-2.9.0]# source /etc/profile

dnsperf的简单使用

  在Linux下任何一个命令,想了解其使用方法,最简单的办法就是使用 –help 来查阅相关说明了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
[root@performance-tools ~]# dnsperf --help
DNS Performance Testing Tool
Version 2.9.0

dnsperf: invalid option -- '-'
Usage: dnsperf [-f family] [-m mode] [-s server_addr] [-p port]
[-a local_addr] [-x local_port] [-d datafile] [-c clients]
[-T threads] [-n maxruns] [-l timelimit] [-b buffer_size]
[-t timeout] [-e] [-E code:value] [-D]
[-y [alg:]name:secret] [-q num_queries] [-Q max_qps]
[-S stats_interval] [-u] [-v] [-W] [-h] [-H] [-O]
-f address family of DNS transport, inet or inet6 (default: any)
-m set transport mode: udp, tcp, dot or doh (default: udp)
-s the server to query (default: 127.0.0.1)
-p the port on which to query the server (default: udp/tcp 53, DoT 853 or DoH 443)
-a the local address from which to send queries
-x the local port from which to send queries (default: 0)
-d the input data file (default: stdin)
-c the number of clients to act as
-T the number of threads to run
-n run through input at most N times
-l run for at most this many seconds
-b socket send/receive buffer size in kilobytes
-t the timeout for query completion in seconds (default: 5)
-e enable EDNS 0
-E send EDNS option
-D set the DNSSEC OK bit (implies EDNS)
-y the TSIG algorithm, name and secret (base64)
-q the maximum number of queries outstanding (default: 100)
-Q limit the number of queries per second
-S print qps statistics every N seconds
-u send dynamic updates instead of queries
-v verbose: report each query and additional information to stdout
-W log warnings and errors to stdout instead of stderr
-h print this help
-H print long options help
-O set long options: <name>=<value>

  这里对自己使用过的参数做个简单的介绍

-d:存有测试的域名及其类型的文件实例如下。

1
2
3
4
5
6
7
8
9
191.zxzmcode.cn A
192.zxzmcode.cn A
193.zxzmcode.cn A
194.zxzmcode.cn A
195.zxzmcode.cn A
196.zxzmcode.cn A
197.zxzmcode.cn A
198.zxzmcode.cn A
199.zxzmcode.cn A

-s:dns服务器的IP地址,缺省时,默认为 127.0.0.1
-p:dns服务的端口,缺省时默认为 UDP 协议的53端口。
-l:测试时间,单位为秒
-c:执行查询的客户端个数。
-T:测试的线程数。

  相关具体使用,请查阅本人文章中的dns系列。

备注

  在上面源码安装dnsperf的情况下,在/opt/dnsperf-2.9.0/bin路径下除了dnsperf命令还有两条命令,为resperf,resperf-report。

  resperf也是dnsperf官方的一个工具之一,官方解释是系统提高dns查询率并监控线相应效率的工具。具体没有使用过,这里也不说了。