[모니터링] Nagios(나기오스) - 서비스 모니터링 등록

이번 포스팅은 nagios에서 웹 서비스를 모니터링하는 방법에 대해 알아보겠습니다.

 

이전 포스팅

실습 환경

VirtualBox
hostname : linux-1

CentOS 7.8 - (IP : 192.168.56.101)

nagios-4.4.6

nagios-plugins-2.3.3

VirtualBox
hostname : linux-2
CentOS 7.8 - (IP : 192.168.56.102)

linux-1 -> linux-2 ssh-key 등록

 

linux-1 서버의 nagios 설정 파일 위치로 이동합니다. 

[root@linux-1 objects]# pwd
/usr/local/nagios/etc/objects
[root@linux-1 objects]# ls
backup  commands.cfg  contacts.cfg  linux-host.cfg  localhost.cfg  templates.cfg  timeperiods.cfg

 

generic-service

우선, 서비스 모니터링의 기본 템플릿을 확인해 보겠습니다. 위치는 templates.cfg 설정 파일에 있습니다.

대부분의 설정은 이미 정의가 되어있습니다, 수정이 필요할 경우 해당 태블릿에서 진행하셔도 되고 아니면, 다음에 설명할 "web-server" 템플릿에서 세부 설정을 진행하셔도 됩니다.

define service {

    name                            generic-service         ; 서비스 템플릿 이름
    active_checks_enabled           1                       ; 액티브 체크 허용
    passive_checks_enabled          1                       ; 패시브 체크 허용
    parallelize_check               1                        
    obsess_over_service             1                        
    check_freshness                 0                       
    notifications_enabled           1                       ; 알람 허용
    event_handler_enabled           1                       ; 이벤트핸들러 허용
    flap_detection_enabled          1                       ; flap 감지 허용
    process_perf_data               1                       ; 성능 데이터 저장
    retain_status_information       1                       ; 프로세스 재시작 간에 상태 정보 저장
    retain_nonstatus_information    0                       ; 프로세스 재시작 간에 상태 정보가 아닌 정보값 저장하지 않음
    is_volatile                     0                       ; 서비스는 volatile 아님
    check_period                    24x7                    ; 365일 내내 체크
    max_check_attempts              3                       ; 문제시 재시도 체크 횟수
    check_interval                  10                      ; 체크 주기 10분
    retry_interval                  2                       ; 문제시 재시도 주기 2분
    contact_groups                  admins                  ; 통보 그룹
    notification_options            w,u,c,r                 ; warning, unknown, critical, and recovery events 일경우 알람 발생
    notification_interval           60                      ; 1시간 마다 알람 재전송
    notification_period             24x7                    ; 24시간 7일 언제나 모니터링
    register                        0                       ; 텦플릿이면 0
}

 

web-server

이번엔 templates.cfg 설정파일에 새로운 서비스 템플릿을 생성해 보겠습니다.

define service{
    name                            web-server
    use                             generic-service
    max_check_attempts              1
    normal_check_interval           1
    retry_check_interval            1
    notification_interval           180
    register                        0
}

 

웹서버 모니터링을 위한 템플릿이기 때문에 이름은 "web-server"로 생성하였고, 

설정은 generic-service 템플릿을 상속받아서 일부 설정만 재정의 하였습니다.

 

generic-service의 설정 값을 상속을 받아도 "web-server" 템플릿에서 다시 설정 값을 변경하면 해당 설정이 적용이 됩니다. 지난 글에서도 말했듯이, 모든 서비스의 공통 설정은 "generic-service"에서 정의를 하고 "web-server"에서는 좀 더 세부적인 설정을 하는 것이라고 보시면 됩니다.

 

 

모니터링할 웹서버 등록

다음은 모니터링할 웹서버를 등록하는 단계입니다.

 

/usr/local/nagios/etc/objects 경로에 cfg 파일을 생성 후 아래 내용을 입력합니다.

define service {
    use                             web-server
    host_name                       a.tistory.com
    service_description             HTTP
    check_command                   check_http! -u /
    register                        1
}
  • use : web-server 템플릿을 사용합니다.
  • host_name : a.tistory.com 웹 서버를 모니터링합니다.(linux-2 서버에 설치되어 있습니다)
  • service_description : 설명란
  • check_command : http 모니터링 명령어 부분
  • register : 템플릿이 아니면 1

그리고 nagios.cfg 설정 파일에 위에서 생성한 설정 파일 경로를 등록해 줍니다

cfg_file=/usr/local/nagios/etc/objects/a.tistory.com.cfg

 

그리고 마지막으로 nagiso 재구동을 해줍니다.

[root@linux-1 objects]# systemctl restart nagios
Job for nagios.service failed because the control process exited with error code. See "systemctl status nagios.service" and "journalctl -xe" for details.

 

로그 내용

 6월 20 03:19:17 linux-1 nagios[8442]: Error: Could not find any host matching 'a.tistory.com' (config file '/usr/local/nagios/etc/objects/a.tistory.com.cfg', starting on line 1)
 6월 20 03:19:17 linux-1 nagios[8442]: Error: Failed to expand host list 'a.tistory.com' for service 'HTTPA' (/usr/local/nagios/etc/objects/a.tistory.com.cfg:1)
 6월 20 03:19:17 linux-1 nagios[8442]: Error processing object config files!

 

웹서버의 호스트 등록이 안되어있는것이 원인이었습니다.

http 80 포트만 모니터링이 필요한데 왜 호스트 모니터링까지 해야 하는지 알 수가 없지만 일단은 등록을 해주었습니다.

이 부분은 따로 확인해 봐야겠다.

 

a.tistosy.com.cfg 파일에 아래 내용을 추가 후 nagios 재구동을 해줍니다.

define host {
    use                     linux-server
    host_name               a.tistory.com
}

 

command 확인

마지막으로 command에 대해 좀 더 확인해 보겠습니다.

check_command                   check_http! -u /

 

command.cfg 파일에서 check_http 명령의 설정에 대해 확인합니다.

define command {

    command_name    check_http
    command_line    $USER1$/check_http -I $HOSTADDRESS$ $ARG1$
}

 

check_http 플러그인을 사용하여 웹서버($HOSTADDRESS)를 체크하며, 인자로($ARG1) "-u /"가 전달됩니다

("/"는 check_command에서 "-u /"로 설정을 했었죠?)

 

[root@linux-1 objects]# /usr/local/nagios/libexec/check_http -I a.tistory.com -u /
HTTP OK: HTTP/1.1 200 OK - 273 bytes in 0.002 second response time |time=0.001870s;;;0.000000 size=273B;;

 

모니터링 확인

    

이렇게 해서 nagios 웹서버 모니터링에 대해 확인해 보았습니다. 감사합니다~

댓글

Designed by JB FACTORY

loading