物探论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 818|回复: 0

MRTG安装方法

[复制链接]
发表于 2013-3-7 15:52:26 | 显示全部楼层 |阅读模式
不要说MRTG已经过时了,我觉得MRTG还是一个比较不错选择,它有着:部署快捷,功能简约,体积较小等优点。

前面我写过一篇《MRTG监控脚本》的文章是专门讲如何用MRTG来监控除了网卡流量以外等其他系统参数的脚本。

这次把MRTG安装过程写出来,也是为了方便大家快速、及时的部署一个简单的监控系统。 安装之前,先来介绍一下MRTG。 MRTG(Multi Router Traffic Grapher,MRTG)是一个监控网络链路流量负载的工具软件,它通过snmp协议从设备得到设备的流量信息,并将流量负载以包含PNG格式的图形的HTML文档方式显示给用户,以非常直观的形式显示流量负载。 下面,我们开始:

首先,你必须要先安装gd、libpng、zlib等MRTG运行所必须一些东西。

1. 安装zlib

mkdir -p /usr/local/src

cd ~

wget http://www.zlib.net/zlib-1.2.3.tar.gz

gunzip -c zlib-1.2.3.tar.gz | tar xf -

mv zlib-1.2.3 /usr/local/src/zlib

cd /usr/local/src/zlib/

./configure

make


2. 安装libpng

cd ~

wget http://nchc.dl.sourceforge.net/s ... ibpng-1.2.25.tar.gz

gunzip -c libpng-1.2.25.tar.gz | tar xf -

mv libpng-1.2.25 /usr/local/src/libpng

cd /usr/local/src/libpng/

make -f scripts/makefile.std CC=gcc ZLIBLIB=../zlib ZLIBINC=../zlib

rm *.so.* *.so


3. 安装GD

cd ~

wget http://www.libgd.org/releases/gd-2.0.35.tar.gz

gunzip -c gd-2.0.35.tar.gz | tar xf -

mv gd-2.0.35 /usr/local/src/gd

cd /usr/local/src/gd/

env CPPFLAGS="-I../zlib -I../libpng" LDFLAGS="-L../zlib -L../libpng" ./configure --disable-shared --without-freetype --without-jpeg


#这里使用的GD是2.0.35版本,如果你使用的是2.0.11之前的版本,例如1.8.4版本,那么这里要使用另外的方法进行编译:

perl -i~ -p -e s/gd_jpeg.o//g Makefile

make INCLUDEDIRS="-I. -I../zlib -I../libpng" LIBDIRS="-L../zlib -L. -L../libpng" LIBS="-lgd -lpng -lz -lm" CFLAGS="-O -DHAVE_LIBPNG"


#好,下面继续GD的编译

make

#这个步骤可能会报错,如果是在RedHat AS3系统上,可以说是一定会报错

[root@ws01 gd]#make
cd . && /bin/bash /usr/local/src/gd/config/missing --run aclocal-1.9 -I config
/usr/local/src/gd/config/missing: /usr/local/bin/aclocal-1.9: bad interpreter: No such file or directory
WARNING: `aclocal-1.9' is missing on your system.  You should only need it if
         you modified `acinclude.m4' or `configure.ac'.  You might want
         to install the `Automake' and `Perl' packages.  Grab them from
         any GNU archive site.
cd . && /bin/bash /usr/local/src/gd/config/missing --run automake-1.9 --foreign
/usr/local/src/gd/config/missing: /usr/local/bin/automake-1.9: bad interpreter: No such file or directory
WARNING: `automake-1.9' is missing on your system.  You should only need it if
         you modified `Makefile.am', `acinclude.m4' or `configure.ac'.
         You might want to install the `Automake' and `Perl' packages.
         Grab them from any GNU archive site.
cd . && /bin/bash /usr/local/src/gd/config/missing --run autoconf
/usr/local/bin/autoconf: /usr/local/bin/autom4te: not found
make: *** [configure] Error 1


