queryperf进行DNS拨测

背景:为了实现”某些域名“在”某个DNS“上的访问次数的增加。

使用Bind压力测试软件queryperf +shell脚本实现拨测的自动化


1.下载queryperf.

# wget http://ftp.isc.org/isc/bind9/9.7.3/bind-9.7.3.tar.gz
        # tar zxvf bind-9.7.3.tar.gz
        # cd bind-9.7.3/contrib/queryperf/

2.安装queryperf.

        看一下README 说的很想详细。
        # ./configure
        # make
        编译完之后会生成queryperf 文件。
         使用方法:
               # queryperf -d input_file -s server

        input_file:压力测试的时候读取的文件,
          格式: www.turku.fi A
                 www.helsinki.fi A
        server:要测试dns服务器的IP。

3.脚本内容.

3.1压力测试文件名称leo.txt.格式如下:

sdklog.cmgame.com A
urlsafe.baidu.com A
timg.baidu.com A
conf.wcd.qq.com A
mt1.baidu.com A

3.2拨测脚本名称que.sh,脚本内容如下:

#!/bin/bash
for j in {1..5}
do 
ps -ef |grep  queryperf  |awk '{print $2}' |xargs kill  -9
done

for i in {1..100}
do
tmp1=`/usr/bin/queryperf -d leo.txt -s 1.1.1.1 -q 15 -l 1 |grep "Queries completed:" |awk '{print $3}'`
echo `date +%m%d_%H%M`  $tmp1>>tmp.txt
tmp2=`/usr/bin/queryperf -d leo.txt -s 1.1.1.1 -q 15 -l 1 |grep "Queries completed:" |awk '{print $3}'`
echo `date +%m%d_%H%M`  $tmp2>>tmp.txt
sleep 1
done

说明:防止进程跑死太多,在每次循环结束的时候把之前的进程杀死。

/usr/bin/queryperf -d leo.txt -s 211.138.106.2 -q 15 -l 1 |grep "Queries completed:" |awk '{print $3}'

/usr/bin/queryperf  queryperf安装成功后的路径

-d leo.txt   拨测使用的文件

-s 1.1.1.1  拨测使用的DNS

-q 15 请求的并发数,默认是20

-l 1 限定在多少秒内完成一次测试

3.3启动拨测脚本以及守护程序脚本

#!/bin/bash
echo '*/5 * * * * /bin/bash  /root/que.sh > /dev/null 2>&1' >> /var/spool/cron/root;/etc/init.d/crond restart
nohup /bin/bash  /root/tt.sh &

说明:添加计划任务,每5分钟执行一次que.sh。这个时间是根据平均que.sh运行一次需要的时间而定的。由于DNS的性能不同,que.sh执行一次所需要的时间不同。

tt.sh是守护程序脚本,后台运行,内容如下:

#!/bin/bash
dat=`date +%m%d`
file=/var/spool/cron/root
while true;do
num=`awk -v d="$dat"  '$1~d{a[$d] += $2}END{for (i in a){print a[i]/10000 }}' tmp.txt`
if [[ $num -gt  180000 ]]    #拨测的请求次数单位万次
then
sed -i '/que.sh/{s/^/#/}' $file;/etc/init.d/crond restart
break;
fi
done

说明:守护脚本的任务是检测拨测的次数,一旦到达预设的次数,该脚本会将计划任务重每5分钟执行一次的*/5 * * * * /bin/bash  /root/que.sh > /dev/null 2>&1注视并重新启动计划任务,使之生效。实现程序的自我停止。

3.4所有脚本执行的导火索:

0 0 * * 5 /bin/bash  /root/hehe.sh > /dev/null 2>&1

上边的计划任务说明,每周5的0点0分开始执行hehe.sh脚本。脚本在达到自己预设的拨测次数后自动关闭。

4.附上queryperf的使用方法:

 -d specifies the input data file (default: stdin)       输入文件,默认手动输入到控制台
  -s sets the server to query (default: 127.0.0.1)        指定拨测的DNS地址,默认127.0.0.1
  -p sets the port on which to query the server (default: 53)     指定拨测的端口,默认53
  -q specifies the maximum number of queries outstanding (default: 20)        指定并发数,默认20
  -t specifies the timeout for query completion in seconds (default: 5)      指定query的超时时间(单位:秒)默认5s
  -n causes configuration changes to be ignored         忽略请求过程中的配置改变
  -l specifies how a limit for how long to run tests in seconds (no default)       指定多久进行一次测试(单位:秒)       
  -1 run through input only once (default: multiple iff limit given)        读取输入文件仅一次
  -b set input/output buffer size in kilobytes (default: 32 k)         设置输入输出的缓冲大小,默认32k
  -i specifies interval of intermediate outputs in seconds (default: 0=none)      指定每次测试的时间间隔(单位:秒),默认0
  -f specify address family of DNS transport, inet or inet6 (default: any)    制定地址家族、DNS,inet,或者inet6.默认任何形式
  -r set RTT statistics array size (default: 50000)        设置RTT静态数组大小,默认50000
  -u set RTT statistics time unit in usec (default: 100)    设置 RTT静态时间单元(单位:微妙),默认100us
  -H specifies RTT histogram data file (default: none)    指定RTT数据文件
  -T specify the target qps (default: 0=unspecified) 制定目标qps,默认0
  -e enable EDNS 0 开启EDNS
  -D set the DNSSEC OK bit (implies EDNS)      
  -R disable recursion                 禁用递归模式
  -c print the number of packets with each rcode    为每个记录打印包的数量
  -v verbose: report the RCODE of each response on stdout     在终端上输出每个响应的结果
  -h print this usage        



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值