STEP 1.

MRTG를 설치하였으니 이제 MRTG를 사용하는 방법에 대해서 알아보도록 하겠다.
내 경우에는 MRTG를 관리 할 계정으로 mrtg 라는 계정을 만들었으며, 그 디렉토리 안에 cfg, data, log를 만들었다.

[root@mrtg cfg]# cfgmaker --global Workdir:/home/mrtg/data --global 'Options[_]:growright,bits' --output=/home/mrtg/cfg/test.cfg public@123.123.123.123:::::2
--base: Get Device Info on public@123.123.123.123:::::2
--base: Vendor Id: cisco
--base: Populating confcache
--coca: populate confcache
public@123.123.123.123:::::2
--coca: store in confcache public@123.123.123.123__2 Name Te3/1 --> 1
--coca: store in confcache
public@123.123.123.123__2 Name Te3/2 --> 2
--coca: store in confcache
public@123.123.123.123__2 Name Gi5/1 --> 3
--coca: store in confcache
public@123.123.123.123__2 Name Gi5/2 --> 4
--coca: store in confcache
public@123.123.123.123__2 Name Gi7/1 --> 5
--coca: store in confcache
public@123.123.123.123__2 Name Gi7/2 --> 6
--coca: store in confcache
public@123.123.123.123__2 Name Vl1 --> 7
--coca: store in confcache
public@123.123.123.123__2 Descr TenGigabitEthernet3/1 --> 1
--coca: store in confcache
public@123.123.123.123__2 Descr TenGigabitEthernet3/2 --> 2
--coca: store in confcache
public@123.123.123.123__2 Descr GigabitEthernet5/1 --> 3
--coca: store in confcache
public@123.123.123.123__2 Descr GigabitEthernet5/2 --> 4
--coca: store in confcache
public@123.123.123.123__2 Descr GigabitEthernet7/1 --> 5
--coca: store in confcache
public@123.123.123.123__2 Descr GigabitEthernet7/2 --> 6
--coca: store in confcache
public@123.123.123.123__2 Descr Vlan1 --> 7
--coca: store in confcache
public@123.123.123.123__2 Type 6 --> 1
--coca: store in confcache
public@123.123.123.123__2 Type 6 --> 2 (duplicate)
--coca: store in confcache
public@123.123.123.123__2 Type 6 --> 3 (duplicate)
--coca: store in confcache
public@123.123.123.123__2 Type 6 --> 4 (duplicate)
--coca: store in confcache
public@123.123.123.123__2 Type 6 --> 5 (duplicate)
--coca: store in confcache
public@123.123.123.123__2 Type 6 --> 6 (duplicate)
--coca: store in confcache
public@123.123.123.123__2 Type 53 --> 7
--coca: store in confcache
public@123.123.123.123__2 Eth 00-16-9d-ab-13-78 --> 1
--coca: store in confcache
public@123.123.123.123__2 Eth 00-1c-b0-b6-67-40 --> 2
--coca: store in confcache
public@123.123.123.123__2 Eth 00-1c-b0-b6-67-40 --> 3 (duplicate)
--coca: store in confcache
public@123.123.123.123__2 Eth 00-1c-b0-b6-67-40 --> 4 (duplicate)
--coca: store in confcache
public@123.123.123.123__2 Eth 00-16-46-e3-18-18 --> 5
--coca: store in confcache
public@123.123.123.123__2 Eth 00-1c-b0-b6-67-40 --> 6 (duplicate)
--coca: store in confcache
public@123.123.123.123__2 Eth 00-00-15-00-00-00 --> 7
--base: Get Interface Info
--base: Walking ifIndex
--base: Walking ifType
--base: Walking ifAdminStatus
--base: Walking ifOperStatus
--base: Walking ifMtu
--base: Walking ifAlias
--base: Walking vmVlan
--base: Walking ifSpeed
--base: Walking ifHighSpeed
--base: snmpget
public@123.123.123.123:::::2:v4only for ifHighSpeed.1 -> 10000 Mb/s
--base: snmpget
public@123.123.123.123:::::2:v4only for ifHCInOctets.1 -> 2554890072645173
--base: snmpget
public@123.123.123.123:::::2:v4only for ifHighSpeed.2 -> 10000 Mb/s
--base: snmpget
public@123.123.123.123:::::2:v4only for ifHCInOctets.2 -> 0
--base: snmpget
public@123.123.123.123:::::2:v4only for ifHighSpeed.3 -> 1000 Mb/s
--base: snmpget
public@123.123.123.123:::::2:v4only for ifHCInOctets.3 -> 88837206
--base: snmpget
public@123.123.123.123:::::2:v4only for ifHighSpeed.4 -> 100 Mb/s
--base: snmpget
public@123.123.123.123:::::2:v4only for ifHCInOctets.4 -> 294876
--base: snmpget
public@123.123.123.123:::::2:v4only for ifHighSpeed.5 -> 1000 Mb/s
--base: snmpget
public@123.123.123.123:::::2:v4only for ifHCInOctets.5 -> 8261120
--base: snmpget
public@123.123.123.123:::::2:v4only for ifHighSpeed.6 -> 1000 Mb/s
--base: snmpget
public@123.123.123.123:::::2:v4only for ifHCInOctets.6 -> 0
--base: snmpget
public@123.123.123.123:::::2:v4only for ifHighSpeed.7 -> 100 Mb/s
--base: snmpget
public@123.123.123.123:::::2:v4only for ifHCInOctets.7 -> 1120902719935
--base: check for HighspeedCounters failed ... Dropping back to V1
--base: Writing /home/mrtg/cfg/test.cfg

