您的位置:首页 > 运维架构 > Linux

LINUX 下基于net-snmp使用MRTG监控服务器流量

2017-04-28 11:28 771 查看
一.服务器环境
    1.Apache 2.2
   
    2.net-snmp-5.3.1-11.fc6.i386.rpm
       net-snmp-devel-5.3.1-11.fc6.i386.rpm
       net-snmp-libs-5.3.1-11.fc6.i386.rpm
       net-snmp-perl-5.3.1-11.fc6.i386.rpm
       net-snmp-utils-5.3.1-11.fc6.i386.rpm
       lm_sensors-2.10.0-3.1.i386.rpm
       lm_sensors-devel-2.10.0-3.1.i386.rpm
       (rpm -qa |grep 检查,缺少哪个安哪个)
    3.fontconfig-devel-2.4.1-5.el5.i386.rpm
       freetype-devel-2.2.1-10.fc6.i386.rpm
      gd-devel-2.0.33-9.3.fc6.i386.rpm
      libjpeg-devel-6b-37.i386.rpm
      libX11-devel-1.0.3-4.fc6.i386.rpm
      libXau-devel-1.0.1-3.1.i386.rpm
      libXdmcp-devel-1.0.1-2.1.i386.rpm
      libXpm-devel-3.5.5-3.i386.rpm
      mesa-libGL-devel-6.5.1-7.fc6.i386.rpm
      xorg-x11-proto-devel-7.1-9.fc6.i386.rpm
      (rpm -qa |grep 检查,缺少哪个安哪个)
  
   4.mrtg-2.16.2.tar.gz
     tar -zxvf mrtg-2.16.2.tar.gz
    ./configure --prefix=/usr/local/mrtg2
    make
    make install
 
二.配置SNMP
    1. vi /etc/snmp/snmpd.conf
    com2sec notConfigUser  default       public                       (建议更改不易被猜测到的团体名)
                                           主机ip         团体名
    view mib2   included  .iso.org.dod.internet.mgmt.mib-2 fc  (这一句默认是开启的,在90行)
    access notConfigGroup "" any noauth exact mib2 none none (原来的mib2的位置是systemview)
   
    2.或者直接吧37到63行换成
####
# First, map the community name "public" into a "security name"
#       sec.name  source          community
com2sec notConfigUser  default       public
####
# Second, map the security name into a group name:
#       groupName      securityModel securityName
group   notConfigGroup v1           notConfigUser
group   notConfigGroup v2c           notConfigUser
####
# Third, create a view for us to let the group have rights to:
# Make at least  snmpwalk -v 1 localhost -c public system fast again.
#       name           incl/excl     subtree         mask(optional)
view    systemview    included   .1.3.6.1.2.1.1
view    systemview    included   .1.3.6.1.2.1.2
view    systemview    included   .1.3.6.1.2.1.25.1.1
view mib2          included   .iso.org.dod.internet.mgmt.mib-2 fc  (90行已开启此句,或者把90行的注释掉)
####
# Finally, grant the group read-only access to the systemview view.
#       group          context sec.model sec.level prefix read   write  notif
#access  notConfigGroup ""      any       noauth    exact  systemview none none
access notConfigGroup "" any noauth exact mib2 none none
 
三. 配置MRTG
   1. /usr/local/mrtg2/bin/cfgmaker --global "WorkDir: /var/named/chroot/var/mrtg" --global "Options[_]: growright, bits" --ifref=ip --output /etc/mrtg.cfg public@192.168.1.1
--global参数表示后面的选项是对后面指定的设备都是有效的(如果希望对多个设 备进行监控时,该参数就会发生作用)。
WorkDir用来指示mrtg的工作目录;
Options用来 指定一些特定的选项,这里的growright,bits是用来指定默认options配置的,对于常见 的应用来说默认options配置就可以满足需求了。
ifref用来指示用什么选项来标识设备接 口,这里指定使用IP地址来标识网络设备接口。
ifref可以指定为 nr、ip、eth、descr、name。
nr表示用接口在MIBII库中Interface接口的ifIndex来识别 接口;
IP表示使用ip地址识别接口;eth表示使用接口的物理地址标识接口;
descr表示使 用接口的描述信息来标识接口;
name表示使用接口名来标识接口。
一般来说ip地址是唯一 的,但是有些情况下接口是没有IP地址的,例如交换机就会出现这种情况。对于接口来说 nr(接口号)是唯一的,因此对于一般情况使用IP地址就可以了,而对于其他一些情况则需 要采用nr了。
"--output /etc/mrtg.cfg"标识将生成的配置文件存放在/etc/目录
 
2. /usr/local/mrtg2/bin/mrtg /etc/mrtg.cfg   运行三次(必须)
root身份crontab -e进入编辑状态,添加内容 如下:

*/5 * * * * /usr/local/mrtg-2/bin/mrtg /etc/mrtg.cfg  (每5分钟统计一次)

  然后在WorkDir定义的目录中会出现流量图,
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: