Centos7限速和测速

时间:2022-05-10 05:40:15

限速

wondershaper是国外人开发的一款在Linux内核下基于TC工具的对整块网卡的限度工具。

第一种安装方法

首先下载wondershaper的rpm安装包:wondershaper-1.1a-7.noarch.rpm

安装wondershaper:

[root@localhost ~]# rpm -ivh wondershaper-1.1a-7.noarch.rpm

第二种安装方法

由于Centos7第三方库内才有这个软件,先安装第三方库

yum install epel-release -y
yum install wondershaper -y

限速命令:

第一个参数为网卡接口名,后面两个数字分别代表上行和下行的速度(单位Kb)

[root@localhost ~]# wondershaper eth0 5000 500

取消限速:

[root@localhost ~]# wondershaper clear eth0

测速

此程序是基于Python开发的脚本程序,利用了speedtest.net的服务来测量出上下行的宽带。Speedtest-cli能根据机房离测速服务器的物理距离来列出测速服务器,或者针对某一服务器进行测速,同时还能为你生成一个URL以便你分享你的测速结果。要在Linux上安装最新版本的speedtest-cli,你必须安装2.4-3.4或者更高版本的Python。

安装:

[root@localhost ~]# wget https://github.com/sivel/speedtest-cli/archive/master.zip

[root@localhost ~]# unzip master.zip

[root@localhost ~]# python speedtest.py (--bytes,以字节计算)

[root@localhost ~]# python speedtest.py --sahre 下载由你的宽带测试结果生成的图片

监控网络流量-1

安装:

[root@localhost ~]# yum install -y slurm
使用:
[root@localhost ~]# slurm -i wlan0

Centos7限速和测速

监控网络流量-2

在类Unix系统中可以使用top查看系统资源,进程,内存占用等信息。查看网络状态可以使用netstat、nmap等工具。

若要查看实时的网络流量,监控TCP/IP连接,反向解析IP,显示端口信息等,则可以使用iftop。

1、安装

由于使用yum install命令,无法进行直接安装。

  1. # yum install iftop //用命令直接安装
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. * base: mirrors.skyshe.cn
  5. * extras: centos.ustc.edu.cn
  6. * updates: mirrors.skyshe.cn
  7. Setting up Install Process
  8. No package iftop available. //没有可用的安装包
  9. Error: Nothing to do //什么都没干

那么,就必须使用第二种安装方式,即下载,解压,配置,并编译安装。

