本文中使用的系统为RH9.0,本机IP地址为192.168.1.6
一、MRTG需要以SNMP服务为基础,所以请确保你的系统已经启用了此服务
1.请确保你的系统安装了以下软件包 net-snmp-5.0.6-17 net-snmp-devel-5.0.6-17 net-snmp-utils-5.0.6-17
2.修改/etc/snmp/snmpd.conf
去掉如下一行的注释 view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc
在大约55行处添加如下一行 view systemview included .1.3.6.1.2.1.2
把如下行 access notConfigGroup "" any noauth exact systemview none none 改作: access notConfigGroup "" any noauth exact mib2 none none
3.启用snmpd服务 #service snmpd start #chkconfig --levle 2345 snmpd on
4.查看端口的开启状况 # netstat -tunlp |grep snmp tcp 0 0 0.0.0.0:199 0.0.0.0:* LISTEN 4973/snmpd udp 0 0 0.0.0.0:161 0.0.0.0:* 4973/snmpd
二、MRTG生成供浏览图像需要httpd服务的支持,同时也需要gd、libpng和zlib三个软件包的支持,而gd的正常运行也需要其它的几个软件,下面一并安装它们
1.安装zlib-1.2.3 #tar zxvf zlib-1.2.3.tar.gz #cd zlib-1.2.3 #./configure --prefix=/usr/local/zlib #make #make install
2.安装httpd-2.2.4 #tar zxvf httpd-2.2.4.tar.gz #cd httpd-2.2.4 #./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-track-vars --enable-rewrite --with-z-dir=/usr/local/zlib #make #make install 启动httpd /usr/local/apache/bin/apachectl -k start
3.安装libpng-1.2.14 #tar zxvf libpng-1.2.14.tar.gz # cd libpng-1.2.14 # cp scripts/makefile.linux makefile # make (若是提示找不到zlib库文件或者头文件,多半是makefile文件里zlib的默认路径有误。可编辑makefile文件,找到zlib项并重新指定路径到/usr/local/zlib/lib和/usr/local/zlib/include)。 # make install
4.安装freetype-2.1.10 # tar -zvxf freetype-2.1.10.tar.gz # cd freetype-2.1.10 # mkdir -p /usr/local/freetype # ./configure --prefix=/usr/local/freetype # make;make install
5.安装jpegsrc.v6b jpeg默认不会自建目录,因此需手动建立目录: # mkdir -pv /usr/local/jpeg6/{,bin,lib,include,man/{,man1},man1} 安装 #tar zxvf jpegsrc.v6b.tar.gz # ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static # make # make install # make install-lib
6.安装libxml2-2.6.19 # tar -zxf libxml2-2.6.19.tar.gz # cd libxml2-2.6.19 # mkdir -p /usr/local/libxml2 # ./configure --prefix=/usr/local/libxml2 # make; make install #cp xml2-config /usr/bin
7.安装GD-2.0.33库 # tar -zvxf gd-2.0.33.tar.gz # mkdir -p /usr/local/gd2 # cd gd-2.0.33 # ./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg6/ --with-png=/usr/local/lib/ --with-zlib=/usr/local/zlib/ --with-freetype=/usr/local/freetype/ # make # make install
三、安装配置MRTG
1.下载mrtg,目前最新版本为mrtg-2.15.1 http://oss.oetiker.ch/mrtg/pub/mrtg-2.15.1.tar.gz
2.安装mrtg-2.15.1 #tar zxvf mrtg-2.15.1.tar.gz # cd mrtg-2.15.1 # ./configure --prefix=/usr/local/mrtg --sysconfdir=/etc/mrtg --with-gd=/usr/local/gd2/include --with-gd-lib=/usr/local/gd2/lib --with-gd-inc=/usr/local/gd2/include --with-png=/usr/local/include --with-png-lib=/usr/local/lib --with-png-inc=/usr/local/include --with-zlib=/usr/local/zlib/include --with-zlib-lib=/usr/local/zlib/include --with-zlib-inc=/usr/local/zlib/include # make # make install
3.基本配置
生成主配置文件 #/usr/local/mrtg/cfgmaker public@localhost > /etc/mrtg/mrtg.cfg
编辑/etc/mrtg/mrtg.cfg 将 #WorkDir:/home/http/mrtg 去掉注释并改为 WorkDir: /usr/local/apache/htdocs/mrtg (此处是你的httpd默认的主目录)
去掉如下行的注释 # Options[_]: growright, bits
添加如下行,实现网页中的中文字符显示 Language:gb2312
生成MRTG网页主页面文件 #/usr/local/mrtg/bin/indexmaker /etc/mrtg/mrtg.cfg --output=/usr/local/apache/htdocs/mrtg/index.html --title="My MRTG"
4.启动MRTG #env LANG=C /usr/local/mrtg/bin/mrtg /etc/mrtg/mrtg.cfg 这个命令会输出一些错误信息,一般可以安全忽略,连续执行三次此命令即可。
5.MRTG生成的web页面是静态的,为了能让其不断的刷新,需要将以上命令添加进crontab #crontab -e 添加如下一行 */3 * * * * env LANG=C /usr/local/mrtg/bin/mrtg /etc/mrtg/mrtg.cfg 注:此行表示每三分钟刷新一次,你可以根据自己的需要修改刷新时间间隔。
6.安装完毕,可以去查看结果了,在浏览器输入形如以下地址 http://192.168.1.6/mrtg (IP地址为你的机器IP)
四、一个示例:内存使用监视
1.新建一个存放脚本的文件夹 #mkdir -pv /usr/local/apache/htdocs/mrtgsh
2.建立脚本文件 #vi /usr/local/apache/htdocs/mrtgsh/mrtg.memory 添加如下脚本: #!/bin/bash # run this script to check the mem usage. totalmem=`/usr/bin/free |grep Mem |awk '{print $2}'` usedmem=`/usr/bin/free |grep Mem |awk '{print $3}'` UPtime=`/usr/bin/uptime | awk '{print $3""$4""$5}'` echo $totalmem echo $usedmem echo $UPtime 让其具有运行权限 #chmod 755 /usr/local/apache/htdocs/mrtgsh/mrtg.memory
3.编辑/etc/mrtg/mrtg.cfg 添加如下内容 Target[memory]: `/usr/local/apache/htdocs/mrtgsh/mrtg.memory` MaxBytes[memory]: 4096000 Title[memory]:Memory Usages ShortLegend[memory]: & kmg[memory]:kB,MB kilo[memory]:1024 YLegend[memory]: Memory Usage : Legend1[memory]: Total Memory : Legend2[memory]: Used Memory : LegendI[memory]: Total Memory : LegendO[memory]: Used Memory : Options[memory]: growright,gauge,nopercent PageTop[memory]:<H1>Memory Usages</H1>
4.重新生成主页面文件 #/usr/local/mrtg/bin/indexmaker /etc/mrtg/mrtg.cfg --output=/usr/local/apache/htdocs/mrtg/index.html --title="My MRTG"
5.可根据情况重新启动MRTG,然后就可以查看效果了。
本文转自bbs.chinaunix.net
|
|