MRTG 설치

“리눅스 로컬호스트의 간단한 모니터링에 유용한 MRTG 설치 매뉴얼 입니다.


1. 준비사항

CentOS, APM 이 설치되어 있어야 합니다.

2. snmp 설치
1) snmp 설치

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

2) /etc/snmp/snmpd.conf 설정

# First, map the community name “public” into a “security name”
# sec.name source community
#com2sec notConfigUser  default       public
com2sec fserver             127.0.0.1      community

# Second, map the security name into a group name:
#        groupName      securityModel securityName
#group   notConfigGroup v1            notConfigUser
#group   notConfigGroup v2c           notConfigUser
group    fgroup         v1      fserver
group    fgroup         v2c    fserver

# Third, create a view for us to let the group have rights to:
# Make at least snmpwalk -v 1 localhost -c public system fast again.
#       name              incl/excl      subtree         mask(optional)
#view    systemview     included   .1.3.6.1.2.1.1
#view    systemview     included   .1.3.6.1.2.1.25.1.1
view     all           included   .1

# Finally, grant the group read-only access to the systemview view.
#       group           context sec.model sec.level prefix read   write  notif
#access  notConfigGroup “”      any       noauth    exact  systemview none none
access   fgroup         “”      any        noauth    exact  all        none none

3. MRTG 설치

[root@localhost ~] # cd /usr/src
[root@localhost src] # wget http://oss.oetiker.ch/mrtg/pub/mrtg-2.17.4.tar.gz
[root@localhost src] # tar xvfz mrtg-2.17.4.tar.gz
[root@localhost src] # cd mrtg-2.17.4
[root@localhost mrtg-2.17.4] #
./configure –with-gd=/usr/local/gd –with-z=/usr/local/zlib –with-png=/usr/local/libpng
[root@localhost mrtg-2.17.4] # make
[root@localhost mrtg-2.17.4] # make install

4. MRTG 설정
1) 웹설정 (<Directory> 설정)

[root@localhost ~] # adduser mrtg
[root@localhost ~] # mkdir /home/mrtg/public_html
[root@localhost ~] # mkdir /home/mrtg/public_html/localhost
[root@localhost ~] # mkdir /home/mrtg/conf
[root@localhost ~] # chmod 755 /home/mrtg
[root@localhost ~] # chown mrtg.mrtg /home/mrtg

[root@localhost ~] # vi /etc/httpd/conf/httpd.conf
~ 중략 ~

<IfModule mod_userdir.c>
# UserDir disabled
UserDir public_html
</IfModule>
<Directory /home/*/public_html>
</Directory>
~ 중략 ~

2) cfgmaker
(모니터링할 대상항목의 Config 파일을 생성하는 작업 입니다.)

[root@localhost ~] # cd /usr/local/mrtg-2/bin

[root@localhost bin] #./cfgmaker –global ‘WorkDir: /home/mrtg/public_html/localhost’ –global ‘Options[_]: bits,growright’ –output /home/mrtg/conf/localhost.cfg community@127.0.0.1

3) 모니터링 Config 수정
(/home/mrtg/conf/localhost.cfg 하단부에 추가 합니다.)

### CPU Load Average ###
Target[cpu]: .1.3.6.1.4.1.2021.10.1.5.1&.1.3.6.1.4.1.2021.10.1.5.2:community@127.0.0.1
MaxBytes[cpu]: 2000
#Unscaled[cpu]: dwmy
Options[cpu]: integer, gauge,withzeroes, growright, noinfo, nopercent
YLegend[cpu]: CPU Load Average
ShortLegend[cpu]: (%)
LegendI[cpu]: Aver 1/minite
LegendO[cpu]: Aver 5/min
Legend1[cpu]: Aver 1/minite
Legend2[cpu]: Aver 5/min
Title[cpu]: CPU Load
PageTop[cpu]: </p><h1>CPU Load Average</h1>

### Rate of CPU use ###
Target[cpu_use]: .1.3.6.1.4.1.2021.11.50.0&.1.3.6.1.4.1.2021.11.52.0:community@127.0.0.1
MaxBytes[cpu_use]: 100
Options[cpu_use]: growright, noinfo, nopercent
YLegend[cpu_use]: CPU usage(%)
ShortLegend[cpu_use]: (%)
LegendI[cpu_use]: User
LegendO[cpu_use]: System
Legend1[cpu_use]: CPU usage(User)(%)
Legend2[cpu_use]: CPU usage(System)(%)
Title[cpu_use]: Rate of CPU use
PageTop[cpu_use]: <h1>Rate of CPU use</h1>

### Memory Free ###
Target[mem]: .1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.4.0:community@127.0.0.1
MaxBytes1[mem]: 7513968
MaxBytes2[mem]: 7513968
Unscaled[mem]: dwmy
Options[mem]: gauge, growright, noinfo
YLegend[mem]: Mem Free(Bytes)
ShortLegend[mem]: Bytes
kilo[mem]: 1024
kMG[mem]: k,M,G,T,P
LegendI[mem]: Real
LegendO[mem]: Swap
Legend1[mem]: RAM [MBytes]
Legend2[mem]: Swap Memory [MBytes]
Title[mem]: Memory Free
PageTop[mem]: <h1>Memory Free</h1>

4) indexmaker 및 mrtg 쿼리

 

[root@localhost ~] # cd /usr/local/mrtg-2/bin

[root@localhost bin] # ./indexmaker –title “Localhost” /home/mrtg/conf/localhost.cfg > /home/mrtg/public_html/localhost/index.html

[root@localhost bin] # env LANG=C /usr/local/mrtg-2/bin/mrtg /home/mrtg/conf/localhost.cfg

5. 웹사이트 및 crontab 적용
1) 리다이렉션 페이지 생성

[root@localhost ~] # cat > /home/mrtg/public_hml/index.html
<meta http-equiv=”refresh” content=”1;url=./localhost/index.html”>
^C

2) 모니터링 스크립트 작성 및 crontab 등록

[root@localhost ~] # cat > /script/mrtg.sh
#!/bin/bash
env LANG=C /usr/local/mrtg-2/bin/mrtg /home/mrtg/conf/localhost.cfg
^C

[root@localhost ~] # crontab -e
*/1 * * * * /scripts/mrtg.sh

.끝.

댓글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다