在RedHat EL4.0 上安装 MRTG
作者:liheng
Email:liheng_2006@hotmail.com
MRTG(Multi Router Traffic Grapher,MRTG)是一个监控网络链路流量负载的工具软件, 它通过snmp协议从设备得到设备的流量信息,并将流量负载以包含PNG格式的图形的HTML 文档方式显示给用户,以非常直观的形式显示流量负载。
MRTG 的安装
首先检查系统中是否已经安装好了 SNMP
[root @test root] # rpm -qa | grep net-snmp
net-snmp-libs-5.1.2-11
net-snmp-5.1.2-11
查询结果显示已正常安装 SNMP 服务,这个候还需要修改 SNMP 配置文件
[root @test root] # vi /etc/snmp/snmpd.conf
将
access notConfigGroup "" any noauth exact systemview none none
修改成
access notConfigGroup "" any noauth exact mib2 none none
将
view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc
前面的 # 字符去掉
启动 snmp 服务
[root @test root] # service snmpd start
设置 SNMP 服务开机自启动
[root @test root] # chkconfig —level 345 snmpd on
查看 snmp 服务是否正常启动
[root @test root] # netstat -tlunp | grep snmp
tcp 0 0 0.0.0.0:199 0.0.0.0:* LISTEN 3722/snmpd
udp 0 0 0.0.0.0:161 0.0.0.0:* 3722/snmpd
安装 ZLIB
[root @test root] # tar xzvf zlib-1.2.3.tar.gz
[root @test root] # cd zlib-1.2.3
[root @test zlib-1.2.3] # ./configure —prefix=/usr/local/zlib
[root @test zlib-1.2.3] # make
[root @test zlib-1.2.3] # make install
[root @test zlib-1.2.3] # cd
安装 libpng
[root @test root] # tar xzvf libpng-1.2.22.tar.gz
[root @test root] # cd libpng-1.2.22
[root @test libpng-1.2.22] # make -f scripts/makefile.std CC=gcc ZLIBLIB=/usr/local/zlib ZLIBINC=/usr/local/zlib
[root @test libpng-1.2.22] # cd
安装 freetype
[root @test root] # tar xzvf freetype-2.3.5.tar.gz
[root @test root] # cd freetype-2.3.5
[root @test freetype-2.3.5] # mkdir -p /usr/local/freetype
[root @test freetype-2.3.5] # ./configure --prefix=/usr/local/freetype
[root @test freetype-2.3.5] # make
[root @test freetype-2.3.5] # make install
[root @test freetype-2.3.5] # cd
安装 jpegsrc.v6b
[root @test root] # mkdir -pv /usr/local/jpeg6/{,bin,lib,include,man/{,man1},man1}
[root @test root] # tar xzvf jpegsrc.v6b.tar.gz
[root @test root] # cd jpeg-6b/
[root @test cd jpeg-6b] # ./configure --prefix=/usr/local/jpeg6 --enable-shared --enable-static
[root @test cd jpeg-6b] # make
[root @test cd jpeg-6b] # make install
[root @test cd jpeg-6b] # make install-lib
[root @test cd jpeg-6b] # cd
安装 libxml
[root @test root] # tar xzvf libxml2-2.6.30.tar.gz
[root @test root] # cd libxml2-2.6.30
[root @test libxml2-2.6.30] # mkdir /usr/local/libxml
[root @test libxml2-2.6.30] # ./configure --prefix=/usr/local/libxml
[root @test libxml2-2.6.30] # make
[root @test libxml2-2.6.30] # make install
[root @test libxml2-2.6.30] # cp xml2-config /usr/bin
[root @test libxml2-2.6.30] # cd
安装 gd
[root @test root] # tar xzvf gd-2.0.33.tar.gz
[root @test root] # mkdir -p /usr/local/gd
[root @test root] # cd gd-2.0.33
[root @test gd-2.0.33] # ./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/jpeg6 --with-png=/usr/local/lib --with-zlib=/usr/local/zlib —with-freetype=/usr/local/freetype
[root @test gd-2.0.33] # make
[root @test gd-2.0.33] # make install
[root @test gd-2.0.33] # cd
安装 mrtg
[root @test root] # tar xzvf mrtg-2.15.2.tar.gz
[root @test root] # cd mrtg-2.15.2
[root @test mrtg-2.15.2] # ./configure --prefix=/usr/local/mrtg --with-gd=/usr/local/gd --with-gd-lib=/usr/local/gd/lib --with-gd-inc=/usr/local/gd/include --with-z=/usr/local/zlib --with-z-lib=/usr/local/zlib/lib --with-z-inc=/usr/local/zlib/include --with-png=/root/libpng
[root @test mrtg-2.15.2] # make
[root @test mrtg-2.15.2] # make install
[root @test mrtg-2.15.2] # mkdir -p /var/www/mrtg/net
[root @test mrtg-2.15.2] # cp images/* /var/www/mrtg/net
[root @test mrtg-2.15.2] # /usr/local/mrtg/bin/cfgmaker --output=/var/www/mrtg/net/mrtg.cfg
[root @test mrtg-2.15.2] # vi /var/www/mrtg/net/mrtg.cfg
将
# WorkDir: /home/http/mrtg
修改成
WorkDir: /var/www/mrtg/net
并去掉前面的 # 字符
注意:在去掉 WorkDir: /var/www/mrtg/net 前面的 # 字符时,在WorkDir: /var/www/mrtg/net 前面不能留空格,不能在执行 /usr/local/mrtg/bin/mrtg /var/www/mrtg/net/mrtg.cfg & env LANG=C /usr/local/mrtg/bin/mrtg /var/www/mrtg/net/mrtg.cfg 时会报错:ERROR: Line 8 ( WorkDir: /var/www/mrtg/net) in CFG file (/var/www/mrtg/net/mrtg.cfg) does not make sense
将
Options[_]: growright, bits
前面的 # 字符去掉
添加下面一行
Language: GB2312
[root @test mrtg-2.15.2] # /usr/local/mrtg/bin/mrtg /var/www/mrtg/net/mrtg.cfg
这时会报错,如下:
-----------------------------------------------------------------------
ERROR: Mrtg will most likely not work properly when the environment
variable LANG is set to UTF-8. Please run mrtg in an environment
where this is not the case. Try the following command to start:
env LANG=C /usr/local/mrtg/bin/mrtg /var/www/mrtg/net/mrtg.cfg
-----------------------------------------------------------------------
根据提示,重新执行命令
[root @test mrtg-2.15.2] # env LANG=C /usr/local/mrtg/bin/mrtg /var/www/mrtg/net/mrtg.cfg
会提示错误:
2007-10-29 16:27:34, Rateup WARNING: /usr/local/mrtg/bin//rateup could not read the primary log file for localhost_2
2007-10-29 16:27:34, Rateup WARNING: /usr/local/mrtg/bin//rateup The backup log file for localhost_2 was invalid as well
2007-10-29 16:27:34, Rateup WARNING: /usr/local/mrtg/bin//rateup Can't remove localhost_2.old updating log file
2007-10-29 16:27:34, Rateup WARNING: /usr/local/mrtg/bin//rateup Can't rename localhost_2.log to localhost_2.old updating log file
[root@bv-diannao-004 mrtg-2.15.2]# env LANG=C /usr/local/mrtg/bin/mrtg /var/www/mrtg/net/mrtg.cfg
2007-10-29 16:27:41, Rateup WARNING: /usr/local/mrtg/bin//rateup Can't remove localhost_2.old updating log file
再次执行相同命令
[root @test mrtg-2.15.2] # env LANG=C /usr/local/mrtg/bin/mrtg /var/www/mrtg/net/mrtg.cfg
又报错:
2007-10-29 16:27:41, Rateup WARNING: /usr/local/mrtg/bin//rateup Can't remove localhost_2.old updating log file
第三次执行上面的相同命令后,不再报错了,说明正常了。如果还报错,就要检查错误的原因了。
[root @test mrtg-2.15.2] # env LANG=C /usr/local/mrtg/bin/mrtg /var/www/mrtg/net/mrtg.cfg
生成 mrtg 显示信息页面
[root @test mrtg-2.15.2] # /usr/local/mrtg/bin/indexmaker --output=/var/www/mrtg/net/index.html --title="My MRTG" /var/www/mrtg/net/mrtg.cfg
MRTG 生成的页面是静态的,为了让其不断的刷新,需要将以下命令添加进 crontab
[root @test mrtg-2.15.2] # crontab -e
*/5 * * * * env LANG=C /usr/local/mrtg/bin/mrtg /var/www/mrtg/net/mrtg.cfg
这样每隔5分钟 mrtg 就会刷新一次。
登录: 查看 mrtg 显示图,如图所示:
用 MRTG 监控内存
制作监测脚本
[root @test root] # vi /usr/local/mrtg/bin/mem.pl
#!/usr/bin/perl
system ("/usr/bin/free -m | grep Mem > mem_info_file");
open (MEMINFO,"mem_info_file");
@meminfo=;
close (MEMINFO);
foreach $line(@meminfo) {
@memstatus=split(/ +/,$line);
}
$memused=$memstatus[2];
$memtotal=$memstatus[1];
print"$memused\n";
print"$memtotal\n";
system("uptime");
system("uname -n");
修改文件权限为可执行
[root @test root] # chmod 755 /usr/local/mrtg/bin/mem.pl
[root @test root] # vi /var/www/mrtg/mem/mem.cfg
WorkDir: /var/www/mrtg/mem
Target[localhost]:`/usr/local/bin/mem.pl`
Xsize[localhost]:300
Ysize[localhost]:100
Ytics[localhost]:10
MaxBytes[localhost]:1006
Title[localhost]:Memory State of bv-diannao-004
PageTop[localhost]:Memory State of BV-DIANNAO-004
ShortLegend[localhost]:B
kmg[localhost]:M
YLegend[localhost]:MemoryUsage
Legend1[localhost]:Used
Legend2[localhost]:Total
LegendI[localhost]:Used
LegendO[localhost]:Total
Options[localhost]:growright,gauge,nopercent
[root @test root] # env LANG=C /usr/local/mrtg/bin/mrtg /var/www/mrtg/mem/mem.cfg
设置计划任务,每五分钟更新一次 MEM 监测数据
[root @test root] # crontab -e
*/5 * * * * env LANG=C /usr/local/mrtg/bin/mrtg /var/www/mrtg/mem/mem.cfg
MRTG 监测内在示意图:
|
文件: |
在REDHAT4.0上安装 MRTG.pdf |
大小: |
231KB |
下载: |
下载 | |
阅读(1196) | 评论(0) | 转发(0) |