技术
成就梦想!

使用Ansible与iperf3进行服务器批量打流测试

通过Ansible自动化工具结合iperf3打流工具,实现对大量服务器进行自动的打流测试,这样可以快速定位出网络瓶颈与故障。

一、安装iperf3

#将iperf3安装包拷贝到所有服务器/tmp/目录
ansible any_host -m copy -a "src=/tmp/iperf3-3.1.3-1.fc24.x86_64.rpm dest=/tmp/iperf3-3.1.3-1.fc24.x86_64.rpm"
#给服务器安装iperf3
ansible any_host -m shell -a "rpm -ivh /tmp/iperf3-3.1.3-1.fc24.x86_64.rpm"

二、修改Ansible配置文件

1、配置ansible配置文件

vim /etc/ansible/ansible.cfg
#取消注释,并配置forks为1,是指并行执行命令数量为1台;
forks          = 1
#取消注释"host_key_checking = False",开启密钥保存
host_key_checking = False

2、配置打流服务器登录信息

#添加要打流的服务器ip、用户、密码 (Client)
vim /etc/ansible/hosts
[any_host]
10.195.154.[1:72] ansible_ssh_user=[用户] ansible_ssh_pass=[密码]
10.195.152.[1:72] ansible_ssh_user=root ansible_ssh_pass=admin000...

1
2
3

三、开始配置打流

1、找一台服务器作为打流的服务端执行命令开启服务

iperf3 -s

2、配置打流执行脚本(如果只做单向打流该项可不配置),打流-t是时间根据整体打流时间去修改。

cat << EOF > /tmp/dl_iperf3.sh
#!/bin/bash
#双向打流脚本
#连接测速,默认测的是从客户端到服务端的带宽(服务器接收,客户端发送),使用8个线程测试。
ansible any_host -m shell -a "iperf3 -t 30 -P 8 -c [服务器地址]"
#反向打流设置服务器发送,客户端接收
ansible any_host -m shell -a "iperf3 -R -t 30 -P 8 -c [服务器地址]"
EOF

3、开始打流

为了防止命令被打断,可以使用screen或crontab进行执行。
sh /tmp/dl_iperf3.sh >> /tmp/dl_iperf3.log
#可通过/tmp/dl_iperf3.log查看进度;

 

参考资料:

ansible离线安装:https://www.xxshell.com/2683.html

iperf3使用教程:https://www.xxshell.com/2664.html

 

赞(7)
未经允许不得转载:未来往事 » 使用Ansible与iperf3进行服务器批量打流测试

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址