munin 패키지를 사용해서 서버 모니터링 설정하기
💡 요약 정리
- munin은 서버 상태를 그래픽으로 모니터링할 수 있는 도구입니다.
- rpmforge 저장소를 추가하여 설치해야 하며, munin-server와 munin-node가 필요합니다.
- 설정 후 Apache 가상호스트를 구성하여 웹에서 결과를 볼 수 있습니다.
- 클라이언트는 munin-node만 설치하면 됩니다.
1. munin 서버 설정
일반적인 yum 저장소에는 munin 패키지가 없기 때문에, rpmforge 저장소를 별도로 추가해야 합니다.
아래는 rpmforge.repo 설정 예시입니다.
[root@localhost ~]cat /etc/yum.repos.d/rpmforge.repo
# Name: RPMforge RPM Repository for Red Hat Enterprise 5 - dag
# URL: http://rpmforge.net/
[rpmforge]
name = Red Hat Enterprise $releasever - RPMforge.net - dag
#baseurl = http://apt.sw.be/redhat/el5/en/$basearch/dag
mirrorlist = http://apt.sw.be/redhat/el5/en/mirrors-rpmforge
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge
enabled = 1
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 0
2. munin, munin-node 패키지 설치
- yum을 이용해 패키지 설치를 진행합니다. (rrdtool 등을 포함한 의존성 패키지 자동 설치됩니다.)
[root@localhost ~]yum install munin munin-node
- 설치 후 데몬의 실행 여부를 확인합니다.
[root@localhost ~]chkconfig --list | grep munin
munin-node 0:off 1:off 2:on 3:on 4:on 5:on 6:off
3. /etc/munin/munin.conf 수정
htmldir값을 웹에서 확인 가능한 디렉터리로 변경합니다.- 파일 중간의
localhost항목 아래에 모니터링할 타 서버 IP를 동일한 형식으로 추가합니다.
[root@localhost ~]vi /etc/munin/munin.conf
예시:
dbdir /var/lib/munin
htmldir /home/munin
#htmldir /var/www/munin
logdir /var/log/munin
rundir /var/run/munin
[localhost]
address 127.0.0.1
use_node_name yes
[www]
address 192.168.0.51
use_node_name yes
4. /etc/munin/munin-node.conf 파일 확인
- 이 파일은 모니터링 클라이언트 설정 파일입니다.
- 서버가 자신을 모니터링하려면
munin-node도 설치해야 합니다. - 해당 파일 마지막 부분에
localhost외에도 munin 서버의 IP를 추가해야 합니다.
[root@localhost ~]vi /etc/munin/munin-node.conf
예시:
allow ^127.0.0.1$
allow ^192.168.0.47$
- 설정 후,
munin-node데몬을 재시작합니다.
[root@localhost ~]/etc/init.d/munin-node restart
Stopping Munin Node agents: [ OK ]
Starting Munin Node: [ OK ]
5. Apache 가상호스트 설정
munin.conf에서 설정한htmldir디렉터리를 Apache의DocumentRoot로 지정합니다.htmldir소유권을munin사용자로 변경합니다.
Apache 설정 예시:
<VirtualHost *:80>
ServerAdmin webmaster@jook.pe.kr
DocumentRoot "/home/munin"
ServerName monitor.jook.pe.kr
ErrorLog "/home/munin/logs/monitor-error.log"
CustomLog "/home/munin/logs/monitor-access.log" common
</VirtualHost>
소유권 변경 명령:
[root@localhost ~]chown munin.munin /home/munin
- 추가로,
htmldir디렉터리 접근 시 로그인 인증을 요구하도록 Apache 인증 설정을 권장합니다.
6. 클라이언트 munin-node 설정
클라이언트 시스템은 munin-server가 아닌 모니터링 대상입니다.
① 클라이언트에 munin-node 설치
[root@localhost ~]yum install munin-node
② /etc/munin/munin-node.conf 수정
- 접근을 허용할 munin server IP를 추가한 후, 데몬을 재시작합니다.
[root@localhost ~]vi /etc/munin/munin-node.conf
예시:
allow ^127.0.0.1$
allow ^192.168.0.47$
데몬 시작:
[root@image1 yum.repos.d]/etc/init.d/munin-node start
Starting Munin Node: [ OK ]
③ 부팅 시 자동 실행 설정
[root@image1 yum.repos.d]chkconfig --list | grep munin
munin-node 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@image1 yum.repos.d]chkconfig munin-node on
[root@image1 yum.repos.d]chkconfig --list | grep munin
munin-node 0:off 1:off 2:on 3:on 4:on 5:on 6:off
④ 웹에서 결과 확인
- 5분에 한 번 cron을 통해 데이터를 수집하기 때문에, 설정이 완료된 후에는 약간의 대기 시간이 필요합니다.
- 웹 브라우저를 통해 가상호스트 주소(monitor.example.com 등)에 접속하여 결과를 확인합니다.