从其官网(http://www.ex-parrot.com/pdw/iftop/download/)上,选择一个最新版本(iftop-1.0pre4.tar.gz)

  1. 1,
  2. [root@localhost nginx]# yum install flex byacc  libpcap ncurses ncurses-devel libpcap-devel
  3. Loaded plugins: fastestmirror
  4. Loading mirror speeds from cached hostfile
  5. * base: centos.ustc.edu.cn
  6. * extras: centos.ustc.edu.cn
  7. * updates: mirrors.163.com
  8. Package ncurses-5.9-13.20130511.el7.x86_64 already installed and latest version
  9. Resolving Dependencies
  10. --> Running transaction check
  11. ---> Package byacc.x86_64 0:1.9.20130304-3.el7 will be installed
  12. ---> Package flex.x86_64 0:2.5.37-
  13. 2,
  14. [root@localhost soft]# wget wget http://www.ex-parrot.com/pdw/iftop/download/iftop-0.17.tar.gz
  15. --2015-06-09 17:30:41--  http://wget/
  16. Resolving wget (wget)... failed: Name or service not known.
  17. wget: unable to resolve host address ‘wget’
  18. --2015-06-09 17:30:43--  http://www.ex-parrot.com/pdw/iftop/download/iftop-0.17.tar.gz
  19. Resolving www.ex-parrot.com (www.ex-parrot.com)... 93.93.130.44
  20. Connecting to www.ex-parrot.com (www.ex-parrot.com)|93.93.130.44|:80... connected.
  21. HTTP request sent, awaiting response... 200 OK
  22. Length: 160381 (157K) [application/gzip]
  23. Saving to: ‘iftop-0.17.tar.gz’
  24. 100%[=========================================================================================================================================>] 160,381     97.3KB/s   in 1.6s
  25. 2015-06-09 17:30:47 (97.3 KB/s) - ‘iftop-0.17.tar.gz’ saved [160381/160381]
  26. 3,
  27. [root@localhost soft]# tar -zxvf iftop-0.17.tar.gz
  28. iftop-0.17/
  29. iftop-0.17/aclocal.m4
  30. iftop-0.17/addr_hash.c
  31. iftop-0.17/addr_hash.h
  32. iftop-0.17/addrs_dlpi.c
  33. iftop-0.17/addrs_ioctl.c
  34. iftop-0.17/AUTHORS
  35. iftop-0.17/bootstrap
  36. iftop-0.17/cfgfile.c
  37. 4,
  38. [root@localhost iftop-0.17]# ./configure
  39. checking build system type... x86_64-unknown-linux-gnu
  40. checking host system type... x86_64-unknown-linux-gnu
  41. checking target system type... x86_64-unknown-linux-gnu
  42. checking for a BSD-compatible install... /usr/bin/install -c
  43. checking whether build environment is sane... yes
  44. checking for gawk... gawk
  45. checking whether make sets ${MAKE}... yes
  46. checking for gcc... gcc
  47. checking for C compiler default output... a.out
  48. checking whether the C compiler works... yes
  49. 6,
  50. [root@localhost iftop-0.17]# make && make install
  51. make  all-recursive
  52. make[1]: Entering directory `/root/soft/iftop-0.17'
  53. Making all in config
  54. make[2]: Entering directory `/root/soft/iftop-

我们使用服务器环境是centos7,centos下通常使用iftop,或者nethogs来进行网络流量监控。这2个工具都需要先安装epel,因为这个库通常操作系统是不自带的。
    那么就先安装epel,使用的命令是:

   rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

yum install -y iftop

2、命令说明

  1. 语法: iftop -h | [-npblNBP] [-i interface] [-f filter code] [-F net/mask] [-G net6/mask6]
  2. -h                  显示本帮助(Help)信息
  3. -n                  不进行主机名(hostName)查找
  4. -N                  不将端口号(port Number)转换成对应的服务 to services
  5. -p                  混合(Promiscuous)模式(显示网络相关的其他主机信息)
  6. -b                  不显示流量图形条(Bar)
  7. -B                  以字节(Byte)为单位,显示带宽(Bandwidth);默认以比特(bit)显示的
  8. -i interface        监控的网卡接口(interface)
  9. -f filter code      包统计时,使用过滤码;默认:无,只统计IP包
  10. -F net/mask         显示特定IPv4网段的进出流量(Flow);如# iftop -F 10.10.1.0/24
  11. -G net6/mask6       显示特定IPv6网段的进出流量(Flow)
  12. -l                  显示并统计IPv6本地(Local)链接的流量(默认:关)
  13. -P                  显示端口(Port)
  14. -m limit            设置显示界面上侧的带宽刻度(liMit)
  15. -c config file      指定配置(Config)文件
  16. -t                  使用不带窗口菜单的文本(text)接口
  17. 排序:
  18. -o 2s                Sort by first column (2s traffic average)
  19. -o 10s               Sort by second column (10s traffic average) [default]
  20. -o 40s               Sort by third column (40s traffic average)
  21. -o source            Sort by source address
  22. -o destination       Sort by destination address
  23. The following options are only available in combination with -t
  24. -s num              print one single text output afer num seconds, then quit
  25. -L num              number of lines to print

3、界面说明

Centos7限速和测速
界面上面显示的是类似刻度尺的刻度范围,为显示流量图形的长条作标尺用的。
前面IP是本机的(Source),后面IP远程主机的(Dest);
中间的<= =>这两个左右箭头,表示的是流量的方向。
右侧的三列数值:
第一列是:在此次刷新之前2s或10s或40s的平均流量(按B设置秒数); 
第二列是:在此次刷新之前10秒钟的总流量的一半; 
第三列是:在此次刷新之前40秒钟的总流量的1/5;
TX:发送(Transmit)流量;RX:接收(Receive)流量;TOTAL:总流量;
cum:运行iftop到目前时间的总和(Cum);peak:流量峰(Peak)值;
rates:分别表示过去 2s 10s 40s 的平均流量;

界面显示时的交互命令:

  1. 主机显示:
  2. n - DNS主机解析的开关
  3. s - 源(Source)主机显示的开关
  4. d - 目标(Dest)主机显示的开关
  5. t - 循环切换行显示模式
  6. 端口显示:
  7. N - toggle service resolution
  8. S - toggle show source port
  9. D - toggle show destination port
  10. p - toggle port display
  11. 排序:
  12. 1/2/3 - sort by 1st/2nd/3rd column
  13. < - sort by source name
  14. > - sort by dest name
  15. o - freeze current order
  16. 普通:
  17. P - 暂停(Pause)显示
  18. h - 本帮助(Help)的显示或隐藏
  19. b - 图形条(Bar)的显示或隐藏
  20. B - cycle bar graph average
  21. T - toggle cumulative line totals
  22. j/k - scroll display
  23. f - edit filter code
  24. l - set screen filter
  25. L - lin/log scales
  26. ! - shell command
  27. q - quit

linux内网服务器之间测速(iperf3)

下载rpm
[root@xiexianbin-cn ~]# rpm -ivh iperf3-3.1.3-1.fc24.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:iperf3-3.1.3-1.fc24 ################################# [100%]
[root@xiexianbin-cn ~]# 服务器端:
[root@xiexianbin-cn ~]# iperf3 -s 客户端:
[root@xiexianbin-cn ~]# iperf3 -c 192.168.8.80

解释: 默认情况客户端使用TCP协议

  • -s:指明是服务器端
  • -c: 指明是客户端
  • 192.168.8.80: 为服务端IP地址
  • -u:指定是udp报文
  • -b:指定发送带宽大小。
  • -p:指定端口
  • iperf3 –h 查看所有参数含义: