MON 은 이벤트를 이용해서 서비스에 대한 사용을 모니터링하는 모듈이다. 자기자신뿐만 아니라 상대방에 대해 ping 프로그램을 이용해서 모니터링하는것과 같은 간단한 경우에서부터 DB부터 각종 서비스까지 가능한 모니터링 모듈로써 이후 작업을 진행하게끔 해주는 모니터링툴입니다.
Heartbeart 나 DRBD, ipvsadm 과 같이 사용하시면 무중단서비스 구성에 유용합니다.
좀더 자세한 INSTALL 방법은 MON 소스 압축을 풀어보시면 INSTALL 파일을 참조하세요.
OVERVIEW
--------
There are several components you'll need to get working to
have a fully functional mon installation.
1. mon, the server
2. Mon::Client, the Perl library used by some clients
3. C programs in mon.d
4. Optional (but highly useful) monitors
5. A customized mon.cf to make the server do what you want
# 다운로드 2010. 02.04 일 현재....1.2.0 이 최신이네요...
ftp://ftp.kernel.org/pub/software/admin/mon/mon-1.2.0.tar.gz설치하기 위해서는 perl 모듈이 필요하며 5.005_01 이상에서 작동이 된다.
perl 모듈을 설치하기 이전에 C 헤더 파일에 대응하는 perl 헤더파일을 만들어야 된다.
[root@node1 mon]# cd /usr/include
[root@node1 mon]# h2ph -r -l .
위 명령어를 실행시키면 xxx.h -> xxx.ph 등의 메세지와 함께 변환이 된다.
다음 필요로 하는 perl 모듈을 설치한다.
Time::Period PRYAN/Period-1.20.tar.gz
Time::HiRes J/JH/JHI/Time-HiRes-1.59.tar.gz
파일은 wget 을 통해서 다운로드 하시면 됩니다.
이제는 mon 소스를 다운로드 하셔서 설치한다.
※ 압축을 풀어보면 디렉토리 구조는 아래와 같습니다.
mon ---- alert.d : 각종 alert 데몬이 들어있는 디렉토리
clients : mon 클라이언트 데몬이 있는 디렉토리
doc : 메뉴얼이 들어있는 디렉토리
etc : 설정화일이 들어있는 디렉토리
mon.d : 모니터링 프로그램이 들어있는 디렉토리
muxpect : 멀티플렉스 TCP라는 기능을 위해 개발되어지고 있는 프로그램
state.d : pid 가 들어갈 자리
utils : mon 용 유틸리티가 들어있는 자리
모니터링 데몬 (mon/mon.d 폴더내 존재)
freespace.monitor : 디스크의 용량을 파악하는 모니터링 데몬/ Filesys::DiskSpace 필요
fping.monitor : 상대의 서버가 ping 에 응답하는지 확인하는 툴
telnet.monitor : 텔넷접속상태를 확인하는 모니터링 데몬 / Net::Telnet 모듈
reboot.monitor
asyncreboot.monitor
netappfree.monitor
process.monitor
hpnp.monitor
ldap.monitor : Net:LDAPapi 모듈을 필요
dialin.monitor : 전화 걸어보는 건가..? Perl Expect 모듈이 필요하다네요...모지 이건..
dns.monitor : dns 를 검사하는 모니터링 데몬 / 모듈은 Net:DNS 를 필요
msql-mysql.monitor : msql 이나 mysql 서비스 모니터링 / MSQL, MySQL DBD 모듈과 DBI 모듈이 필요
기본파일을 /etc/mon/ 디렉토리로 복사한다.
[root@node1 mon-1.2.0]# mkdir /etc/mon
[root@node1 mon-1.2.0]# cp etc/example.cf /etc/mon/mon.cf
[root@node1 mon-1.2.0]# cp etc/auth.cf /etc/mon/auth.cf
/etc/service 파일에 해당 서비스 포트를 등록한다.
mon 2583/tcp #MON
mon 2583/udp #MON traps
설치는 이로써 끝이다...이제는 설정을 잡아주기 위한 cf 파일 수정만 해주면 된다.
- example.cf 파일을 참조해서 생성하면 된다.
- /etc/mon.cf (테스트용도라면 아래처럼 만들어서 확인해보면 된다.)
cfbasedir = /etc/mon
alertdir = /usr/local/src/mon-1.2.0/alert.d
mondir = /usr/local/src/mon-1.2.0/mon.d
maxprocs = 20
histlength = 100
randstart = 30s
authtype = getpwnam
hostgroup node2 218.236.115.226 # 모니터링 대상서버
watch node2
service http # 모니터링 서비스
interval 5s # 모니터링 간격
monitor http.monitor # 참조파일
period wd {Sun-Sat} # 모니터링 기간 (요일/시간)
alert echo.alert "node2 server is down!!" # 실행파일 및 메세지
upalert echo.alert "node2 server is live!!"
- 간단히 로그를 남겨서 서비스 모니터링 여부를 판단하기 위한 echo 파일을 하나 만들어준다.
작동하는 시간을 /var/log/echo.alert.log 라는 파일에 로깅!
- 다른 파일과 퍼미션을 동일하게 755
[root@node1 alert.d]# pwd
/usr/local/src/mon-1.2.0/alert.d
[root@node1 alert.d]# cat echo.alert
#!/bin/sh
echo "`date`$*" >> /var/log/echo.alert.log;
[root@node1 alert.d]# chmod 755 echo.alert.log
==> 이부분에 서비스 down/up 시 작업해야될 스크립트를 만들어 두면....무중단 서비스 구성을 할수 있다.
서비스실행
[root@node1 root]# /usr/local/src/mon-1.2.0/mon -f -c /etc/mon/mon.cf
프로세서를 실행되어진 상태 (ps -aux)
root 3957 0.0 1.0 50812 8764 ? S Feb04 0:05 /usr/bin/perl /usr/local/src/mon-1.2.0/mon -f -c /etc/mon/mon.cf
※ -c config config file, defaults to "mon.cf"
-f fork and become a daemon
- node2 (218.236.115.226) 아파치 데몬을 stop / start 시키면서 로깅을 확인해본다.
/var/log/echo.alert.log
Thu Feb 4 17:04:06 KST 2010-s http -g node2 -h 218.236.115.226 -t 1265270646 node2 server is down!!
Thu Feb 4 17:04:11 KST 2010-s http -g node2 -h 218.236.115.226 -t 1265270651 node2 server is down!!
Thu Feb 4 17:04:16 KST 2010-s http -g node2 -h 218.236.115.226 -t 1265270656 -u node2 server is live!!
Thu Feb 4 17:07:28 KST 2010-s http -g node2 -h 218.236.115.226 -t 1265270848 node2 server is down!!
Thu Feb 4 17:07:34 KST 2010-s http -g node2 -h 218.236.115.226 -t 1265270854 node2 server is down!!
Thu Feb 4 17:07:39 KST 2010-s http -g node2 -h 218.236.115.226 -t 1265270859 node2 server is down!!
Thu Feb 4 17:07:44 KST 2010-s http -g node2 -h 218.236.115.226 -t 1265270864 node2 server is down!!
Thu Feb 4 17:07:49 KST 2010-s http -g node2 -h 218.236.115.226 -t 1265270869 -u node2 server is live!!
Thu Feb 4 17:33:09 KST 2010-s http -g node1 -h 218.236.115.225 -t 1265272389 node1 server is down!!
Thu Feb 4 17:33:15 KST 2010-s http -g node1 -h 218.236.115.225 -t 1265272395 node1 server is down!!
Thu Feb 4 17:33:20 KST 2010-s http -g node1 -h 218.236.115.225 -t 1265272400 node1 server is down!!
Thu Feb 4 17:33:25 KST 2010-s http -g node1 -h 218.236.115.225 -t 1265272405 node1 server is down!!
마지막으로 mon 데몬을 올리고 내리기 쉽게 스크립트로 만들어둬서 사용한다.
- /etc/init.d/mon (퍼미션은 755)
#!/bin/bash
MON_HOME=/usr/local/src/mon-1.2.0 # 본인이 설치한 폴더위치
MON_CF=/etc/mon # mon.cf 설정파일이 들어갈 위치
case "$1" in
start)
if [ -f $MON_HOME/mon.pid ]; then
echo "mon already started"
exit
fi
echo "Starting Mon"
$MON_HOME/mon -c $MON_CF/mon.cf -L $MON_HOME -P $MON_HOME/mon.pid &
;;
stop)
if [ -f $MON_HOME/mon.pid ]; then
echo "Stopping Mon"
kill -9 `cat $MON_HOME/mon.pid`
rm -f $MON_HOME/mon.pid
else
echo "no server pid, server doesn't seem to run"
fi
;;
status)
echo "doing good"
;;
*)
echo "Usage: $0 {start|stop|status|reload|restart}"
exit 1
esac
exit 0