mrtg可能很多人都用过,但那已经是n久以前的事了,现在在国内很多IDC,ISP都还用这个,因为我们这有个Linux科学家,在Linux工作n 久,我也就沾点光,学了不少东西,现在给大家介绍一个rrdtools的工具。用这个做出来的图非常经典。rrdtools也是mrtg的作者编出来的,因此可以结合使用也可以单独使用,如果单独使用就要自己写一些脚本了,这里我就只介绍mrtg和rrdtools结合用的方法。

0.配置需要采集信息的服务器snmp服务(默认为机器已经装了,如果没有自己装去)
#vi /etc/snmp/snmpd.conf

在第三行加入
rocommunity public
public是snmp的识别名,默认为这个,一定要换成其它名称,在这里为了方便我还是用这个。(不换就会被黑客扫描到)

# /etc/rc.d/init.d/snmpd start //启动服务

1。radhat9.0 安装,安装时在系统管理内选择系统工具和网络工具
2。下载 # wget ftp://rpmfind.net/linux/redhat/9/en....81-88.i386.rpm //一会有个外挂程序是perl的,会用到,而且库初始化也要用
3。下载 # wget ftp://rpmfind.net/linux/redhat/9/en....17-13.i386.rpm //也可以用源码安装,不过这个简单就用他了

如果使用新版本请按照安装提示下载相应的包

5。# wget ftp://rpmfind.net/linux/freshrpms/r...5-1.fr.i386.rpm

6。 安装
# rpm -ivh perl-CGI-2.81-88.i386.rpm
# rpm -ivh mrtg-2.9.17-13.i386.rpm
# rpm -ivh rrdtool-1.0.45-1.fr.i386.rpm

7。Mrtg数据采集:在mrtg.cfg中需要修改下列配置才能够将mrtg采集的数据保存到rrd库中
#vi /etc/mrtg/mrtg.cfg //用rpm安装,默认配置文件在这,也可以随意放
WorkDir: /var/www/html/mrtg/ //存放库文件的地方
Options[_]: growright,bits
Language: gb //语言,可以选择gb2312等好多种
#Refresh: 300 //下面的参数是可以选择开放的,先暂时屏蔽
#writeExpires: Yes
#RunAsDaemon: Yes
#Interval: 5
LogFormat: rrdtool //用rrdtool初始化
PathAdd:/usr/bin
LibAdd:/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi/ //perl安装的路径

###################################################
在往下就是你要采集的服务器的信息了,例如要采集一个windows的流量信息

Target[202.103.***.***_16777219]: 16777219ublic@202.103.***.***:
SetEnv[202.103.***.***_16777219]: MRTG_INT_IP="202.103.***.***" MRTG_INT_DESCR="202.103.***.***"
MaxBytes[202.103.***.***_16777219]: 12500000
Title[202.103.***.***_16777219]: Traffic Analysis for 16777219 -- ChangSha
PageTop[202.103.***.***_16777219]: <H1>Traffic Analysis for 16777219 -- WAI-01</H1>
#######################################################

执行crontab -e加入

*/2 * * * * mrtg /etc/mrtg/mrtg.cfg

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

如何知道采集客户端信息可以用以下方法:
# cfgmaker --output=/etc/mrtg/mrtg.cfg public@211.152.***.***
这种方法是直接输出客户端信息到mrtg.cfg中

