分享
 
 
 

使用Mrtg监控网络流量

王朝other·作者佚名  2008-05-18
窄屏简体版  字體: |||超大  

虽然使用mrtg来实现网络设备的流量监控本站已经有很多了,但是我还是想写一篇关于此方面的文章,Mrtg是个功能比较强大的软件,除了流量监控之外还可以监控服务器的CPU使用效率,SQUID代理服务器的流量统计以及服务器网卡流量.本文将只讨论如何用Mrtg监控交换机和路由器的端口流量.

基本环境介绍

RedHat Linux7.3 + 自带的Mrtg2.9.17+Apache 1.3.27 +RRDTools 1.0.41 + routers2.cgi version2.11

Mrtg

首先安装好RedHat7.3安装完后检查是否装了Mrtg这个软件,当然你也可以下载源代码安装,这里为了省事就用了RedHatLinux自带的RPM包了,使用下面的命令检查:

# rpm -qa|grep mrtg

如果得到输出:

mrtg-2.9.17-3

就说明mrtg已经安装好了,如果没有得到输出,请从您的CD上安装这个软件

Apache

接下来下载Apache,具体编译过程就不多说了,无论你如何编译,请切记把mod_expries这个模块编译进去,因为后面的routers2.cgi需要这个模块来定期刷新页面.下面的是我编译apache的常用参数,安装目录为/usr/local/apache,编译支持所有自带的模块:

# ./configure --enable-module=most --enable-shared=max

安装配置

mrtg的包是和httpd有关联的,所以只要安装了系统自带的mrtg的包就肯定会把自带的apache给装上,运行下面的命令去掉系统自带的apache的启动,并用我们启动我们编译好的apache:

# chkconfig --level 345 httpd on

# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd

# /etc/init.d/httpd start

# mkdir /usr/local/apache/htdocs/mrtg

RRDTools

从这里下载最新的版本,目前的稳定版本是1.4.1,使用RRDTools的目的一是为了能使用mrtg的第三方的前端工具routers.cgi还有就是可以减少服务器的负担,增加工作效率,如果不使用这个软件,mrtg会每5分钟采样一次并对每个端口生成每日,每周,每月和每年的流量分析图.而使用这个软件后,mrtg会每隔5分钟将采样数据保存到rrd数据库中,但是不会再生成流量分析图了,这样就降低了服务器的负载

# tar zxvf rrdtool-1.0.41.tar.gz

# cd rrdtool-1.0.41

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

# make;make install;make site-perl-install

安装完毕

Mrtg数据采集

# mkdir /usr/local/apache/htdocs/mrtg/conf

# cfgmaker --output=/usr/local/apache/htdocs/mrtg/conf/2948.conf public@10.1.1.1

修改2948.conf,修改第8行为

WorkDir: /usr/local/apache/htdocs/mrtg/2948

在大概16行的地方加入:

Options[_]: bits

Language: GB2312

LogFormat: rrdtool

PathAdd:/usr/local/rrdtool/bin

LibAdd:/usr/local/rrdtool/lib/perl

修改/usr/bin/mrtg在881行加入

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

执行crontab -e加入

*/5 * * * * mrtg /usr/local/apache/htdocs/mrtg/conf/2948.conf

到此mrtg的配置基本结束,mrtg会每5分钟采样一次并将数据保存到rrd数据库中.

routers.cgi

为了能在web页面中显示我们的流量分析图,我们还需要下载routers.cgi这个用perl写的cgi文件,从这里下载,你需要首先安装GD的perl模块,最新版本是2.06,该版本需要GD的2.01以上的版本,因此我们也需要安装GD的最新版本在是安装步骤如下:

# tar zxvf gd-2.0.11.tar.gz

# cd gd-2.0.11

# ./configure --prefix=/usr/local/gd;make;make install

# tar zxvf GD-2.0.6.tar.gz

# cd GD-2.0.6

# perl Makefile.PL

NOTICE: This module requires libgd 2.0.5 or higher.

it will NOT work with earlier versions.

For earlier versions of libgd, use GD version 1.41.

Where is libgd installed? [/usr/lib] /usr/local/gd/lib

Please choose the features that match how libgd was built:

Build JPEG support? [y] y

Build FreeType support? [y] n

Build XPM support? [y] n

If you experience compile problems, please check the @INC, @LIBPATH and @LIBS

arrays defined in Makefile.PL and manually adjust, if necessary.

Writing Makefile for GD

# make;make install

# tar zxvf routers2-v2.11.tar.Z

# cd routers2-v2.11

# perl install.pl 执行该命令后会要你回答一系列的问题,请根据你的系统情况如实填写

This program attempts to install the routers2.cgi package, located in

the current directory. It will attempt to identify system settings,

but you must confirm the locations guessed, or give the correct

information.

At any point, you can answer 'quit' to abort the installation.

Depending on your Perl implementation, you may also have line editing

and history capability.

Default answers are in square brackets before the prompt.

Continue [yes]?

Checking Perl libraries...

RRDs library found correctly.

GD libraries found correctly.

WARNING: You do not have the Time::Zone library installed.

This is not a big problem, so don't worry.

This will only be a potential problem if you are using multiple time zones and

