MRTG使用方法(配置SNMP服务)
对于不同的设备,配置SNMP支持的方法是不一致的,具体请参考设备的随机文档,一般里 面都有详细的介绍。这里我们讨论在Linux环境下配置SNMP服务器,以实现对本机流出流入数据的分析和报表(我的应用环境是使用Linux带动一个小型局域网上网,监控本机进出 流量)。
在linux环境下安装snmp软件包是很容易的,只需要安装相应的软件包即可:
[root@mail doc]# rpm -qa|grep snmp
net-snmp-libs-5.3.1-14.el5
net-snmp-libs-5.3.1-14.el5
net-snmp-5.3.1-14.el5
[root@mail doc]# /etc/rc.d/init.d/snmpd start
Starting snmpd: [ OK ]
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
如果命令输出如上所示,就表示snmp服务器启动正常。
为了配合mrtg使用,还要修改snmpd的配置,以使其允许mrtg读取其interface(网络接口) 流量数据。
vi /etc/snmp/snmpd.conf
- 1.
- 2.
装下面这个的#注
view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc
- 1.
- 2.
然后将
access notConfigGroup "" any noauth exact systemview none none
- 1.
- 2.
修改为:
access notConfigGroup "" any noauth exact mib2 none none
- 1.
- 2.
在55行左右加入:
view systemview included .1.3.6.1.2.1.2
- 1.
- 2.
然后再重新启动snmpd:
/etc/rc.d/init.d/snmpd restart
- 1.
- 2.
生成MRTG配置文件
# mkdir /data/mrtg/cfg/
- 1.
- 2.
配置文件:/data/mrtg/cfg/mrtg.cfg
# cd /data/mrtg/bin
# ./cfgmaker --global 'WorkDir: /data/apache2/htdocs/mrtg' --global 'Options[_]: bits,growright' --output /data/mrtg/cfg/mrtg.cfg public@192.168.3.9
- 1.
- 2.
- 3.
- 4.
更新信息.
env LANG=C /data/mrtg/bin/mrtg /data/mrtg/cfg/mrtg.cfg
# mkdir /data/apache2/htdocs/mrtg
- 1.
- 2.
- 3.
- 4.
生成mrtg的index文件
# ./indexmaker --output /data/apache2/htdocs/mrtg/index.html /data/mrtg/cfg/mrtg.cfg
servername mrgt.yourdomanin.com
documentroot /data/apache2/htdocs/mrtg
customlog logs/mrgt.yourdomanin.com common
options followsymlinks includes
allowoverride none
order allow,deny
allow from all
authname "MRTG流量察看"
authtype basic
authuserfile /data/apache2/passdir/mrtgpass
require user 4ujk
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
生成密码:
mkdir /data/apache2/passdir/
/data/apache2/bin/htpasswd -bc /data/apache2/passdir/mrtgpass username userpass
- 1.
- 2.
- 3.
- 4.
让系统每隔5分钟执行一次mrtg,生成新的MRTG流量图
# crontab –e
*/5 * * * * env LANG=C /data/mrtg/bin/mrtg /data/mrtg/cfg/mrtg.cfg
- 1.
- 2.
- 3.
【编辑推荐】