Nagios Client OS별 설정 방법

CentOS/RHEL, Ubuntu/Debian, Windows에서 Nagios 클라이언트를 구성하는 방법입니다. NRPE, NSClient++, 방화벽, 서버 측 check_nrpe 검증까지 정리했습니다.

Nagios 클라이언트 설정은 OS마다 패키지 이름, 플러그인 경로, 서비스 이름이 다릅니다. 실습은 CentOS, Ubuntu, Windows를 한 번에 소개하고 있었으므로, 여기서는 NRPE 기반 Linux 클라이언트와 NSClient++ 기반 Windows 클라이언트로 나누어 설치, 허용 서버, command 정의, 방화벽, 서버 측 테스트까지 연결해서 정리합니다.

구성 기준

  • Nagios 서버 IP: 192.168.0.1
  • Linux 클라이언트: NRPE daemon 사용
  • Windows 클라이언트: NSClient++ 사용
  • 기본 NRPE 포트: TCP 5666

실제 운영에서는 192.168.0.1을 본인의 Nagios 서버 IP로 바꿔야 합니다. 클라이언트에서 허용할 서버 IP를 넓게 잡으면 임의 명령 실행 위험이 커지므로 관리망 IP만 허용합니다.

CentOS/RHEL 계열 NRPE 설정

1. 패키지 설치

sudo yum install -y epel-release
sudo yum install -y nagios-plugins nagios-plugins-all nrpe

2. 플러그인 경로 확인

rpm -ql nagios-plugins | grep '/check_load$' || true
ls -al /usr/lib64/nagios/plugins/

RHEL/CentOS 계열은 보통 /usr/lib64/nagios/plugins를 사용합니다. OS 버전이나 패키지에 따라 다를 수 있으므로 command를 등록하기 전에 실제 경로를 확인합니다.

3. nrpe.cfg 수정

sudo cp -a /etc/nagios/nrpe.cfg /etc/nagios/nrpe.cfg.bak.$(date +%Y%m%d-%H%M%S)
sudo vi /etc/nagios/nrpe.cfg
server_address=0.0.0.0
allowed_hosts=127.0.0.1,192.168.0.1

command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib64/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_root_disk]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /
command[check_total_procs]=/usr/lib64/nagios/plugins/check_procs -w 250 -c 400
command[check_zombie_procs]=/usr/lib64/nagios/plugins/check_procs -w 5 -c 10 -s Z

4. 서비스와 방화벽

sudo systemctl enable --now nrpe
sudo systemctl status nrpe --no-pager

sudo firewall-cmd --add-port=5666/tcp --permanent
sudo firewall-cmd --reload

Ubuntu/Debian 계열 NRPE 설정

1. 패키지 설치

sudo apt-get update
sudo apt-get install -y nagios-plugins nagios-nrpe-server

2. 플러그인 경로 확인

dpkg -L nagios-plugins-basic | grep '/check_load$' || true
ls -al /usr/lib/nagios/plugins/

3. nrpe.cfg 수정

sudo cp -a /etc/nagios/nrpe.cfg /etc/nagios/nrpe.cfg.bak.$(date +%Y%m%d-%H%M%S)
sudo vi /etc/nagios/nrpe.cfg
server_address=0.0.0.0
allowed_hosts=127.0.0.1,192.168.0.1

command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_root_disk]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /
command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 250 -c 400
command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z

4. 서비스와 방화벽

sudo systemctl enable --now nagios-nrpe-server
sudo systemctl status nagios-nrpe-server --no-pager

sudo ufw allow from 192.168.0.1 to any port 5666 proto tcp

Linux 클라이언트 로컬 테스트

/usr/lib64/nagios/plugins/check_load -w 15,10,5 -c 30,25,20 2>/dev/null || \
 /usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20

ss -tnlp | grep ':5666'

클라이언트에서 NRPE가 떠 있고 포트가 열렸다면 Nagios 서버에서 원격 테스트를 합니다.

/usr/lib/nagios/plugins/check_nrpe -H <client-ip> -c check_load
/usr/lib/nagios/plugins/check_nrpe -H <client-ip> -c check_root_disk

Windows NSClient++ 설정

1. 설치

Windows에서는 NSClient++를 설치하고 서비스로 등록합니다. 설치 중에는 Nagios 서버 IP를 허용 목록에 넣고, NRPE 또는 check_nt 중 어떤 방식으로 확인할지 운영 기준을 정합니다.

2. nsclient.ini 예시

[/settings/default]
allowed hosts = 192.168.0.1

[/modules]
CheckSystem = enabled
CheckDisk = enabled
CheckExternalScripts = enabled
NRPEServer = enabled

[/settings/NRPE/server]
port = 5666
allow arguments = false
allow nasty characters = false

[/settings/external scripts/scripts]
check_disk = scripts\\check_disk.bat

Windows 방화벽에서도 Nagios 서버에서 들어오는 TCP 5666 접근만 허용합니다.

New-NetFirewallRule -DisplayName "NRPE from Nagios" `
 -Direction Inbound `
 -Protocol TCP `
 -LocalPort 5666 `
 -RemoteAddress 192.168.0.1 `
 -Action Allow

Nagios 서버 측 command/service 예시

define command {
 command_name check_nrpe
 command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

define service {
 use generic-service
 host_name linux-client-01
 service_description CPU Load
 check_command check_nrpe!check_load
}

define service {
 use generic-service
 host_name linux-client-01
 service_description Root Disk
 check_command check_nrpe!check_root_disk
}

문제 해결

증상 확인 조치
Connection refused NRPE 서비스 미기동 또는 포트 미리스닝 systemctl status, ss -tnlp 확인
Connection timed out 방화벽 또는 라우팅 차단 클라이언트 방화벽과 네트워크 ACL 확인
CHECK_NRPE: Error receiving data SSL/버전/허용 호스트 문제 NRPE 로그, allowed_hosts, 서버 check_nrpe 옵션 확인
Plugin not found command 경로 오류 /usr/lib/nagios/plugins 또는 /usr/lib64/nagios/plugins 실제 경로 확인

적용 체크리스트

  1. 클라이언트 OS별 plugin 경로를 확인합니다.
  2. allowed_hosts에는 Nagios 서버 IP만 넣습니다.
  3. TCP 5666 방화벽은 Nagios 서버에서 오는 트래픽만 허용합니다.
  4. 클라이언트 로컬 plugin 실행과 서버의 check_nrpe 원격 실행을 둘 다 검증합니다.
  5. Nagios 서버에는 host/service object를 추가하고 configuration test 후 reload합니다.
BGM EVER