your operating system does not support the TZ environment variable.

If you wish to obtain this package, visit CPAN.org

WARNING: You do not have the Net::SNMP library installed.

This library is required if you wish to use the routingtable extension.

routers2.cgi will run correctly without this package, however.

If you wish to obtain this package, visit CPAN.org

FINDING OUT ABOUT YOUR SYSTEM

0. Attempting to identify your OS and web server...

- I think you are running under UNIX.

- I think you have Apache installed in

/usr/local/apache/conf

1. Web server document root directory.

This is the base document directory of your web server.

Document root [/usr/local/apache/htdocs]?

2. Web server CGI directory.

This is the directory where your web server keeps the CGI scripts.

CGI directory [/usr/local/apache/cgi-bin/]?

3. MRTG install directory.

This is the directory where your MRTG configuration files are kept

MRTG config directory? /usr/local/apache/htdocs/mrtg/conf

4. MRTG config files.

This is the wildcarded filename format for your MRTG configuration files.

Use a '*' to mean 'any characters' - for example, '*.cfg' or '*/*.conf'.

MRTG files [*.cfg]? *.conf

5. RRD Database directory.

This is the directory where your .rrd files are kept

RRD directory [/usr/local/apache/htdocs/mrtg/2948]?

6. Perl executable.

This is the full pathname of where the Perl executable file is kept.

Perl executable [/usr/local/bin/perl]?

7. routers2.cgi configuration file

This is the file that will hold the routers2.cgi configuration. Unless you

have a reason to move it, stick with the default.

If this file already exists, I will ask before overwriting it!

Configuration file [/usr/local/apache/htdocs/mrtg/2948/routers2.conf]?

ASKING OPTIONS

1. Net::SNMP does not appear to be installed. Extensions disabled.

If you subsequently install Net::SNMP, then you can enable the extensions

in the routers2.conf file.

GD Perl Library is detected.

2. The Compact Summary pages will be enabled.

3. How big should 1K and 1M be? This is the 'usebigk' parameter from the

routers2.conf file. You have three options - 'yes', 'no' and 'mixed'.

yes -> 1K=1024, 1M=1024x1024

no -> 1K=1000, 1M=1000x1000

mixed -> 1K=1024, 1M=1024x1000 (dont ask)

'usebigk' option [mixed]? yes

4. Can I attempt to send an email to the author to let him know that the

software has been installed? This will only give your routers.cgi version,

Perl version, and Operating System version.

Can I mail [yes]?

INSTALLING SOFTWARE

Perl is : /usr/local/bin/perl

MRTG files : /usr/local/apache/htdocs/mrtg/conf/*.conf

RRD files : /usr/local/apache/htdocs/mrtg/2948

Doc root : /usr/local/apache/htdocs

CGI bin : /usr/local/apache/cgi-bin/

Config file : /usr/local/apache/htdocs/mrtg/2948/routers2.conf

Extensions : INACTIVE

Compact page: ENABLED

'usebigk' : yes

Mail Steve : yes

Other options can be set later by modifying the Config file

Continue [yes]?

WARNING: /usr/local/apache/htdocs/mrtg/2948/routers2.conf already exists!

Overwrite existing file [no]?

Writing new configuration to /usr/local/apache/htdocs/mrtg/2948/routers2.conf.new

Creating /usr/local/apache/htdocs/mrtg/2948/routers2.conf.new...

Message sent using MAPI.

** ALL COMPLETE **

You should now be able to run the software, although you may need to

make sure you have your web server running.

To access the frontend, point your favourite web browser at the URL:

http://ns1.catv.net/cgi-bin/routers2.cgi

See http://www.cheshire.demon.co.uk/pub/wishlist for information on

how to say 'thanks' for this free software.

* Apache users should make sure that mod_expires is loaded and enabled

* Apache should also be configured with 'AllowOverride: All' for the directory

/usr/local/apache/htdocs/graphs

* Apache users should NOT use mod_perl or speedycgi for this script.

* You may wish to tighten the rights granted on the graphs directory

/usr/local/apache/htdocs/graphs

以后如果想修改routers2的配置可以直接修改routers2.conf文件,之后只要在你浏览器中输入:http://你的机器的IP/cgi-bin/routers2.cgi就可以看到流量分析图了:

下面是部分截图:

500) {this.resized=true; this.width=500;}" onmouseover="this.style.cursor='hand'" onclick="{window.open('http://www.chinalinuxpub.com/images/routers1.jpg');}" src="http://www.chinalinuxpub.com/images/routers1.jpg" onmousewheel="return bbimg(this)" width=600 border=0

500) {this.resized=true; this.width=500;}" onmouseover="this.style.cursor='hand'" onclick="{window.open('http://www.chinalinuxpub.com/images/routers2.jpg');}" src="http://www.chinalinuxpub.com/images/routers2.jpg" onmousewheel="return bbimg(this)" width=600 border=0

500) {this.resized=true; this.width=500;}" onmouseover="this.style.cursor='hand'" onclick="{window.open('http://www.chinalinuxpub.com/images/routers3.jpg');}" src="http://www.chinalinuxpub.com/images/routers3.jpg" onmousewheel="return bbimg(this)" width=600 border=0

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有