专技天下网登录2017:MRTG 监控主机流量

来源:百度文库 编辑:中财网 时间:2024/04/28 14:55:53

MRTG 监控主机流量

参考资料:http://hi.baidu.com/isbruce/blog/item/eca2ed31bdbccaa95fdf0e02.html系统:Centos 5.2MRTG所需软件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进行安装。 Centos 5.2  1、配置SNMP服务 #       sec.name  source          community
com2sec notConfigUser  192.168.1.12/24   public 
# 192.168.1.12/24 为充许连接的IP和网络,public 为密码
#vi /etc/snmp/snmpd.conf
把第89行前面的注释符号#去掉,变成    
view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc
在62行进行修改:将
access notConfigGroup "" any noauth exact systemview none none
改为
access notConfigGroup "" any noauth exact mib2 none none
 Ubuntu 9.0.4apt-get install snmpdvi /etc/default/snmpd#SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid 127.0.0.1'修改为SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid'去掉后面的127.0.0.1 ,要不然snmpd启动会监听到127.0.0.1的端口上,其它服务器无法读取数据.修改/etc/snmp/snmpd.conf文件#             sec.name    source                    community
#com2sec paranoid    default                 public
  com2sec readonly     192.168.1.12/24    public # 192.168.1.12/24 为充许连接的IP和网络,public 为密码
#com2sec readwrite default                 private

2、安装MRTGtar zxvf mrtg
./configure --prefix=/usr/local/mrtg
make && make install
3、配置MRTG在MRTG安装目录中新建一个目录imagesmkdir /usr/local/mrtg/images将MRT解压目录下的images下的所有文件复制到MRTG安装目录的imagescp /data/mrtg/images/* /usr/local/mrtg/images4、创建MRTG配置文件cd /usr/local/mrtg/
bin/cfgmaker public@192.168.1.56 --global workdir:/usr/local/mrtg --output=1.56.cfg
public为192.168.1.56主机的snmp密码,workdir 为mrtg工作目录,output 为生成的mrtg文件路径5、修改MRTG配置文件vi 1.56.cfg
#Options[_]: growright, bits前面的#去掉前面的#号
在最后加上Options[_]: growright, bitsLanguage: gb然后wq保存。这样可以让页面显示中文

运行程序bin/mrtg 1.56.cfg如果有警告错,多运行几次次,警告错不再出现就ok了。
6、制作首页
[root@centos]#/usr/local/mrtg/bin/indexmaker --output=/usr/local/mrtg/index.html --title="test MRTG on linux" /usr/local/mrtg/1.56.cfg如果有多台主机监控,可以使用[root@centos]#/usr/local/mrtg/bin/indexmaker --output=/usr/local/mrtg/index.html --title="test MRTG on linux" /usr/local/mrtg/*.cfg这样每台主机的监控都在首页上显示output 输入目录为mrtg的网页目录title 为网页标题/usr/local/mrtg/1.56.cfg 为生成的MRTG文件7、设定任务每5分钟运行一次crontab -e
*/5 * * * * /usr/local/mrtg/bin/mrtg /usr/local/mrtg/1.56.cfg
8、配置MRTG网页目录vi /etc/httpd/conf/httpd.conf在文件尾输入        Alias /mrtg /usr/local/mrtg          AddDefaultCharset gb2312  # 设置为gb编码,与1.56.cfg的配置文件编码相同,这样web访问才是中文件显示
         "/usr/local/mrtg"
>
            AuthType Basic
            Options None
            AllowOverride None
            Order allow,deny
            Allow from all
#            AuthName "Mrtg Access"
#            AuthUserFile /usr/local/mrtg/etc/htpasswd  也可对目录加入口命令保护
#            Require valid-user
        9、启动SNMP HTTP CRON 服务/etc/init.d/snmpd restart
/etc/init.d/httpd restart
/etc/init.d/crond restart
10、测试MRTG监控页面访问http://192.168.1.11/mrtg 如下图所示

本文出自 “网海过客” 博客,请务必保留此出处http://cqfish.blog.51cto.com/622299/157910