1、安装net-snmp
#yum install net-snmp net-snmp-utils -y
#snmpwalk -v 1 -c public localhostIP-MIB::ipAdEntIfIndex
Created directory: /var/lib/net-snmp/mib_indexes
Timeout: No Response from localhost
现在是提取不到数据的,我们需要对/etc/snmp/snmpd.conf 进行一些修改
# vim /etc/snmp/snmpd.conf
#com2secnotConfigUser default public
com2sec local localhost public
com2sec mynetwork 192.168.0.0/24(网段) public(团体名重要)
#group notConfigGroupv1 notConfigUser
#group notConfigGroupv2c notConfigUser
group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local
group MyROGroup v1 mynetwork
group MyROGroup v2c mynetwork
group MyROGroup usm mynetwork
#view systemview included .1.3.6.1.2.1.1
#view systemview included .1.3.6.1.2.1.25.1.1
view all included .1 80
#access notConfigGroup "" any noauth exact systemview none none
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all none
将下边的这部分稍微改动一下,其实就是一些描述的东西
syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
syslocation Linux6.
syscontact Vivek G Gite vivek@nixcraft.com
以上就是要修改的地方了!
# /etc/init.d/snmpd restart
# snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex
IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
IP-MIB::ipAdEntIfIndex.192.168.0.55 = INTEGER: 2
现在就可以提取到数据了
#chkconfig snmpd on
2、安装MRTG
1)生成配置文件
cfgmaker public@*.*.*.* >> /etc/mrtg/mrtg.cfg
2)生成index.html首页
indexmaker--output=/data/web/mrtg/index.html /etc/mrtg/mrtg.cfg
3)成像
mrtg /etc/mrtg/mrtg.cfg
现在装一下mrtg,我这里用到的是mrtg-2.16.2-5.el6.x86_64
# yum install -y mrtg
# mkdir -p /var/www/html/mymrtg
cfgmakerpublic@*.*.*.* > /etc/mrtg/mrtg.cfg
如果后续还要添加主机的时候使用cfgmakerpublic@*.*.*.* >> /etc/mrtg/mrtg.cfg
这样mrtg可以自动获取能监控设备的信息(对于Cisco交换机就可以监控单独端口的流量),snmpwalk -v 2c -c public 192.168.123.111 if
修改配置文件vim /etc/mrtg/mrtg.cfg
#for UNIX
WorkDir: /data/web/mrtg/114.255.92.153 #这行去掉注释和空格,填写合适路径
# or for NT
#WorkDir: c:\mrtgdata
###Global Defaults
# to get bits instead of bytes and graphsgrowing to the right
Options[_]: growright, bits #这行去掉注释和空格
RunAsDaemon:yes #加这两行是为了没5分钟自动刷新一次
Interval:5
如果监控一台远程主机,这样做的话,需要给远程主机也安装snmp,进行配置,将本机的配置文件复制过去即可!配置文件如下:
com2seclocal localhost public
com2sec mynetwork 192.168.0.0/24 public
group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local
group MyROGroup v1 mynetwork
group MyROGroup v2c mynetwork
group MyROGroup usm mynetwork
view all included .1 80
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all none
com2sec local localhost public
com2sec mynetwork 192.168.0.0/24 public
syslocation Linux6.
syscontact Vivek G Gite <vivek@nixcraft.com>
dontLogTCPWrappersConnects yes
#/etc/init.d/snmpd restart
# snmpwalk -v 1 -c public localhostIP-MIB::ipAdEntIfIndex
IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
IP-MIB::ipAdEntIfIndex.192.168.0.222 = INTEGER: 4
IP-MIB::ipAdEntIfIndex.192.168.122.1 = INTEGER: 5
# chkconfig snmpd on
#indexmaker--output=/var/www/html/mymrtg/index.html /etc/mrtg/mymrtg.cfg
Use of uninitialized value $first in hash element at /usr/bin/indexmaker line353.这里有时候会出现一个错误,是因为生成的/etc/mrtg/mymrtg.cfg 文件里接口内容被注掉了,将下边内容下的东西注释行去掉,改成下边这样子:
### Interface 1 >> Descr: ‘lo‘ | Name: ‘lo‘ | Ip: ‘127.0.0.1‘ | Eth: ‘‘###
### The following interface is commented out because:
### * it is a Software Loopback interface
Target[localhost_1]: 1:public@localhost:
SetEnv[localhost_1]: MRTG_INT_IP="127.0.0.1"MRTG_INT_DESCR="lo"
MaxBytes[localhost_1]: 1250000
Title[localhost_1]: Traffic Analysis for 1 -- server26.example.com
PageTop[localhost_1]: <h1>Traffic Analysis for 1 --server26.example.com</h1>
<div id="sysdetails">
<table>
<tr>
<td>System:</td>
<td>server26.example.com in Linux6.</td>
</tr>
<tr>
<td>Maintainer:</td>
<td>Vivek G Gite <vivek@nixcraft.com></td>
</tr>
<tr>
<td>Description:</td>
<td>lo </td>
</tr>
<tr>
<td>ifType:</td>
<td>softwareLoopback (24)</td>
</tr>
<tr>
<td>ifName:</td>
<td>lo</td>
</tr>
<tr>
<td>Max Speed:</td>
<td>1250.0 kBytes/s</td>
</tr>
<tr>
<td>Ip:</td>
<td>127.0.0.1 (localhost.localdomain)</td>
</tr>
</table>
</div>
# indexmaker --output=/var/www/html/mymrtg/index.html/etc/mrtg/mymrtg.cfg(生成主页文件)
# mrtg /etc/mrtg/mrtg.cfg(启动mrtg)
-----------------------------------------------------------------------
ERROR: Mrtg will most likely not work properly when the environment
variable LANG is set to UTF-8. Please runmrtg in an environment
where this is not the case. Try thefollowing command to start:
env /usr/bin/mrtg/etc/mrtg/mymrtg.cfg
-----------------------------------------------------------------------
# env /usr/bin/mrtg /etc/mrtg/mymrtg.cfg
这条命令前两次运行会出错,运行三次就ok了
为了方便,我们可以写一个crontab
# crontab -e
*/5 * * * * /usr/bin/mrtg /etc/mrtg/mymrtg.cfg --logging /var/log/mrtg.log
由于页面访问是基于httpd的,记得开启httpd服务哦!
也可以在每个配置文件中加入一下代码,每5分钟自动刷行一次
RunAsDaemon:yes
Interval:5
原文地址:http://7964599.blog.51cto.com/7954599/1441356