一、安装前的准备工作:

MRTG为使用Perl程序编写的,并且使用到了zlibgdpng的函数库(zlib用来压缩图表、gd用来绘制图表),且由于MRTG是使用SNMP协议与网络设备通讯,并且最后是以HTTP的网页型态输出成图表,因此,你需要确定Linux主机(本教程是基于RedLinux9.0基础上的)中已经含有下列的组件:

perl (perl-5.0xx 以上)

zlib (zlib-1.1.3-xx 以上)

gd (gd-1.3.xx 以上)

libpng

apache

确定的方法通过RPM的命令来确认 :

rpm-qa | grep perl

rpm-qa | grep zlib

rpm-qa | grep gd

rpm-qa | grep libpng

apache是下载安装的

a. 安装Apache

# wget http://archive.apache.org/dist/httpd/httpd-2.2.23.tar.gz

# tar zxvf httpd-2.2.23.tar.gz

# cd httpd-2.2.23

# ./configure --prefix=/usr/local/apache2

# make && make install

下载mrtg的版本为2.10.15
[root@mail src]# tar xvfzmrtg-2.10.15.tar.gz
[root@mail src]# cd mrtg-2.10.15

[root@mail mrtg-2.10.15]#./configure --prefix=/usr/local/mrtg
[root@mail mrtg-2.10.15]# make
[root@mail mrtg-2.10.15]# make install

到现在我们就已经正确地安装了MRTG系统

中间遇到一个问题是

Quote:  
** Ooops, one of many bad things happened:  
a) You don't have the GD library installed.  Get it from http://www.boutell.com, compile it and  
use either –with-gd-lib=DIR and -with-gd-inc=DIR to specify  its location. You might also have to use –with-z-inc,  –with-z-lib and –with-png-inc, -with-png-lib for gd  versions 1.6 and higher. Check config.log for more  information on the problem.  
b) You have the GD library installed, but not the gd.h  header file. Download the source (see above) and use  -with-gd-inc=DIR to specify where the file can be found.  
c) You have the library and the header file installed, but  you also have a shared GD library in the same directory.  Remove the shared library files and/or links (e.g.  libgd.so.2.0.0, libgd.so and libgd.so.2). This is especially  likely if you're using a recent (post 1.8.4) version of GD  and didn't configure it with –disable-shared.  
d) You have gd library installed and also it-s headers, but you are  missing libpng (and headers) or freetype (and headers)  
(mrtg does not use freetype, but if your copy of gd is precompiled  against it, you have to install it...  
在./configure--后报出这样  

这个就是提示啦,系统有安装过GD库,但没有GD库的开发包,所以无法找到gd.h文件

[root@localhost mrtg-2.16.2]# rpm -qa | grep gd      
    gd-2.0.33-9.4.el5_1.1      
    gdbm-1.8.0-26.2.1      
    sysklogd-1.4.1-44.el5      
    gdm-2.16.0-46.el5      
[root@localhost mrtg-2.16.2]# yum list '*gd*'      
    ·····
[root@localhost mrtg-2.16.2]#

     用YUM安装gd-devel.i386就可以了,依赖关系一步到位,装了十几个依赖包:)

   [root@localhost mrtg-2.16.2]# yum -y install gd-devel  

     再运行一次 ./cofigure --prefix=/usr/local/mrtg 成功,

这时候运行下面的命令:
[root@maildoc]# /etc/rc.d/init.d/snmpd start
Starting snmpd: [ OK ]
如果命令输出如上所示,就表示snmp服务器启动正常。

另外,为了配合mrtg使用,还要修改snmpd的配置,以使其允许mrtg读取其interface(网络接口) 流量数据。

vi /etc/snmp/snmpd.conf

#viewsystemview included mib2
的内容修改为:
viewmib2 included .iso.org.dod.internet.mgmt.mib-2 fc

有些版本是下面的


view systemview included .1.3.6.1.2.1.1
view systemview included .1.3.6.1.2.1.25.1.1
修改为:
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.


然后将
accessnotConfigGroup "" any noauth exact systemview none none
修改为:
accessnotConfigGroup "" any noauth exact mib2 none none
然后再重新启动snmpd
/etc/rc.d/init.d/snmpdrestart

/生成mrtg配置文件/etc/mrtg.cfg  ,其中public@后接的是你的主机名
#/usr/local/mrtg/bin/cfgmaker --global "WorkDir:/var/www/html/mrtg" --output /etc/mrtg.cfg public@IP地址

如果提示没有mrtg目录。手动创建一下,

#mkdir  /var/www/html/mrtg

然后执行命令

#/usr/local/mrtg/bin/mrtg /etc/mrtg.cfg

执行报错不用管,这是在生成mrtg.cfg文件

生成网页浏览

#/usr/local/mrtg/bin/cfgmaker /etc/mrtg.cfg --output /var/www/html/mrtg/index.html

通过ip/mrtg  就可以网页浏览了。

配置mrtg程序自动五分钟休采集交换机MIB信息,生成新的图表

#crontab -e

里边输入

*/5 * * * *  /usr/local/mrtg/bin/mrtg /etc/mrtg.cfg --loggin=/var/log/mrtg.log