모니터링

장애 발생시에 신속한 원인을 규명하는데 사용될 수 있다.

Opsview

nrpe

nsca

Nagios의 Passive Check를 사용하는 방법이다. 일단 NSCA를 추가로 설치해야 한다.

Using NSCA with Opsview
http://docs.opsview.org/doku.php?id=opsview-community:nsca

Opsview 서버에 NSCA 2.7.2를 설치하고 5668로 데몬을 띄운다. 5667은 이미 nagios에서 사용하고 있다.

wget http://cdnetworks-kr-2.dl.sourceforge.net/project/nagios/nsca-2.x/nsca-2.7.2/nsca-2.7.2.tar.gz
tar xvfz nsca-2.7.2.tar.gz
cd nsca-2.7.2
yum install gcc make libmcrypt
./configure --with-nsca-port=5668
make all
make install

실행

/usr/local/nagios/bin/nsca -c /usr/local/nagios/etc/nsca.cfg

설정파일

/usr/local/nagios/etc/nsca.cfg

nsca debug 옵션을 키고 messages로그

Nov 3 17:49:42 sa nsca[23844]: Handling the connection...
Nov 3 17:49:43 sa nsca[23844]: SERVICE CHECK -> Host Name: 'top-backup', Service Description: 'passive_test', Return Code: '2', Output: 'CRITICAL'
Nov 3 17:49:43 sa nsca[23844]: End of connection...

EPEL repo를 사용하여, 대상(client) 서버쪽에 nsca-client를 설치하고 설정한다.

yum install nsca-client

간단히 테스트를 해보자.

echo -e "top-backup\tpassive_test\t2\tCRITICAL\n" | send_nsca -H 모니터링서버IP주소 -p 5668 -c /etc/nagios/send_nsca.cfg

1 data packet(s) sent to host successfully.

서버\t서비스이름\t코드\t\레벨\

/etc/nagios/send_nsca.cfg

password=wnsrns
encryption_method=2

Munin

장점 : 간편한 설치, 깔끔한 그래프, 다양한 플러그인 지원

단점 : 기간 검색 안됨(1 day, 1 week, 1 month, 1 year 단위로만 조회)

설치참조 : http://thuannvn.blogspot.com/2009/06/howto-install-munin-on-centos.html

munin 데모 : http://h1550830.stratoserver.net/munin/stratoserver.net/index.html

CentOS 5.3 i386 기준으로 작성하고 테스트하였음

패키지 설치 준비

rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm

rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.i386.rpm

서버 설치

패키지 설치

yum -y install httpd

yum -y install munin

yum -y install munin-node

서버쪽 설정

vi /etc/munin/munin.conf

[localhost-server] // munin 서버에서 사용될 이름을 지정한다.

address 127.0.0.1

use_node_name yes

노드(클라이언트) 설정 // munin 서버 자체를 모니터링 하기 위해서

vi /etc/munin/munin-node.conf

host_name localhost-server // munin 서버에서 사용될 이름을 지정한다.

munin 시작

/etc/rc.d/init.d/munin-node start

chkconfig munin-node on

잘 전송되는지 tail -f /var/log/munin/munin-node.log 해서 로그를 확인한다.

2009/10/14-17:35:01 CONNECT TCP Peer: "127.0.0.1:37109" Local: "127.0.0.1:4949"

2009/10/14-17:40:01 CONNECT TCP Peer: "127.0.0.1:57802" Local: "127.0.0.1:4949"

이렇게 나온다면 정상.

시간이 조금 지난 후에(데이타가 저장되면) http://localhost/munin 에서 확인

노드(클라이언트) 추가

패키지 설치

yum install munin-node

노드 설정

vi /etc/munin/munin-node.conf

host_name localhost2 // munin 서버에서 사용될 이름을 지정한다.

allow ^192\.168\.0\.4$ // munin 서버를 지정한다.

munin-node 시작

/etc/rc.d/init.d/munin-node start

chkconfig munin-node on

마지막으로 서버 /etc/munin/munin.conf 에서 노드를 추가해준다.

[localhost-server]

address 127.0.0.1

use_node_name yes

// 아래와 같이 /etc/munin/munin-node.conf 수정할때 입력한 host_name과 맞추어서 추가하면 된다.

[localhost2]

address 192.168.0.5

use_node_name yes

잘 전송되는지 tail -f /var/log/munin/munin-node.log 해서 로그를 확인한다.

2009/10/14-17:35:01 CONNECT TCP Peer: "192.168.0.4:33896" Local: "192.168.0.5:4949"

2009/10/14-17:40:01 CONNECT TCP Peer: "192.168.0.4:34895" Local: "192.168.0.5:4949"

이렇게 나온다면 정상.

업데이트가 잘 되는 지 tail -f /var/log/munin/munin-update.log 해서 로그를 확인한다.

Oct 14 18:35:06 [4955] - Fetched service: localhost-server -> memory (0.08 sec)

Oct 14 18:35:07 [4955] - Fetched service: localhost-server -> vmstat (1.06 sec)

Oct 14 18:35:07 [4955] - Fetched node: localhost-server (4.71 sec)

Oct 14 18:35:01 [4954] - Processed node: localhost2 (0.01 sec)

Oct 14 18:35:01 [4954] - Processed domain: localhost2 (0.01 sec)

Oct 14 18:35:07 [4954] - connection from localhost2 -> localhost2 (4957)

Oct 14 18:35:07 [4954] - connection from localhost2 -> localhost2 (4957) closed

Oct 14 18:35:07 [4954] - connection from localhost-server -> localhost-server (4955)

Oct 14 18:35:07 [4954] - connection from localhost-server -> localhost-server (4955) closed