[root@mrtg cfg]#

보안상 내가 설치한 서버의 정보는 공개하지 않았다.
--global Workdir:/home/mrtg/data는 MRTG의 작업 디렉토리를 지정 하는 것이다. 이 때 MRTG는 MRTG의 로그 파일 및 웹 페이지 작업을 디렉토리에 생성한다.
--global 'Options[_]:growright,bits'는 MRTG 그래프에서 트래픽에 관한 표시를 Bit per Second로 하여 X축의 시간 증가가 오른쪽임을 의미한다.
output=/home/cfg/test.cfg는 cfgmaker를 통하여 생선한 cfg 파일 저장 경로와 파일의 이름을 의미한다.
public@123.123.123.123:::::2는 트래픽 정보를 수집하는 라우터에 관한 정보로 123.123.123.123은 라우터 IP의 정보이며, public은 community를 통해 SNMP Request로 접근함을 의미한다. :::::2는 SNMP v2로 접근하는 것을 의미한다.




STEP 2.

MRTG를 주기적으로 라우터의 트래픽 정보를 수집하는 것은 cron을 이용하여 주기적으로 MRTG를 실행시키는 방법과 MRTG의 데몬 모드로 실행시켜 주기적으로 데이터를 수집 할 수 있다.

cron을 통해 주기적으로 실행시키면 실행을 할 때 마다 MRTG cfg 파일을 읽어 초기화 하는 단점이 있기 때문에 MRTG 데몬 모드를 실행하는 것이 더 효율적이어서 MRTG 데몬 모드로 실행하는 방법을 설명하겠다.

[root@mrtg cfg]# vi test.cfg
# Created by
# /usr/local/mrtg-2/bin/cfgmaker --global Workdir:/home/mrtg/data --global 'Options[_]:growright,bits' --output=/home/mrtg/cfg/test.cfg
public@123.123.123.123:::::2


### Global Config Options

#  for UNIX
# WorkDir: /home/http/mrtg

#  or for NT
# WorkDir: c:\mrtgdata

### Global Defaults

#  to get bits instead of bytes and graphs growing to the right
# Options[_]: growright, bits

EnableIPv6: no
Workdir:/home/mrtg/data
Options[_]:growright,bits

######################################################################
# System: Cisco-Router
# Description: Cisco Internetwork Operating System Software


test.cfg 파일을 열었을 경우 위와 같은 설정으로 생성이 되어있다.
여기에 RusAsDaemon과 이 데몬이 실행 될 주기를 입력하면 된다.

# Created by
# /usr/local/mrtg-2/bin/cfgmaker --global Workdir:/home/mrtg/data --global 'Options[_]:growright,bits' --output=/home/mrtg/cfg/test.cfg
public@123.123.123.123:::::2


### Global Config Options

#  for UNIX
# WorkDir: /home/http/mrtg

#  or for NT
# WorkDir: c:\mrtgdata

### Global Defaults

#  to get bits instead of bytes and graphs growing to the right
# Options[_]: growright, bits

EnableIPv6: no
Workdir:/home/mrtg/data
Options[_]:growright,bits
RunAsDaemon: Yes
Interval: 3


######################################################################
# System: Cisco-Router
# Description: Cisco Internetwork Operating System Software


RunAsDaemon을 Yes로 하고, Interval에서 3으로 3분 주기로 설정을 하였다.



MRTG를 실행 시키는 방법은 아래와 같다.
[root@mrtg cfg]# mrtg /home/mrtg/cfg/test.cfg --logging /home/mrtg/log/test.log
Daemonizing MRTG ...
[root@mrtg cfg]#

