본문으로 건너뛰기

MRTG를 이용한 서버 트래픽 모니터링 방법은 무엇인가요?

💡 요약 정리

  • CentOS 5.x 및 Apache 환경에서 MRTG를 설정해 서버 네트워크 트래픽을 모니터링할 수 있습니다.
  • SNMP 및 MRTG 패키지를 설치하고, 설정 파일을 구성한 후 웹 인터페이스에서 확인 가능합니다.
  • 주요 단계는 패키지 설치, snmp.conf 설정, mrtg 실행, 자동화 설정입니다.

1. 설치 환경

  • CentOS 5.x (32bit)
  • apache 2.2.2 기본 웹소스 디렉토리: /home/mrtg/html

2. 설치 및 설정 절차

1. snmp 패키지 설치

서버에 snmp 관련 패키지를 설치합니다.

[root@localhost /]# yum install net-snmp*

2. MRTG 관련 패키지 설치

yum으로 설치 시 기본 위치는 /var/www/mrtg 입니다.

[root@localhost /]# yum install mrtg*

3. 라이브러리 설치

그래픽 라이브러리가 설치되어 있는지 확인하고, 없다면 다음을 실행합니다.

[root@localhost /]# yum install freetype gd libjpeg libpng

4. /etc/snmp/snmp.conf 파일 수정

snmp.conf 파일을 다음과 같이 수정합니다. 기존 파일은 snmp.conf_old 로 백업 후 작업합니다.

[root@localhost /]# cp -a /etc/snmp/snmp.conf /etc/snmp/snmp.conf_old
[root@localhost /]# vi /etc/snmp/snmp.conf

다음 내용을 참고하여 수정:

  • 기존 com2secgroup 항목 일부 주석 처리
  • 서버 IP에 맞춰 접근 소스 지정 후 public 커뮤니티를 설정
  • view와 access 권한도 사용자 지정으로 변경

해당 예시는 생략되었으나 실제 snmp.conf는 반드시 위 파일 내 관련 항목을 설정해야 합니다.


5. snmp 데몬 재시작

변경된 설정을 적용하기 위해 데몬을 재시작합니다.

[root@localhost /]# /etc/rc.d/init.d/snmpd restart
Stopping snmpd:                                          [  OK  ]
Starting snmpd:                                          [  OK  ]

6. mrtg.cfg 파일 생성

cfgmaker를 이용해 mrtg.cfg 파일을 생성합니다. WorkDir 값은 웹에서 접근 가능한 위치여야 합니다. 예: /var/www/html

[root@localhost /]# cfgmaker --global 'WorkDir: /home/mrtg/html/' --global 'Language: korean' --global 'Options[_]: bits,growright' -output /home/mrtg/html/mrtg.cfg public@서버IP

7. index.html 파일 생성

indexmaker를 이용해 인덱스 파일을 생성합니다. 설정된 웹폴더에 생성되도록 합니다.

[root@localhost /]# indexmaker --title "MRTG TEST" --output /home/mrtg/html/index.htm /home/mrtg/html/mrtg.cfg

8. mrtg 실행

mrtg 명령어를 실행하여 모니터링을 시작합니다.

처음 몇 번은 warning 메세지가 나오더라도 반복 실행 시 정상화됩니다.

[root@localhost /]# /usr/bin/mrtg /home/mrtg/html/mrtg.cfg

16-01-2013 10:39:10, Rateup WARNING: /usr/bin/rateup could not read the primary log file for xxx.xxx.xxx.xxx_2
16-01-2013 10:39:10, Rateup WARNING: /usr/bin/rateup The backup log file for xxx.xxx.xxx.xxx_2 was invalid as well
16-01-2013 10:39:10, Rateup WARNING: /usr/bin/rateup Can't remove xxx.xxx.xxx.xxx_2.old updating log file
16-01-2013 10:39:10, Rateup WARNING: /usr/bin/rateup Can't rename xxx.xxx.xxx.xxx_2.log to 220.73.163.10_2.old updating log file

[root@localhost /]# /usr/bin/mrtg /home/mrtg/html/mrtg.cfg
[root@localhost /]# /usr/bin/mrtg /home/mrtg/html/mrtg.cfg

9. mrtg 자동 실행 설정

crontab을 설정하여 1분마다 자동 실행되도록 설정합니다.

[root@localhost /]# crontab -e
* * * * * /usr/bin/mrtg /home/mrtg/html/mrtg.cfg
[root@localhost /]#

추가 참고사항

  • 생성된 /home/mrtg/html/index.htm 페이지를 웹브라우저로 접근하면 트래픽 그래프를 실시간으로 확인할 수 있습니다.
  • 서버 IP 주소는 실제 모니터링 대상에 맞게 설정해야 하며, 외부 접근이 막혀있을 경우 방화벽 설정도 확인 바랍니다.