Oct 14 18:35:07 [4954] - Munin-update finished (6.43 sec)

이렇게 나온다면 정상.

만약 같은 도메인으로 분류할려면 서버의 /etc/munin/munin.conf에서 다음과 같이 추가한다.

위에서도 말했다시피 노드에 등록한 이름과, 서버에 등록한 이름이 같아야 한다. (당연!)

[testdomain;localhost-server]

address 192.168.0.4

use_node_name yes

[testdomain;localhost2]

address 192.168.0.5

use_node_name yes

플러그인 사용

1. 아파치 모니터링

아파치 웹서버를 모니터링 할려면

ln -s /usr/share/munin/plugins/apache_* /etc/munin/plugins/

해서 플러그인을 쓸수 있도록 하고,

아파치 설정에서도 server-status 를 사용할 수 있도록 수정한다.

ExtendedStatus On

<Location /server-status>

SetHandler server-status

Order deny,allow

Deny from all

Allow from 127.0.0.1

</Location>

마지막으로 service munin-node restart 를 하여 적용시킨다. 시간이 지나면 모니터링화면에서 갱신되어 볼 수 있다.

2. MySQL 모니터링(테스트 진행중)

ln -s /usr/share/munin/plugins/mysql_* /etc/munin/plugins/

If your root user has a password (or want to use a different user),

edit the plugin configuration file in /etc/munin/plugin-conf.d/munin-node and

uncomment line 16 by removing the leading hash (#).

Then change the parameters that will be used when mysqladmin is run.

그외 플러그인 다운로드

http://muninexchange.projects.linpro.no

설치방법은 위에서도 알겠지만 /etc/munin/plugins/ 에 해당 플러그인을 복사하거나 링크를 걸어주면 된다.

자세한 것들은 각 플러그인의 README 문서등을 확인하자.

munin 모니터링 페이지 보안

서버에서 httpd.conf 에 다음 내용 추가

<Directory "/var/www/html/munin">

Options -Indexes FollowSymLinks

AllowOverride All

Allow from all

</Directory>

/var/www/html/munin/.htaccess 파일 작성

AuthType Basic

AuthName "Members Only"

AuthUserFile /var/www/html/munin/.mypasswd

<limit GET PUT POST>

require valid-user

</limit>

/var/www/html/munin/.mypasswd 파일 작성

[root@localhost munin]# htpasswd -c /var/www/html/munin/.mypasswd admin

New password:

Re-type new password:

Adding password for user admin

[root@localhost munin]# cat .mypasswd

admin:WOQyFQnaXXA4E

오류 수정

설정에 이상이 없는데도 그래프가 그려지지 않으면(정확히는 png 파일이 생성이 안되면), 완전히 삭제하고 재설치해본다.

yum remove munin munin-node

rm -rf /etc/munin/

rm -rf /var/log/munin/

rm -rf /var/www/html/munin/

rm -rf /var/run/munin/

방화벽에 막혀서 그럴수 도 있으나 tcpdump나 telnet 호스트명 4949 로 열려있는지 확인

서버에서 :

tcpdump host 노드IP

15:45:06.026183 IP 192.168.0.4.56021 > 192.168.0.5.munin: . ack 18168 win 501 <nop,nop,timestamp 856234716 2614717493>

15:45:06.026283 IP 192.168.0.5.munin > 192.168.0.4.56021: P 18168:18536(368) ack 850 win 46 <nop,nop,timestamp 2614717533 856234716>

15:45:06.026299 IP 192.168.0.4.56021 > 192.168.0.5.munin: . ack 18536 win 501 <nop,nop,timestamp 856234716 2614717533>

15:45:06.028062 IP 192.168.0.4.56021 > 192.168.0.5.munin: F 850:850(0) ack 18536 win 501 <nop,nop,timestamp 856234718 2614717533>

15:45:06.028300 IP 192.168.0.5.munin > 192.168.0.4.56021: F 18536:18536(0) ack 851 win 46 <nop,nop,timestamp 2614717535 856234718>

15:45:06.028316 IP 192.168.0.4.56021 > 192.168.0.5.munin: . ack 18537 win 501 <nop,nop,timestamp 856234718 2614717535>

이렇게 통신을 주고 받으면 정상.

[root@ns2 ~]# telnet 192.168.0.6 4949

Trying 192.168.0.6...

Connected to 192.168.0.6 (192.168.0.6).

Escape character is '^]'.

  1. munin node at localhost2

이렇게 나오면 정상.

로그에 아래와 같이 찍힌다면 (확인중)

Use of uninitialized value in eval {block} exit at /usr/sbin/munin-node line 385, <CHILD> line 17.

http://osdir.com/ml/db.rddtool.munin.general/2008-02/msg00059.html

을 보면 FQDN으로 hostname을 입력하라고 나온다. 다음 것도 보자. 제대로된 hostname을 지정하면 된단다.

http://charles.lescampeurs.org/2009/03/11/munin-and-use-of-uninitializer-value-in-eval

좀더 발전적인 참고 자료

http://waste.mandragor.org/munin_tutorial/munin.html

http://wiki.kartbuilding.net/index.php/Munin_Statistics

http://www.arnebrodowski.de/blog/improving-munin-snmp-performance.html

임계값이 넘어가면 메일로 통보받거나, nagios로 연동되는 건 나중에 해보자.

아주 중요한 내용을 설명하지 못하였다. 바로 그래프의 내용을 어떻게 볼것인가다.

이건 시스템관리를 하는 사람이라면...알고 있거나 알아가는 과정일테니 뒤로 미루자. 나는 후자다.

참고로 각 항목별 페이지 하단에 잘 설명되어 있다.

atop

rsyslog 중앙 로그 서버