一般情况我们可以这样:
# cfgmaker public@211.152.***.***
输出在屏幕上,然后把需要的信息拷贝到mrtg.cfg中,一般可用的端口前面没有注释(#),就拷那部分就行。

还可以自己编写采集信息的外挂程序
  可以应用安装完sysstat套件后产生的/usr/bin/sar程序进行外挂程序的编写,也可以使用bash写一个监测CPU的小程序。示例如下:

#vi cpu.sh
***************************************************************
#!/bin/sh
cpuusr=`/usr/bin/sar|grep Average|awk '{print$3}'`
cpusys=`/usr/bin/sar|grep Average|awk '{print$5}'`
UPtime=`/usr/bin/uptime | awk '{print $3" "$4" "$5}'`
echo $cpuusr
echo $cpusys
echo $UPtime
echo yourdomain

******************************************************************
*为文件内容,不要在sh中出现

# chmod 755 cpu.sh(设定成可执行)
# /etc/mrtg/cpu.sh(测试看可执行否)
输出:
2.0
  5.4
  1day,22:30,
  yourdomain

开始设定MRTG参数项,方法如下:
# vi cpu.cfg
************************************************************************

WorkDir: /var/www/html/mrtg/
Options[_]: growright,bits
Language: gb
MaxBytes[localhost]:100
Options[localhost]:gauge,nopercent,growright
#Refresh: 300
#writeExpires: Yes
#RunAsDaemon: Yes
#Interval: 5
LogFormat: rrdtool
PathAdd:/usr/bin
LibAdd:/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi/

############添加部分###############
Target[localhost]:`/etc/mrtg/cpu.sh`
YLegend[localhost]: CPUloading(%)
ShortLegend[localhost]: %
LegendO[localhost]: CPU User;
LegendI[localhost]: CPU System;
Title[localhost]: 99_CPU
PageTop[localhost]:99_CPU

**************************************************************************
  这之后开始执行参数项,注意,要执行三次以上:
  # mrtg /etc/mrtg/cpu.cfg

写入到/etc/crontab当中:
  */5 * * * * mrtg /etc/mrtg/cpu.cfg
  这样就OK了,直接将Web指向地址就可以看见了。

还可以编写其它信息,例如磁盘应用情况,内存应用情况等等发,方法类似,就不介绍了。

到此为止,rrdtools就开始工作了,你可以自己编写一些脚本生成图片,编写方法可以看rrdtools的说明,下面我要介绍另一个经典的外挂程序,你可以不用编写就能生成图像,而且可以分组管理。

8. routers.cgi

为了能在web页面中显示我们的流量分析图,我们还需要下载routers.cgi这个用perl写的cgi文件,
从这里下载http://edlink.esc18.net/downloads/mrtg/ ,

你需要首先安装GD
http://www.cpan.org/authors/id/L/LD...,最新版本是2.06,
该版本需要GD
http://www.boutell.com/gd/http/gd-2...是安装步骤如下:

# 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.
WARNING: You do not have the GD Perl libraries installed correctly.
routers2.cgi will still run, but the Compact Summary display will not work.
Download the GD libraries from CPAN.org if required.
NT Users should use PPM to collect GD from ActiveState.
UNIX users should note that they need the GD.pm Perl library IN ADDITION to
the libgd.a C library.
Continue [y]?
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
/etc/httpd/conf //apache安装的地方

1. Web server document root directory.
This is the base document directory of your web server.
Document root [/var/www/html]? //网站主目录

2. Web server CGI directory.
This is the directory where your web server keeps the CGI scripts.
CGI directory [/var/www/cgi-bin/]? //网站cgi目录

3. MRTG install directory.
This is the directory where your MRTG configuration files are kept
MRTG config directory? /etc/mrtg //你的mrtg的配置文件存放地

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]? //mrtg配置文件的格式(后缀)

5. RRD Database directory.
This is the directory where your .rrd files are kept
RRD directory [/var/www/html/mrtg/]? //存放rrd库的地方,在你的mrtg配置文件里设的