#原因是缺少atuomake,但是你在编译automake的时候,还会提示你说你缺少autoconf,所以我们还必须先安装autoconf

cd ~

wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.61.tar.gz

gunzip -c autoconf-2.61.tar.gz | tar xf -

cd autoconf-2.61

./configure && make && make install

cd ..

wget http://ftp.gnu.org/gnu/automake/automake-1.10.tar.gz

gunzip -c automake-1.10.tar.gz | tar xf -

cd automake-1.10

./configure && make && make install

cd /usr/local/src/gd

env CPPFLAGS="-I../zlib -I../libpng" LDFLAGS="-L../zlib -L../libpng" ./configure --disable-shared --without-freetype --without-jpeg

make

cp .libs/* .


OK,到现在为止,我们已经安装好了所有MRTG的运行环境了,zlib、libpng、gd都是安装在/usr/local/src/下面的,事实上,这也是MRTG官方推荐安装的地方。

4. 下面开始安装MRTG

cd ~

wget http://oss.oetiker.ch/mrtg/pub/mrtg-2.16.1.tar.gz

gunzip -c mrtg-2.16.1.tar.gz | tar xf -

cd mrtg-2.16.1

./configure --prefix=/usr/local/mrtg --with-gd=/usr/local/src/gd --with-z=/usr/local/src/zlib --with-png=/usr/local/src/libpng

make && make install


5. 创建相关目录

我习惯于将MRTG的配置文件、运行脚本、日志都放在安装目录下面

mkdir -p /usr/local/mrtg/cfg

mkdir -p /usr/local/mrtg/script

mkdir -p /usr/local/mrtg/log


再创建MRTG的工作目录,实际上是生成MRTG页面文件的为止,一般来说我放在Apache页面目录的一个子目录里面

mkdir -p /var/www/html/mrtg

6. 运行MRTG

首先,是生成配置文件,这个配置文件位置和名字都可以由你自己指定,这里我是这样定义的:

/usr/local/mrtg/bin/cfgmaker --global 'WorkDir: /var/www/html/mrtg' --subdirs=HOSTNAME --global 'Options[_]: bits,growright' --output /usr/local/mrtg/cfg/ws01.cfg whatever@ws01

然后,让MRTG运行这个配置文件:

/usr/local/mrtg/bin/mrtg /usr/local/mrtg/cfg/ws01.cfg

第一次运行会报错,第二次也会报错,但比第一次少,第三次没有报错。

这个时候在/var/www/html/mrtg目录下面已经生成了MRTG数据了,网卡的流量已经可以监控了

下面添加crontab,设置定时运行
SunOS:
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/local/mrtg/bin/mrtg /usr/local/mrtg/cfg/ws01.cfg --logging /usr/local/mrtg/log/mrtg.log

Linux:
*/5 * * * * /usr/local/mrtg/bin/mrtg /usr/local/mrtg/cfg/ws01.cfg --logging /usr/local/mrtg/log/mrtg.log

也可以配置MRTG运行为daemon模式:
vi /ceno/product/mrtg/cfg/ws01.cfg
RunAsDaemon: Yes


下面你还打算监控系统其他参数可以参看《MRTG监控脚本》这篇文章,这里有脚本介绍。

最后,你应该为你的监控页面生成一个index.html文件

/usr/local/mrtg/bin/indexmaker --output=/var/www/html/mrtg/ws20/index.html --title="MRTG" ws01.cfg cpu.cfg mem_swap.cfg http_conn.cfg pop_conn.cfg smtp_conn.cfg

好了,到此,MRTG的安装已经结束了。最后,祝你好运,如果有什么问题欢迎留言或者来信和我交流。

后面,我会再将Net-SNMP的安装写出来。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|物探论坛 ( 鄂ICP备12002012号 微信号:iwutan )

GMT+8, 2024-4-16 17:48 , Processed in 0.073971 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表