Nagios 설치 및 운용

Nagios는 시스템과 네트워크를 모니터링하기 위한 오픈소스 도구 중 하나로, 대규모 시스템 및 네트워크 모니터링에 적합합니다. 이번에는 Nagios 설치 및 운용에 대한 총정리를 작성하겠습니다.

1. Nagios 설치

1-1. 사전 준비

  • Nagios 설치를 위해 필요한 패키지들을 설치합니다.
$ sudo apt-get update
$ sudo apt-get install -y wget build-essential apache2 php libapache2-mod-php7.4 openssl perl make php-pear php7.4-dev snmp libnet-snmp-perl gettext

1-2. Nagios Core 설치

  • Nagios Core를 다운로드하고 압축을 해제합니다.
$ cd /tmp
$ wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.6.tar.gz
$ tar xzf nagios-4.4.6.tar.gz
  • Nagios Core를 컴파일하고 설치합니다.
$ cd nagios-4.4.6
$ ./configure --with-httpd-conf=/etc/apache2/sites-enabled
$ make all
$ sudo make install
$ sudo make install-init
$ sudo make install-commandmode
$ sudo make install-config
  • Nagios 웹 인터페이스를 사용하기 위해 Apache 웹 서버를 구성합니다.
$ sudo usermod -a -G nagios www-data
$ sudo a2enmod rewrite cgi
$ sudo systemctl restart apache2

1-3. Nagios Plugin 설치

  • Nagios Plugin을 다운로드하고 압축을 해제합니다.
$ cd /tmp
$ wget https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz
$ tar xzf nagios-plugins-2.3.3.tar.gz
  • Nagios Plugin을 컴파일하고 설치합니다.
$ cd nagios-plugins-2.3.3
$ ./configure --with-nagios-user=nagios --with-nagios-group=nagios
$ make
$ sudo make install

2. Nagios 운용

2-1. Nagios 구성 파일 수정

  • Nagios 구성 파일인 nagios.cfg 파일을 수정합니다.
$ sudo vi /usr/local/nagios/etc/nagios.cfg
  • allowed_hosts 항목에 모니터링 대상 서버의 IP 주소나 서브넷을 추가합니다.
# ALLOWED HOSTS
# This is a comma-delimited list of IP address (or hostnames) that are allowed
# to access the web interface.  This value can be a single IP address of a
# host, or a subnet in CIDR notation (e.g. 192.168.0.0/16).
allowed_hosts=127.0.0.1,192.168.0.0/24

2-2. 모니터링 대상 서버 설정

  • Nagios Plugin을 사용하여 모니터링 대상 서버의 상태를 체크할 수 있습니다.
  • commands.cfg 파일에서 각 체크 명령어의 인수를 수정합니다.
$ sudo vi /usr/local/nagios/etc/objects/commands.cfg
  • 예를 들어, HTTP 서비스 체크 명령어를 수정하려면 다음과 같이 작성합니다.
# 'check_http' command definition
define command{
        command_name    check_http
        command_line    $USER1$/check_http -I $HOSTADDRESS$ -w 5 -c 10
}
  • 위 예시에서 -I 옵션은 체크할 서버의 IP 주소를 나타내며, -w 옵션은 경고 임계값을 나타내고, -c 옵션은 치명적 임계값을 나타냅니다.

2-3. 모니터링 대상 서버 추가

  • Nagios에서 모니터링 대상 서버를 추가하려면 hosts.cfg 파일을 수정합니다.
$ sudo vi /usr/local/nagios/etc/objects/hosts.cfg
  • 모니터링 대상 서버를 추가하려면 다음과 같이 작성합니다.
define host{
        use             linux-server
        host_name       server1
        alias           My Linux Server
        address         192.168.0.1
}
  • use 항목은 호스트 설정을 상속할 템플릿을 지정합니다. host_name 항목은 호스트 이름을 나타내며, alias 항목은 호스트의 설명을 나타냅니다. address 항목은 호스트의 IP 주소를 나타냅니다.

2-4. 서비스 체크 추가

  • Nagios에서 서비스를 체크하려면 services.cfg 파일을 수정합니다.
$ sudo vi /usr/local/nagios/etc/objects/services.cfg
  • 서비스 체크를 추가하려면 다음과 같이 작성합니다.
define service{
        use                     generic-service
        host_name               server1
        service_description     HTTP
        check_command           check_http
        notifications_enabled   0
}
  • use 항목은 서비스 설정을 상속할 템플릿을 지정합니다. host_name 항목은 서비스를 체크할 호스트의 이름을 나타냅니다. service_description 항목은 서비스의 설명을 나타냅니다. check_command 항목은 체크할 명령어를 지정합니다. notifications_enabled 항목은 알림 설정을 나타냅니다.

2-5. Nagios 서비스 시작

  • 모든 구성 파일을 수정한 후 Nagios 서비스를 시작합니다.
$ sudo systemctl start nagios
  • Nagios 웹 인터페이스에서 모니터링 대상 서버의 상태를 확인할 수 있습니다.

위 방법들은 Nagios 설치 및 운용에 대한 대표적인 방법들입니다. 다만, Nagios 모니터링 대상에 따라 추가적인 설정이 필요할 수 있으므로, 상황에 맞게 적절한 방법을 선택하여 사용해야 합니다.