MRTG가 제대로 실행되고 있는지 확인 해 본다.
[root@mrtg cfg]# ps aux | grep mrtg
avahi     2804  0.0  0.0   2592  1344 ?        Ss   11:55   0:00 avahi-daemon: running [mrtg.local]
root      6764  1.1  0.2  12316 10248 ?        Ss   16:22   0:00 /usr/bin/perl -w /usr/local/mrtg-2/bin/mrtg /home/mrtg/
cfg/test.cfg --logging /home/mrtg/log/test.log
root      6815  0.0  0.0   1844   528 pts/1    S+   16:23   0:00 grep mrtg

[root@mrtg cfg]#



서버를 재부팅 할 경우 MRTG를 실행하기 위해서는 /etc/rc.local 파일에 MRTG를 실행시키는 스크립트를 추가하면, 서버가 혹시라도 재부팅 되는 경우가 발생하더라도 자동으로 MRTG가 실행 될 것이다.

[root@mrtg cfg]# vi /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
LANG=C
/usr/local/apache/bin/apachectl start


아래와 같이 스크립트를 추가한다.

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
LANG=C
/usr/local/apache/bin/apachectl start

mrtg /home/mrtg/cfg/test.cfg --logging /home/mrtg/log/test.log





STEP 3.

MRTG로 수집한 트래픽 정보를 RRDTool에 저장을 하면 MRTG의 동작 속도를 향상 시킬 수 있으며, RRDTool의 경우 일정한 용량의 데이터로 수집하고 저장하기 때문에 서버의 용량이 크게 작용하지 않는 장점을 가지고 있다.
물론 시간이 많이 지나게되면, 처음에 수집한 데이터 값을 일정한 시간의 평균 값으로 저장하기 때문에 실제 데이터와 차이를 보이는 단점은 있다.

MRTG에서 수집한 트래픽 정보를 RRD에 저장하기 위해서 MRTG cfg 파일 내에 로그파일 형식을 RRDTool로 선언하는 항목을 추가하면된다. 또, MRTG에서 RRDTool을 이용하기 위해서는 RRDs.pm이라는 RRDTool의 perl모듈이 필요하며 RRDTool을 실행 할 수 있어야 한다.

[root@mrtg cfg]# vi test.cfg
# Created by
# /usr/local/mrtg-2/bin/cfgmaker --global Workdir:/home/mrtg/data/ --global 'Options[_]:growright,bits' --output=/home/mrtg/cfg/test.cfg
public@123.123.123.123:::::2


### Global Config Options

#  for UNIX
# WorkDir: /home/http/mrtg

#  or for NT
# WorkDir: c:\mrtgdata

### Global Defaults

#  to get bits instead of bytes and graphs growing to the right
# Options[_]: growright, bits

EnableIPv6: no
WorkDir:/home/mrtg/data
icondir:/images/mrtg
Options[_]:growright,bits
RunAsDaemon: Yes
Interval: 3

######################################################################
# System: Cisco-Router
# Description: Cisco Internetwork Operating System Software


아래와 같이 추가한다.

# Created by
# /usr/local/mrtg-2/bin/cfgmaker --global Workdir:/home/mrtg/data/ --global 'Options[_]:growright,bits' --output=/home/mrtg/cfg/test.cfg
public@123.123.123.123:::::2


### Global Config Options

#  for UNIX
# WorkDir: /home/http/mrtg

#  or for NT
# WorkDir: c:\mrtgdata

### Global Defaults

#  to get bits instead of bytes and graphs growing to the right
# Options[_]: growright, bits

EnableIPv6: no
WorkDir:/home/mrtg/data
icondir:/images/mrtg
Options[_]:growright,bits
RunAsDaemon: Yes
Interval: 3

PathAdd: /usr/local/rrdtool-1.2.12/bin/
LibAdd: /usr/local/rrdtool-1.2.12/lib/perl/5.8.8/i386-linux-thread-multi/
LogFormat: rrdtool

######################################################################
# System: Cisco-Router
# Description: Cisco Internetwork Operating System Software






STEP 4.

MRTG-RRD는 CGI/FastCGI로 개발된 RRDTool 형태의 데이터로부터 MRTG 그래프를 생성하는 스크립트이다.

MRTG를 이용하여 그래프를 생성하는 스크립트를 받는다.
이 스크립트는 매 5분마다 PNG파일을 생성하지 않아 MRTG를 이용한 모니터링 시스템의 성능을 향상 시킨다.

[root@mrtg cfg]#  cd /usr/local/rrdbuild
[root@mrtg rrdbuild]# lftpget ftp://ftp.linux.cz/pub/linux/people/jan_kasprzak/mrtg-rrd/mrtg-rrd-0.7.tar.gz
[root@mrtg mrtg-rrd-0.7]# cp * /usr/local/apache/cgi-bin/
[root@mrtg cfg]# cd /usr/local/apache/cgi-bin/
[root@mrtg cgi-bin]# vi mrtg-rrd.cgi

