Nagios 설치 · 2 min read · Oct 18, 2025

Debian Lenny에 Nagios 설치 및 Debian Lenny 서버 모니터링 - 2페이지

7. server1의 로컬 서비스를 모니터 서버에 소개하기

우리는 nrpe로 이제 발견할 수 있는 새로운 서비스를 모니터링하기 위해 5단계에서 생성한 hostconfig를 변경해야 합니다.

monitor:~# nano /etc/nagios3/conf.d/server1_nagios2.cfg

파일 끝에 다음을 추가합니다:

define service{
        use                     generic-service
        host_name               server1
        service_description     Current Load
        check_command           check_nrpe_1arg!check_load
}
define service{
        use                     generic-service
        host_name               server1
        service_description     Current Users
        check_command           check_nrpe_1arg!check_users
}
define service{
        use                     generic-service
        host_name               server1
        service_description     Disk Space
        check_command           check_nrpe_1arg!check_hda1
}
define service{
        use                     generic-service
        host_name               server1
        service_description     Total Processes
        check_command           check_nrpe_1arg!check_total_procs
}

nagios 서비스를 재시작합니다:

monitor:~# /etc/init.d/nagios3 restart

웹 서비스에서 이제 추가된 서비스를 볼 수 있어야 하며, 서서히 확인할 수 있어야 합니다. 그 중 하나인 디스크 공간 확인은 /dev/hda1 파티션이나 장치가 없기 때문에 실패할 가능성이 높습니다.

monitor1 서버에서 이 확인을 우리가 확인하고자 하는 실제 파티션으로 변경합니다. 제 경우에는 머신이 xen에 의해 호스팅되는 가상 서버에 위치하고 있으며, server1에서 다음 명령어를 사용하여 사용 중인 파티션을 확인할 수 있습니다:

server1:~# df -h
Filesystem            Size  Used Avail Use% Mounted on  
 /dev/mapper/iscsi1-root  
                     7.3G  714M  6.2G  11% /
 tmpfs                 137M     0  137M   0% /lib/init/rw  
 udev                  10M  568K  9.5M   6% /dev  
 tmpfs                 137M     0  137M   0% /dev/shm  
 /dev/xvda1          228M  9.5M  207M   5% /boot

이것은 우리에게 파티션과 그 마운트 포인트를 보여줍니다. 제 경우 실제 ‘root’ 파티션은 /dev/mapper/iscsi1-root이며, 이는 마운트 포인트 ‘/‘를 찾아보면서 발견했습니다.

이제 이 확인이 작동하도록 서버에서 nrpe 구성을 변경할 수 있습니다. 이를 위해 nrpe.cfg 파일을 다시 엽니다:

server1:~# nano /etc/nagios/nrpe.cfg

그런 다음 (기본적으로 201행)에 있는 줄로 이동합니다:

command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1

그리고 다음과 같이 변경합니다:

command[check_iscsi1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/mapper/iscsi1-root

Nagios 서버의 hostconfig를 이러한 변경 사항을 반영하도록 변경합니다:

monitor:~# nano /etc/nagios3/conf.d/server1_nagios2.cfg

다음에서:

define service{
        use                     generic-service
        host_name               server1
        service_description     Disk Space
        check_command           check_nrpe_1arg!check_hda1
}

다음으로:

define service{
        use                     generic-service
        host_name               server1
        service_description     Disk Space
        check_command           check_nrpe_1arg!check_iscsi1
}

두 서비스를 모두 재시작합니다.

server1:~# /etc/init.d/nagios-nrpe-server restart  
 monitor:~# /etc/init.d/nagios3 restart
 

8. 이메일로 알림 구성하기

서비스가 임계 상태에 들어갈 때 이메일로 알림을 받고 싶습니다. 따라서 nagiosadmin 사용자에 대한 이메일 주소를 구성해야 합니다.

파일 /etc/nagios3/conf.d/contacts_nagios2.cfg로 들어가서 이메일 주소를 자신의 것으로 변경합니다. 더 많은 사용자를 추가하려면 ‘define contact’ 섹션을 복사하고, 이를 사용하여 두 번째 항목을 생성하고 아래의 contactgroup에 사용자들을 추가하면 됩니다.

define contact{
        contact_name                    root
        alias                           Root
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    w,u,c,r
        host_notification_options       d,r
        service_notification_commands   notify-service-by-email
        host_notification_commands      notify-host-by-email
        email                           [email protected]
        }
        
define contact{
        contact_name                    example
        alias                           example
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    w,u,c,r
        host_notification_options       d,r
        service_notification_commands   notify-service-by-email
        host_notification_commands      notify-host-by-email
        email                           [email protected]
        }
define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 root,example
        }

간단한 이메일 알림을 활성화하려면 Debian 시스템의 smtp 전송을 활성화해야 합니다. Nagios가 하는 모든 것은 메시지를 Linux 파이프를 통해 표준 프로그램 /usr/bin/mail로 전달하는 것입니다.

Postfix를 설치하고 Nagios 서버가 스스로 이메일을 보낼 수 있도록 기본 구성을 설정해야 합니다.

monitor:~# apt-get install postfix mailx

이제 Postfix를 “인터넷 사이트”로 구성하고 Nagios 이메일이 올 도메인을 설정합니다.

이후 재시작하고 테스트 서버에서 apache 서비스를 중지합니다:

monitor:~# /etc/init.d/nagios3 restart  
 server1:~# /etc/init.d/apache2 stop

이것은 contacts_nagios2.cfg 파일에 이메일 주소를 설정하면 수신해야 하는 알림 메시지를 생성합니다.

기타: Icinga에 대하여

Icinga는 더 큰 개발자 커뮤니티를 가진 Nagios 포크이며, 앞으로 사용할 소프트웨어가 될 가능성이 높습니다. Icinga에 대한 사용 방법은 HowtoForge에서 찾을 수 있으며, Nagios 플러그인을 Icinga에서 재사용할 수 있습니다.

모든 사람에게 Nagios와 Icinga를 가지고 놀아보라고 추천합니다.

Share: X/Twitter LinkedIn

새 게시물을 받은 편지함에서 받기

스팸은 없습니다. 언제든지 구독 해지 가능합니다.