前言
操作系统: Linux
操作环境: Centos7 / ubuntu
linux查看服务器带宽具体方法
一、使用speedtest-cli命令查看下载和上传最大流量值
因为命令是python的,所以需要先下载一个python,用pip下载次命令;
1 2 3 | yum -y install python-pip 或 apt install python-pip #等待下载完 pip install speedtest-cli |

1 2 3 4 5 6 7 8 9 10 | root@cs:[/root]: speedtest-cli Retrieving speedtest.net configuration... Testing from China Unicom (125.119.20.3)... Retrieving speedtest.net server list... Selecting best server based on ping... Hosted by China Telecom TianJin-5G (TianJin) [123.83 km]: 47.213 ms Testing download speed................................................................................ Download: 16.36 Mbit/s Testing upload speed................................................................................................ Upload: 18.58 Mbit/s |
二、查看网卡、网络的详情
1.查看服务器网络端口
1 | ifconfig |

2.ethtool命令查看宽带大小
1 | ethtool 网卡名称 |
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 | [root@222 ~]# ethtool eno1 Settings foreno1: Supported ports: [ TP ] Supported link modes: 10baseT/Half10baseT/Full 100baseT/Half100baseT/Full 1000baseT/Full Supported pause frame use: No Supports auto-negotiation: Yes Supported FEC modes: Not reported Advertised link modes: 10baseT/Half10baseT/Full 100baseT/Half100baseT/Full 1000baseT/Full Advertised pause frame use: No Advertised auto-negotiation: Yes Advertised FEC modes: Not reported Speed: 100Mb/s Duplex: Full Port: Twisted Pair PHYAD: 1 Transceiver: internal Auto-negotiation: on MDI-X: off (auto) Supports Wake-on: pumbg Wake-on: g Current message level: 0x00000007 (7) drv probe link Link detected: yes |
Speed: 100Mb/s 带宽为白兆
三、nload命令实时统计网卡带宽使用率
没有nload命令的需要下载;
1 2 3 4 | yum -y installnload #等待下载完 #直接使用命令查看 nload |

1 | #指定网卡进入nload eno1 |

Incoming是进入网卡的流量,Outgoing是从这块网卡出去的流量,每一部分都有下面几个。
Curr:当前流量
Avg:平均流量
Min:最小流量
Max:最大流量
Ttl:总流量
四、dstat -n命令实时监测网络的状态
1 | dstat -n |

LINUX服务器出网带宽 一直被占用原因查找
一、遇到的状况

出网带宽:流出服务器的带宽,从服务器对外提供访问,或者从客户端FTP等方式下载服务器内部资源都是出网带宽,服务器出带宽就是购买的带宽值。
2M的带宽几乎一直被占用,导致程序非常卡,出网带宽占用一般情况是从服务器在大量持续性下载东西,或者访问异常,恶意访问等等。
二、解决方法(在服务器安装iftop监控流量使用情况)
1.服务器内部安装 iftop 流量监控工具

2.运行下面命令查看流量占用情况
iftop -i eth1 -P
注:-P 参数会将请求服务的端口显示出来,也就是说是通过服务器哪个端口建立的连接,看内网流量执行 iftop -i eth0 -P 命令

如上面示例图,通过分析发现最耗流量的是服务器上 53139 端口和 115.205.150.235 地址建立的连接,产生了大量入网流量。执行 netstat 命令反查 53139 端口对应进程。

4.最终定位出来是服务器上 vsftpd 服务产生大量流量,这时可以先看看该服务对应的代码有什么问题,通过修改代码,停止服务或使用iptables服务来对指定地址进行处理,如屏蔽 IP 地址,限速,以保证服务器带宽能够正常使用。
三、总结
我通过上面的方法得出的结论是服务对应的页面加载时需要加载过多的图片,而且用的是IO流的方式,所以带宽一直被占用,修改图片加载方式为直接url展示则不会影响带宽