Centos7限速和测速_centos7 wondershaper

128 阅读5分钟

取消限速:

[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

监控网络流量-2

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

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

1、安装

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

[java]  view plain  copy

  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 //什么都没干

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

从其官网(www.ex-parrot.com/pdw/iftop/d…)上,选择一个最新版本(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 www.ex-parrot.com/pdw/iftop/d…
  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--  www.ex-parrot.com/pdw/iftop/d…
  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 dl.fedoraproject.org/pub/epel/ep…

        yum install -y iftop

2、命令说明

[plain]  view plain  copy

  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、界面说明

界面上面显示的是类似刻度尺的刻度范围,为显示流量图形的长条作标尺用的。

前面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 的平均流量;

界面显示时的交互命令:

[plain]  view plain  copy

  1. 主机显示:
  2. n - DNS主机解析的开关
  3. s - 源(Source)主机显示的开关
  4. d - 目标(Dest)主机显示的开关
  5. t - 循环切换行显示模式
  6. 端口显示:
  7. N - toggle service resolution