努力, 努力, 再努力
全部博文(220)
分类: 系统运维
2015-04-13 22:05:10
应用场景描述:
如果你发现网络较慢, 经查是出口带宽流量较大, 继续查是网内某台linux服务器的对外流量比较大, 然后采取措施, 对该linux服务器限速或者暂时性关闭网络. 但问题是, 这台服务器怎么了? 是中毒了, 还是用户访问量过大? 等你限速后, 再到服务器上查询原因, 基本上是查不到了, 各个进程占用率都正常了, 无法看到故障时的状态. 换句话说, 你无法通过本次故障, 避免同类故障再次发生.
那么新的需求就是, 作为管理员, 你要知道这台linux服务器上哪个进程占用了你大量带宽? 找到他, 才能明确知道是中毒,还是业务访问过大.
应用场景描述完了, 该解决问题了, 答案是nethogs
nethogs 可以查看当前linux系统中哪个进程占用了多少带宽?
具体步骤:
1. 安装epel yum源
方法: 安装 epel-release-6-8.noarch.rpm(针对centOS6.*)
rpm -Uvh
或者 从下面的链接下载
安装 epel-release-5-4.noarch.rpm (针对centOS5.4)
rpm -Uvh
或者从下面的链接下载
安装后, 在/etc/yum.repos.d/下会出现两个YUM配置文件
epel.repo, epel-testing.repo
[root@master yum.repos.d]# cat epel.repo
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=
mirrorlist=
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 6 - $basearch - Debug
#baseurl=/debug
mirrorlist=
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=1
[epel-source]
name=Extra Packages for Enterprise Linux 6 - $basearch - Source
#baseurl=
mirrorlist=
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=1
2. 安装nethogs包
[root@master ~]# yum install nethogs -y
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* c6-media:
* epel: mirrors.yun-idc.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package nethogs.x86_64 0:0.8.0-1.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================
Package Arch Version Repository Size
===============================================================================
Installing:
nethogs x86_64 0.8.0-1.el6 epel 28 k
Transaction Summary
===============================================================================
Install 1 Package(s)
Total download size: 28 k
Installed size: 53 k
Downloading Packages:
nethogs-0.8.0-1.el6.x86_64.rpm | 28 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : nethogs-0.8.0-1.el6.x86_64 1/1
Verifying : nethogs-0.8.0-1.el6.x86_64 1/1
Installed:
nethogs.x86_64 0:0.8.0-1.el6
Complete!
3. 使用nethogs 查看哪些linux进程占用带宽
[root@master yum.repos.d]# nethogs -p eth0