# Location of RRDs.pm, if it is not in @INC
# use lib '/usr/lib/perl5/5.00503/i386-linux';
use RRDs;

use vars qw(@config_files @all_config_files %targets $config_time
        %directories $version $imagetype);

# EDIT THIS to reflect all your MRTG config files
BEGIN { @config_files = qw(/home/fadmin/mrtg/cfg/mrtg.cfg); }

$version = '0.7';

아래와 같이 변경한다.

# Location of RRDs.pm, if it is not in @INC
use lib '/usr/local/rrdtool-1.2.12/lib/perl/5.8.8/i386-linux-thread-multi';

use RRDs;

use vars qw(@config_files @all_config_files %targets $config_time
        %directories $version $imagetype);

# EDIT THIS to reflect all your MRTG config files
BEGIN { @config_files = qw(/home/mrtg/cfg/test.cfg); }

$version = '0.7';

RRDs.pm 모듈에 대한 경로 설정 및 mrtg.cfg 파일의 경로를 지정한 것이다.
현재 내가 설치 한 서버에서는 /usr/local/rrdtool-1.2.12/lib/perl/5.8.8/i386-linux-thread-multi에 RRDs.pm 모듈이 존재하며, cfg 파일은 /home/mrtg/cfg에 rrd 파일은 /home/mrtg/data에 마지막으로 log 파일은 /home/mrtg/log에 저장 할 것이다. BEGIN { @config_files = qw(/home/mrtg/cfg/mrtg.cfg); } 의 위치는 각자 자신이 저장할 위치에 맞춰서 저장하면 될 것이다.


이제 웹브라우저를 실행시켜 웹으로 접속을 해 보겠다.


올바른 경로로 접속을 하였지만 기대했던 그래프는 나오지 않고, Error 메시지가 우리를 반긴다.
test.cfg가 저장 된 /home/mrtg 디렉토리가 사용자만 사용 할 수 있기 때문에 현재 권한이 없다고 나오는 것이다.

[root@mrtg home]# ls -al
total 48
drwxr-xr-x  6 root    root     4096 Mar 23 13:44 .
drwxr-xr-x 23 root    root     4096 Mar 25 11:55 ..
drwx------  3 celltwo celltwo  4096 Mar 25 16:38 celltwo
drwx------  2 root    root    16384 Mar 23 10:26 lost+found
drwx------  6 mrtg    mrtg     4096 Mar 25 16:38 mrtg

[root@mrtg home]#

웹에서 디렉토리에 접근하여 볼 수 있게 접근 권한을 변경한다.

[root@mrtg home]# chmod 777 mrtg/
[root@mrtg home]# ls -al
total 48
drwxr-xr-x  6 root    root     4096 Mar 23 13:44 .
drwxr-xr-x 23 root    root     4096 Mar 25 11:55 ..
drwx------  3 celltwo celltwo  4096 Mar 25 16:38 celltwo
drwx------  2 root    root    16384 Mar 23 10:26 lost+found
drwxrwxrwx  6 mrtg    mrtg     4096 Mar 25 16:38 mrtg

[root@mrtg home]#


/home/mrtg 안에 설치 할 때 만든 cfg, data, log 디렉토리가 있을 것이다. (다르게 설치했다면, 그 설정에 맞출 것)
하위 디렉토리도 그에 맞게 설정을 변경을 하여야 한다.

[root@mrtg home]# cd mrtg/
[root@mrtg mrtg]# chmod 755 cfg
[root@mrtg mrtg]# chmod 755 log
[root@mrtg mrtg]# chmod 777 data


cfg와 log는 읽고 실행만 가능하게 해줬는데 data 디렉토리만 읽고 쓰고 실행 모든 권한을 다 줬는지 궁굼할 것이다.
MRTG가 RRDTool에서 데이터를 불러와 그래프로 표현 할 때 쓰기 권한이 없으면 그래프를 생성 할 수 없기 때문에 모든 권한을 다 열어 준 것이다.

이제 설정이 완료 되었으므로 웹브라우저를 새로고침 해 본다.


이제부터는 5분마다 그래프를 그리며 라우터의 트래픽을 보여 줄 것이다.




'Linux tools > MRTG' 카테고리의 다른 글

MRTG서버에 Weathermap 설치 및 사용하기  (0) 2010.03.26
MRTG 설치 방법  (0) 2010.03.23
블로그 이미지

쭈꾸댕이

아직 어설픈 실력으로 나름 제가 하는 것에 대한 것들을 옮기는 공간입니다. 틀린 부분도 있을 수 있으니 이 점 양해하시고, 도움이 되셨으면 좋겠네요.

,