MRTG安装配置

配置SNMP和MRTG:MRTG是利用SNMP协议去查询指定有SNMP协议的设备,定时统计其设备的流
首页 新闻资讯 行业资讯 MRTG安装配置

  MRTG安装配置

  MRTG所需软件

  gd、gd-devel、libpng、libpng-deve、libpng、libpng、perl、zlib、zlib-deve、httpd、gcc、net-snmp、mrtg.tar.g

  可使用rpm -qa | grep xxx 查看是否安装以上软件包,如果没有安装可使用yum install xxx进行安装。我们的系统已经默认安装了这些包.

  Mrtg需要以SNMP服务器为基础.所以我们要先配置SNMP并启动它.

  确认系统中安装了以下软件包:

  net-snmp-libs

  net-snmp

  net-snmp-utils

  1、 配置SNMP服务

复制

  #vi /etc/snmp/snmpd.conf
  • 1.

  • 2.

  去掉如下一行的注释

复制

  view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc
  • 1.

  • 2.

  在大约55行处添加如下一行

复制

  view systemview included .1.3.6.1.2.1.2
  • 1.

  • 2.

  把如下行

复制

  #access notConfigGroup "" any noauth exact systemview none none
  • 1.

  • 2.

  改作:

复制

  access notConfigGroup "" any noauth exact mib2 none none     #com2sec paranoid default public     com2sec readonly 192.168.1.12/24 public # 192.168.1.12/24 为充许连接的IP和网络,public 为密码     #service snmpd start
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  • 7.

  • 8.

  2、安装MRTG

复制

  #tar zxvf mrtg-2.16.2.tar.tar –C ../software     #./configure --prefix=/usr/local/mrtg     #make && make install
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  3、创建目录

复制

  #mkdir /usr/local/mrtf/etc //用于存放所有每台主机的配置文件     #mkdir /usr/local/mrtf/html //用于存放mrtg生成的流量图.
  • 1.

  • 2.

  • 3.

  • 4.

  4、创建MRTG配置文件

复制

  #/usr/local/mrtg/bin/cfgmaker public@192.168.1.56 --global workdir:/usr/local/mrtg/html --output=192.168.1.56.cfg     #public为192.168.1.56主机的snmp密码     #workdir 为mrtg工作目录     #output 为生成的mrtg文件路径
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  • 7.

  • 8.

  5、修改MRTG配置文件

复制

  #vi 192.168.1.56.cfg     #Options[_]: growright, bits前面的#去掉前面的#号
  • 1.

  • 2.

  • 3.

  • 4.

  在最后加上

复制

  Options[_]: growright, bits     Language: gb     然后wq保存。这样可以让页面显示中文
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  6、制作首页

复制

  #/usr/local/mrtg/bin/indexmaker --output=/usr/local/mrtg/html/index.html --title="test MRTG on linux" /usr/local/mrtg/etc/192.168.1.56.cfg如果有多台主机监控,可以使用     #/usr/local/mrtg/bin/indexmaker --output=/usr/local/mrtg/html/index.html --title="test MRTG on linux" /usr/local/mrtg/etc/*.cfg     //这样每台主机的监控都在首页上显示     //output 输入目录为mrtg的网页目录     //title 为网页标题     // /usr/local/mrtg/etc/192.168.1.56.cfg 为生成的MRTG文件
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  • 7.

  • 8.

  • 9.

  • 10.

  • 11.

  • 12.

  7、启动MRTG

复制

  # env LANG=C /usr/local/mrtg/bin/mrtg /etc/mrtg/mrtg.cfg
  • 1.

  • 2.

  这个命令会输出一些错误信息,一般可以安全忽略,连续执行三次此命令即可。

  MRTG生成的web页面是静态的,为了能让其不断的刷新,需要将以上命令添加进crontab

  设定任务每3分钟运行一次

复制

  #crontab -e     */3 * * * * env LANG=C /usr/local/mrtg/bin/mrtg /usr/local/mrtg/etc/192.168.1.56.cfg
  • 1.

  • 2.

  • 3.

  • 4.

  8、配置MRTG网页目录

复制

  #vi /etc/httpd/conf/httpd.conf
  • 1.

  • 2.

  在文件尾输入

复制

  Alias /mrtg /usr/local/mrtg     AddDefaultCharset gb2312 # 设置为gb编码,与192.168.1.56.cfg的配置文件编码相同,这样web访问才是中文件显示          AuthType Basic     Options None     AllowOverride None     Order allow,deny     Allow from all     # AuthName "Mrtg Access"     # AuthUserFile /usr/local/mrtg/etc/htpasswd 也可对目录加入口命令保护     # Require valid-user          #service httpd start
  • 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.

  客户机配置:

  只需要修改snmp配置文件并启动服务

复制

  #vim /etc/snmp/snmpd.conf
  • 1.

  • 2.

  去掉如下一行的注释

复制

  view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc
  • 1.

  • 2.

  在大约55行处添加如下一行

复制

  view systemview included .1.3.6.1.2.1.2
  • 1.

  • 2.

  把如下行

复制

  access notConfigGroup "" any noauth exact systemview none none
  • 1.

  • 2.

  改作:

复制

  access notConfigGroup "" any noauth exact mib2 none none
  • 1.

  • 2.

  76行左右:

复制

  com2sec readonly 192.168.1.0/24 public
  • 1.

  • 2.

  10、测试MRTG监控页面

  http://localhostip/mrtg

  关于mrtg监控100M以上流量不准的解决办法及配置实例

复制

  /usr/local/mrtg-2/bin/cfgmaker --global 'WorkDir: /var/www/html/mrtg/test' --global 'Options[_]: bits,growright' --output /etc/mrtg/cfg/test.cfg --snmp-option=:::::2 --ifdesc=alias --no-down snmp值@IP地址
  • 1.

  • 2.

  注:

  (1)cfgmaker --snmp-option=:::::2表示采集时使用snmp2(采用64bit),可支持155M以上的大流量,而缺省是snmp1(采用32bit),流量超过100M后就不准确

  (2)--no-down 表示不管端口是up还是down,都显示出来,缺省只显示up的端口

  (3)--ifdesc=alias 表示将端口描述description作为图片提示语

  缺省是--ifdesc=nr 表示interface description uses Interface Number

  vi /etc/mrtg/cfg/test.cfg 加入以下

复制

  RunAsDaemon: Yes     Refresh:300     //Language: GB2312
  • 1.

  • 2.

  • 3.

  • 4.

  • 5.

  • 6.

  以下连运行三次

复制

  env LANG=C /usr/local/mrtg-2/bin/mrtg /etc/mrtg/cfg/test.cfg
  • 1.

  • 2.

  再生成起始文件

复制

  /usr/local/mrtg-2/bin/indexmaker --output=/var/www/html/mrtg/zhonghualuGSR/index.html /etc/mrtg/cfg/test.cfg
  • 1.

  • 2.

【编辑推荐】

Linux下用mrtg监控网络设备端口流量

FreeBSD下安装MRTG监控流量

通过路由器利用MRTG进行网络监控

10    2011-04-01 15:00:35    MRTG 安装