ㅇ 설치
지금 설명하는 내용은 nagios 1.1, nagios-plugin 1.3.1 을 소스로 설치한 경우이다.
- http://www.nagios.org/download/ 에서 nagios, nagios-plugin 을 받는다.
# mkdir /usr/local/nagios
# adduser nagios
# ./configure --prefix=/usr/local/nagios --with-cgiurl=cgiurl --with-htmurl=htmurl --with-nagios-user=someuser --with-nagios-grp=somegroup
기본경로
prefix=/usr/local/nagios
with-cgiurl=/nagios/cgi-bin
with-htmlurl=/nagios
with-nagios-user=nagios
with-nagios-grp=nagios
위의 기본경로를 사용할 것이라면 별도로 지정하지 않고 configure만 실행해도된다.
# make all
# make install
# make install-init (/etc/rc.d/init.d/ 에 nagios 시작파일 복사)
# make install-commandmode (external command file 에 대한 퍼미션 조정)
# make install-config (prefix/etc 에 샘플파일 복사)
이제는 nagios-plugin을 설치한다
# 소스 압축풀고 이동
# ./configure --prefix=BASEDIRECTORY --with-nagios-user=SOMEUSER --with-nagios-group=SOMEGROUP --with-cgiurl=SOMEURL
prefix 는 nagios 설치디렉토리(기본 /usr/local/nagios)
나머지 옵션도 nagios 설치했을때와 동일하게 하면 된다. 별도 지정하지 않으면 nagios 동일한 기본경로를 가진다.
# make all
# make install (prefix/libexec 에 복사함)
# chown -R nagios.nagios /usr/local/nagios/libexec/ (소유권맞추어줌)
ㅇ 웹서버 설정
httpd.conf 파일에 nagios 실행을 위한 환경설정을 추가한다. alias와 인증관련 설정을 하면 된다.
ScriptAlias /nagios/cgi-bin/ /usr/local/nagios/sbin/
<Directory "/usr/local/nagios/sbin/">
AllowOverride AuthConfig
Options ExecCGI
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
require valid-user
Order allow,deny
Allow from all
</Directory>
Alias /nagios/ /usr/local/nagios/share/
<Directory "/usr/local/nagios/share">
Options None
AllowOverride AuthConfig
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
require valid-user
Order allow,deny
Allow from all
</Directory>
** AuthName 부터 require 까지를 .htaccess 파일에 넣어두는 것이 관리상 편리할것임
$ cat .htaccess
AuthName "Nagios Access guest/guest 하면 내용을 볼수 있습니다"
AuthType Basic
AuthUserFile /usr/local/etc/nagios/.htpasswd.users
require valid-user
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
# htpasswd /usr/local/nagios/etc/htpasswd.users <username>
** 위에서 추가한 사용자는 contatcs.cfg에 설정해주어야한다.
** contacts.cfg에 설정한 내용에 따라 자신이 볼수 있는 service, host 가 정해지며 system, process, config 등에 대한 추가 권한은 cgi.cfg 에서 설정한다. 보통 nagios 의 관리자에게만 추가권한을 설정하면 될 것이다. 추가권한은 다음과 같다.
authorized_for_system_information
authorized_for_system_commands
authorized_for_configuration_information
authorized_for_all_hosts
authorized_for_all_host_commands
authorized_for_all_services
authorized_for_all_service_commands
웹을 다시 재시작한다.
이러한 권한설정이 작용하려면 nagios/etc/cgi.cfg 의 파일에 다음 내용이 들어가야하는데 기본으로 설정되어있다.
use_authentication=1
ㅇ external command 실행 설정 (이에 대해서 아직 모르면 뒤의 내용부터 본다)
external command 를 실행하기 위해서는 적절한 퍼미션 설정이 필요하다. (이 프로그램은 cgi 에서 외부 프로그램을 사용할 경우 필요하다. 예를 들어 comment 를 달거나 service 에 대한 모니터링을 중단하는등)
nagios, apache 유저가 동시에 접근할 수 있는 그룹을 설정한다.
# /usr/sbin/groupadd nagioscmd
# /usr/sbin/usermod -G nagioscmd nagios
# /usr/sbin/usermod -G nagioscmd apache
# mkdir /usr/local/nagios/var/rw (처음 설치시 만들어져있으므로 있으면 만들지 않아도 된다)
# chown nagios.nagioscmd /usr/local/nagios/var/rw -
# chmod u+rwx /usr/local/nagios/var/rw
# chmod g+s /usr/local/nagios/var/rw (위 세줄은 간단히 chmod 2770 rw 해도 된다)
아래와 같이 퍼미션이 나오면 된다.
drwxrws--- 2 nagios nagioscmd 1024 Aug 11 16:30 rw
여기서 other 사용자는 권한이 있으면 안된다.
ㅇ 환경파일 설정 및 프로그램 시작하기
- etc 디렉토리의 샘플파일을 이용하여 수정, 추가하면 된다.
참고로 처음 설치시에는 -sample 이런 형태로 파일이 되어있으므로 간단하게 쉘스크립트를 이용하여 파일명을 바꾸자.
for a in `ls -1` ; do mv $a `ls $a | awk -F- '{print $1}'` ; done
- 편리하게 실행하기 위해 nagios/bin 을 경로에 추가한다.
- nagios -v nagios.cfg 명령을 통해 프로그램을 시작하지 않고도 설정파일에 문제가 있는지 확인할 수 있다. 아니면 syslog 를 확인해도 된다.
** init 스크립트에 위 명령을 추가하면 편리할 것이다. (redhat /etc/init.d/nagios, freebsd /usr/local/etc/rc.d/nagios.sh
test)
$NagiosBin -v $NagiosCfg
;;
- nagios.cfg 에서는 check_external_commands 를 1로 수정해준다. 그래야 앞에서 설명한 external command 를 실행할 수 있다.
- hosts.cfg 에서는 모니터링할 호스트를 지정한다.
host_name, alias, address 정도 수정하면 된다. (** parents 를 이용하면 서버간의 연관관계를 줄수 있다. 이는 웹에서 Status map을 보는 경우 편리하다.)
- contacts.cfg 에는 contact_name, alias , email 수정하면된다. 이를 contactgroups.cfg 를 이용하여 그룹으로 묶는다.
- hostgroups.cfg 에는 모니터링할 호스트(hosts.cfg)의 그룹을 지정할 수 있다. contact_groups 에 관련된 contact group을 설정하고 (contacts.cfg) members에는 hosts.cfg 에 지정한 host 를 넣는다.
- service.cfg 에는 해당 host 에 대한 모니터링할 service를 지정한다. host_name, service_description, contact_groups, check_command 등을 조정하면된다.
- dependencies.cfg 와 escalations.cfg 는 아직 사용법을 몰라 모두 주석처리했다.
- checkcommands.cfg 는 hosts.cfg 와 service.cfg 의 check_command 에서 사용할 수 있는 명령어를 지정하며 libexec 에 있는 plugin에 있는 명령을 사용할 수 있다.
** checkcommands.cfg 는 모든 플러그인에 대한 정의가 들어있는 것은 아니며 예를 들어 check_ssh 등은 추가를 해주어야한다. 문법을 보면 그리 어렵지 않다.
- misscommands.cfg 에는 주로 notification command 가 들어있다.
- resource.cfg 에는 plugin 디렉토리, db연동시 관련된 내용을 지정하는데 기본 실행을 하는데는 바꿀 필요가 없다.
- hostextinfo.cfg 에는 각 호스트별도 별도의 아이콘을 지정할 수 있다. 이경우에는 nagios 사이트에서 Image packs을 다운받아야한다. 나는 base와 cook을 이용했다.
** 설정파일을 보면 알겠지만 기본설정을 만들어 register로 등록(템플릿)하면 편리하다. 공통되는것을 등록해놓고 상속받는다고 생각하면 된다.
** service 등에서는 host_name 에 호스트그룹설정도 가능하며 여러개의 호스트를 개별적으로 설정할 수 있다. 중복된 설정작업을 막아주는 것이다.전체적으로 그룹으로 묶어서 관리하면 편리하다.
수정을 하였으면 이제 프로그램을 실행하면 된다.
# /etc/init.d/nagios (nagios 사용자 권한으로 실행이 된다)
웹에서 접속하여 확인을 해본다. http://localhost/nagios/ 인증창이 뜨고 htpasswd 에 입력한 사용자 계정과 contats.cfg 의 내용을 이용하여 적절한 권한을 제공한다.
ㅇ nsca 설치
Passive Service Checks 라고 하여 nagios 서버에서 주기적으로 체크하는 것이 아니라 클라이언트에서 메시지를 보내 nagios 서버가 메시지를 처리하도록 할 수도 있다. 사설망이라서 접근하지 못하는 경우에 유용할 것이다.
http://www.nagios.org/download/extras.php 에서 Nagios Service Check Acceptor (NSCA) 2.4 를 받는다.
nsca 간의 통신을 할때 암호화를 하려면 http://mcrypt.hellug.gr/ 를 참고하여 http://sourceforge.net/project/showfiles.php?group_id=87941 에서 libmcrypt-2.5.7.tar.gz 를 받아서 미리 설치해야한다.
libmcrypt 소스를 푼다
# ./configure --prefix=/usr/local/libmcrypt
# make
# make test
# make install
이제 /etc/ld.so.conf 에 다음 줄을 추가한다.
/usr/local/libmcrypt/lib
# ldconfig
nsca 소스를 푼다
# ./configure
** libmcrypt 를 이용하여 컴파일할 경우에는 아래와 같이 지정한다.
./configure --with-mcrypt-lib=/usr/local/libmcrypt/lib --with-mcrypt-inc=/usr/local/libmcrypt/include --with-libmcrypt-prefix=/usr/local/libmcrypt
# make all
src 디렉토리에 바이너리들이 복사가 된다. 적절한 위치로 이동을 한다.
나는 /usr/local/nagios/nsca 디렉토리에 복사를 하였다.
# chown -R nagios.nagios nsca/
nsca : nagios 서버에서 돌아가는 대몬
nsca.cfg : nsca 에서 사용하는 환경파일
send_nsca : client 프로그램
send_nsca.cfg : client 환경파일
inetd 나 xinetd 설정을 해야한다.
/etc/service 에 다음 내용을 추가한다.
nsca 5667/tcp # NSCA
xinetd 는 다음과 같은 파일을 /etc/xinet.d/nsca 로 복사해서 작성하여 사용한다.
# default: on
# description: NSCA
service nsca
{
disable = no
flags = REUSE
socket_type = stream
wait = no
user = nagios
group = nagios
server = /usr/local/nagios/nsca/nsca
server_args = -c /usr/local/nagios/nsca/nsca.cfg --inetd
log_on_failure += USERID
#only_from = <ipaddress1> <ipaddress2> ...
}
ㅇ nsca 설정
nsca.cfg : debug=1 로 설정하면 syslog 에서 좀더 자세한 정보를 볼 수 있다. allowed_hosts 는 xinetd 를 이용한 경우 작동을 하지 않는 것 같은데 tcp_wrapper 나 xinetd 에서 only_from 을 이용하여 설정하면 된다. decryption_method 는 nsca.cfg 와 send_nsca.cfg 를 동일하게 설정해야한다. 여기에 추가하여 password 까지 동일하게 설정하면 보안을 더 강화할 수 있을 것이다.
이제 nagios 에서 설정을 해보자.
hosts.cfg, hostgroups.cfg 에는 동일하게 설정하면 된다.
service.cfg 에서는 is_volatile=1, max_check_attempts=1, active_checks_enabled 0, passive_checks_enabled 1 로 설정한다.
service 설정에서 host_name taejun, service_description nsca 라고 가정하겠다. 클라이언트에서 send_nsca 프로그램을 이용하면 된다. 형식은 아래와 같다. 보내는 메시지는 standard input 를 이용한다.
형식) ./send_nsca -H <host_address> [-p port] [-to to_sec] [-d delim] [-c config_file]
# ./send_nsca -H nagios_server_ip < http.msg
여기서 http.msg 내용을 보자. 아래 공백은 탭으로 띄어야한다.
# cat http.msg
taejun nsca 0 'web service good'
메시지 형태는 다음과 같다.
Service Checks:
<host_name>[tab]<svc_description>[tab]<return_code>[tab]<plugin_output>[newline]
Host Checks:
<host_name>[tab]<return_code>[tab]<plugin_output>[newline]
원래는 external application 이 서비스 점검한 결과를 아래의 형식으로 알려주면 nagios 에서 처리를 한다.
[<timestamp>] PROCESS_SERVICE_CHECK_RESULT;<host_name>;<description>;<return_code>;<plugin_output>
return_code : 0=OK, 1=WARNING, 2=CRITICAL, 3=UNKNOWN
지금처럼 nsca를 이용할때는 send_nsca 가 보내준 메시지를 nsca 서버 프로그램에서 PROCESS_SERVICE_CHECK_RESULT 에서 본 형태대로 자동으로 바꾸어주는 것이다.
ㅇ Nagat - Nagios Administration Tool
http://sourceforge.net/projects/nagat/
nagios.cfg 등 환경설정파일을 웹에서 편집할 수 있는 php 프로그램이다. 위의 사이트에서 프로그램을 다운받고 원하는 디렉토리로 옮긴후 local.inc.dist 를 local.inc 로 복사하고 define("NGT_ROOT","/var/www/html/nagat/") 경로만 수정하면 된다. (nagios 는 /usr/local/nagios 에 설치되었다고 가정)
nagios 의 etc 디렉토리밑 파일을 수정하려면 웹사용자(apache)가 etc 디렉토리에 대한 권한이 있어야 한다. 앞에서 nagios, apache 유저가 동시에 접근할 수 있는 그룹인 nagioscmd 를 사용하면 될 것이다. 보안상 문제가 될 수 있으므로 SSL등을 이용하면 좋겠다.
웹에서 접속하여 먼저 Importer 를 이용하여 cfg 파일을 읽어들여야 한다. nagios.cfg, cgi.cfg 를 읽어들이고나면 나머지 다른 파일들도 import를 한다. 이제 원하는 내용을 편집하면 된다. 편집을 마치고나면 export를 이용하여 저장하면 파일이 저장된다. nagat 형식으로 바꾸어서 간결하게 바뀐다. nagat를 이용한 경우에는 직접 설정파일을 바꾸지 않을것을 추천하고 있다
'linux > Install' 카테고리의 다른 글
snort -- install (0) | 2007.03.15 |
---|---|
BIND 9 installation (0) | 2007.03.15 |
apm-임시 (0) | 2007.03.15 |
A(2.0.54)P(5.0.4)M(4.1.18)++Zend+Tomcat (0) | 2007.03.15 |
vsftpd 설치 (0) | 2007.03.15 |