MRTG安装配置

运维 系统运维
配置SNMP和MRTG:MRTG是利用SNMP协议去查询指定有SNMP协议的设备,定时统计其设备的流量或负载,再将统计结果绘成统计图,从统计图上能很容易、直观地就能查出流量或负载。本文讲述的是用MRTG在IIS上实现入侵检测功能。

  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进行网络监控

责任编辑:zhaolei 来源: CSDN
相关推荐

2011-04-02 14:21:46

MRTG安装

2010-06-07 18:12:39

mrtg 安装

2011-03-30 15:05:40

MRTG安装

2011-11-08 21:55:58

MRTG 配置

2011-03-31 10:31:18

Ubuntu安装MRTG

2011-03-31 09:02:22

Windows安装MRTG

2010-05-28 18:57:15

Mrtg配置

2011-04-01 10:19:13

MrtgCISCO安装

2010-06-01 10:45:02

Mrtg 安装

2010-06-01 09:51:11

2011-03-31 10:26:51

安装MRTG

2010-06-01 10:12:29

Mrtg配置

2011-03-02 10:41:41

Vsftpd安装

2011-02-23 10:43:17

2011-02-25 17:48:52

2010-06-07 11:22:28

2011-04-02 10:29:19

MRTG安装

2011-02-25 17:19:09

Pureftpd安装

2011-04-02 15:26:51

Cacti安装

2011-03-25 15:01:44

Cacti安装
点赞
收藏

51CTO技术栈公众号