6. Perl executable.
This is the full pathname of where the Perl executable file is kept.
Perl executable [/usr/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 [/var/www/html/mrtg/routers2.conf]? /var/www/html/mrtg/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.

2. GD does not appear to be installed. This is required for the compact
summary screen to work. If you intend to install it later, answer YES.
Otherwise, answer NO.
Activeate Compact Summary screen [no]? yes //需要GD

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/bin/perl
MRTG files : /etc/mrtg/*.cfg
RRD files : /var/www/html/mrtg/
Doc root : /var/www/html
CGI bin : /var/www/cgi-bin/
Config file : /var/www/html/mrtg/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: /var/www/html/mrtg/routers2.conf already exists!
Overwrite existing file [no]? yes
Creating /var/www/html/mrtg/routers2.conf...
No Mail::Send available, trying sendmail instead.
/usr/sbin/sendmail: invalid option -- U
/usr/sbin/sendmail returned code 0. Looks like I cant send an email after all.

** 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://netcool2/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
/var/www/html/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
/var/www/html/graphs //图片输出位置

到此你的安装完成,如果出现的界面跟上面的不一样,说明你还有一些需要的包没有安装上,你可以根据提示安装,最常见的如libpng-devel-1.2.2-16.i386.rpm,libjpeg-devel-6b-26.i386.rpm没有安装。

如果安装通过,就可以访问“http://你的机器的IP/cgi-bin/routers...笨戳髁糠治鐾剂�

以后如果想修改routers2的配置可以直接修改routers2.conf文件。

mrtg 和 rrdtools的更多相关文章

  1. 使用snmp+mrtg监控CPU、流量、磁盘空间、内存

    1.安装snmp rpm -qa|grep snmp* //查看是否安装了snmpyum -y install snmp* //安装snmp #vim /etc/snmp/snmpd.confroco ...

  2. mrtg

    centos6.5-64-minimal http://oss.oetiker.ch/mrtg/doc/cfgmaker.en.htmlhttp://www.cnblogs.com/see7di/ar ...

  3. MRTG开源监控安装手册

    环境要求: CentOS6以上版本 2G内存 16G存储 源码包下载:第一部分:下载,第二部分:下载 1.安装snmp: yum install -y net-snmp net-snmp-devel ...

  4. CentOS 6用snmp配合MRTG显示系统状态

    1. 软件安装以yum的方式安装snmp/MRTG 安装SNMP(要记得安装net-snmp-utils,不然snmpwalk将不能使用)yum -y install net-snmp* 安装MRTG ...

  5. mrtg监控网络流量简单配置

    Mrtg服务器搭建(监控网络流量) [日期:2012-07-03] 来源:Linux社区  作者:split_two [字体:大 中 小]   [实验环境] 监控机:Red Hat linux 5.3 ...

  6. Windows server install mrtg

    由于MRTG使用Perl语言编写 , 安装ActivePerl http://downloads.activestate.com/ActivePerl/releases/5.20.1.2000/Act ...

  7. MRTG在Windows平台的安装及使用

    MRTG (Multi Router Traffic Grapher)是一款监控网络流量负载的免费软件,目前利用MRTG已经开发出了各式各样的统计系统: 1.系统资源负载统计,例如:磁盘空间.CPU负 ...

  8. centos Install Mrtg

    安装支持软件包yum –y install gcc perl gd libpng zlib net-snmp mrtg配置snmpd编辑/etc/snmp/snmpd.conf文件备份snmpd.co ...

  9. Linux服务器---流量监控MRTG

    MRTG MRTG可以分析网络流量,但是它必须依赖SNMP协议.将收集到的数据生成HTML文件,以图片的形式展示出来 1.安装一些依赖软件 [root@localhost bandwidthd-2.0 ...

随机推荐

  1. android studio怎么导入appcompat-v7

    方法1: 在项目的build.gradle文件里,用传统的自动依赖处理方式:compile ‘com.Android.support:appcompat-v7:+’,然后rebuild就可以了. 方法 ...

  2. [原创]解决jQuery.live在mobile safari(iphone / ipad / ipod)绑定失败的问题

    解决方案: 给要使用live绑定事件的元素,添加“cursor:pointer”样式即可! 如: a,input,td{cursor:pointer;} 原文链接:http://bugs.jquery ...

  3. UNIX环境编程学习笔记(23)——信号处理初步学习

    lienhua342014-10-29 1 信号的概念 维基百科中关于信号的描述是这样的: 在计算机科学中,信号(英语:Signals)是 Unix.类 Unix 以及其他 POSIX 兼容的操作系统 ...

  4. mysql add foreign key 不成功

    今天修改了mysql数据表的结构,然后添加外键index一直不成功: 查到问题在于,被外键的表,引擎不是Innodb,而是MyISAM. 修改好,以后保存报错: 解决办法,将数据库表里的数据全部删除, ...

  5. 详解ABBYY FineReader 12扫描亮度设置

    很多刚接触ABBYY FineReader 12的小伙伴可能出现过这样一个问题:在扫描过程中会显示一条消息以提示更改亮度设置.这是因为你 FineReader扫描设置中亮度未正确设置.下面小编就给小伙 ...

  6. jQuery form的load函数与el表达式赋值的冲突问题

    问题: 在使用el表达式给表单中的项赋初始值的时候,总是失败,物流公司没有自动选中,物流单号也没有显示值. <form id="form" method="post ...

  7. Apache+php5

    .下载回来的是解压文件,解压好放到要安装的位置.(我这里以D:\Acpache24为例) .打开Apache24\conf下httpd.conf 文件,用记事本打开即可. ()第37行ServerRo ...

  8. SpringBoot------注解把配置文件自动映射到属性和实体类

    1.映射到属性 package top.ytheng.demo.controller; import org.springframework.beans.factory.annotation.Valu ...

  9. VB2010新特性

    1.取消了连接符(1)","之后(2)"()"前后(3)"{}"前后(4)XML(5)连接字符"&"后(6)赋值 ...

  10. 浅谈iPhone OS(iOS)架构

    iPhone OS(现在叫iOS)是iPhone, iPod touch 和 iPad 设备的操作系统