웹사이트 검색

RHEL, Rocky 및 AlmaLinux에 Nagios를 설치하는 방법


Nagios는 데이터 센터에 있든 그냥 있든 모든 머신/네트워크를 항상 감시할 수 있는 보다 포괄적인 모니터링 환경을 제공하는 멋진 오픈 소스 모니터링 도구입니다. 당신의 작은 연구실.

Nagios를 사용하면 단일 창에서 원격 호스트와 해당 서비스를 원격으로 모니터링할 수 있습니다. 경고를 표시하고 서버에 문제가 있는 경우 표시하여 문제가 발생하기 전에 이를 감지하는 데 도움이 됩니다. 이는 다운타임비즈니스 손실을 줄이는 데 도움이 됩니다.

최근 Nagios는 최신 버전인 Nagios Core 4.4.9Nagios 플러그인 2.3.3의 최신 안정 릴리스를 2022년 10월 4일에 출시했습니다. .

이 문서는 RHEL 및 CentOS Stream과 같은 RHEL 기반 배포판의 소스(tarball)에서 최신 버전의 Nagios Core를 설치하고 구성하는 방법에 대한 쉬운 지침을 안내하기 위해 작성되었습니다. Strong>, Rocky Linux, AlmaLinux,Fedora.

30분 내에 로컬 컴퓨터를 모니터링하게 되며 고급 설치 절차 없이 기본 설치만 수행하면 오늘날 대부분의 Linux 서버에서 100% 작동합니다.

참고: 여기에 표시된 설치 지침은 RHEL 9.0 Linux 배포판을 기반으로 작성되었습니다.

Linux에 Nagios Core 및 Nagios 플러그인 설치

이 지침을 올바르게 따르면 다음 정보가 표시됩니다.

  • Nagios와 해당 플러그인은 /usr/local/nagios 디렉토리에 설치됩니다.
  • Nagios는 로컬 컴퓨터의 몇 가지 서비스(디스크 사용량, CPU 로드, 현재 사용자, 총 프로세스<)를 모니터링하도록 구성됩니다. /강한> 등)
  • Nagios 웹 인터페이스는 http://localhost/nagios에서 사용할 수 있습니다.

1단계: Apache 및 PHP 패키지 설치

Apache, PHPgcc, glibc, glibc-common과 같은 일부 라이브러리를 설치해야 합니다. ,GD 라이브러리와 해당 개발 라이브러리를 소스와 함께 Nagios를 설치하기 전에 확인하세요. 이를 위해 yum 패키지 설치 프로그램을 사용할 수 있습니다.

yum install -y httpd httpd-tools php gcc glibc glibc-common gd gd-devel make net-snmp

2단계: Nagios 사용자 및 그룹 생성

useradd 명령과 nagcmd 그룹 계정을 사용하여 새로운 nagios 사용자를 생성하고 비밀번호를 설정합니다.

[root@tecmint]# useradd nagios
[root@tecmint]# groupadd nagcmd

그런 다음 usermod 명령을 사용하여 nagios 사용자와 apache 사용자를 모두 nagcmd 그룹에 추가합니다.

[root@tecmint]# usermod -G nagcmd nagios
[root@tecmint]# usermod -G nagcmd apache

3단계: Nagios Core 및 Nagios 플러그인 다운로드

Nagios 설치 및 향후 모든 다운로드를 위한 디렉토리를 만듭니다.

[root@tecmint]# mkdir /root/nagios
[root@tecmint]# cd /root/nagios

이제 wget 명령을 사용하여 최신 Nagios Core 및 Nagios 플러그인 패키지를 다운로드하세요.

wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.9.tar.gz
wget https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz

4단계: Nagios Core 및 Nagios 플러그인 추출

다음과 같이 tar 명령을 사용하여 다운로드한 패키지를 추출해야 합니다.

tar -xf nagios-4.4.9.tar.gz
tar -xf nagios-plugins-2.3.3.tar.gz

이러한 타르볼을 추출하면 해당 디렉토리에 두 개의 새 폴더가 나타납니다.

ls -l

total 13804
drwxrwxr-x 21 root root     4096 Nov 17 02:22 nagios-4.4.9
-rw-r--r--  1 root root 11339450 Nov 17 03:08 nagios-4.4.9.tar.gz
drwxr-xr-x 15 root root     4096 Mar 11  2020 nagios-plugins-2.3.3
-rw-r--r--  1 root root  2782610 Mar 11  2020 nagios-plugins-2.3.3.tar.gz

5단계: Nagios Core 설치 및 구성

이제 먼저 Nagios Core를 구성하고 이를 위해 Nagios 디렉터리로 이동하여 구성 파일을 실행해야 합니다. 모든 것이 정상이면 출력이 다음과 같이 표시됩니다. 샘플 출력으로 끝납니다.

cd nagios-4.4.9/
./configure --with-command-group=nagcmd

Creating sample config files in sample-config/ ...


*** Configuration summary for nagios 4.4.9 2022-11-16 ***:

 General Options:
 -------------------------
        Nagios executable:  nagios
        Nagios user/group:  nagios,nagios
       Command user/group:  nagios,nagcmd
             Event Broker:  yes
        Install ${prefix}:  /usr/local/nagios
    Install ${includedir}:  /usr/local/nagios/include/nagios
                Lock file:  /run/nagios.lock
   Check the result directory:  /usr/local/nagios/var/spool/checkresults
           Init directory:  /lib/systemd/system
  Apache conf.d directory:  /etc/httpd/conf.d
             Mail program:  /usr/bin/mail
                  Host OS:  linux-gnu
          IOBroker Method:  epoll

 Web Interface Options:
 ------------------------
                 HTML URL:  http://localhost/nagios/
                  CGI URL:  http://localhost/nagios/cgi-bin/
 Traceroute (used by WAP):  


Review the options above for accuracy.  If they look okay,
type 'make all' to compile the main program and CGIs.

구성 후에는 make allmake install 명령을 사용하여 모든 바이너리를 컴파일하고 설치해야 합니다. 필요한 모든 라이브러리를 컴퓨터에 설치하고 계속 진행할 수 있습니다.

make all
make install
*** Main program, CGIs and HTML files installed ***

You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):

  make install-init
     - This installs the init script in /lib/systemd/system

  make install-commandmode
     - This installs and configures permissions on the
       directory for holding the external command file

  make install-config
     - This installs sample config files in /usr/local/nagios/etc

make[1]: Leaving directory '/root/nagios/nagios-4.4.9'

다음 명령은 Nagios용 init 스크립트를 설치합니다.

make install-init

Nagios가 명령줄에서 작동하도록 하려면 명령 모드를 설치해야 합니다.

make install-commandmode

다음으로 샘플 Nagios 파일을 설치하고 다음 명령을 실행하십시오.

make install-config
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg
/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg

*** Config files installed ***

Remember, these are *SAMPLE* config files.  You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.

6단계: Nagios 구성 사용자 정의

선택한 편집기로 "contacts.cfg" 파일을 열고 nagiosadmin 연락처 정의와 연결된 이메일 주소를 이메일 알림 수신으로 설정하세요.

vi /usr/local/nagios/etc/objects/contacts.cfg
###############################################################################
#
CONTACTS
#
###############################################################################

Just one contact defined by default - the Nagios admin (that's you)
This contact definition inherits a lot of default values from the
'generic-contact' template which is defined elsewhere.

define contact {

    contact_name            nagiosadmin             ; Short name of user
    use                     generic-contact         ; Inherit default values from generic-contact template (defined above)
    alias                   Nagios Admin            ; Full name of user
    email                   [email  ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}

7단계: Nagios용 웹 인터페이스 설치 및 구성

백엔드의 모든 구성이 완료되었습니다. 이제 다음 명령을 사용하여 Nagios용 웹 인터페이스를 구성하겠습니다. 아래 명령은 Nagios용 웹 인터페이스를 구성하고 웹 관리자 사용자가 "nagiosadmin"으로 생성됩니다.

make install-webconf

이 단계에서는 “nagiosadmin”에 대한 비밀번호를 생성합니다. 이 명령을 실행한 후 비밀번호를 두 번 입력하고 Nagios 웹 인터페이스에 로그인할 때 이 비밀번호가 사용되므로 기억해 두십시오.

htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin

새 설정을 적용하려면 Apache를 다시 시작하세요.

systemctl restart httpd

8단계: Nagios 플러그인 컴파일 및 설치

거기로 가서 아래 지시에 따라 구성하고 설치하십시오.

cd /root/nagios
cd nagios-plugins-2.3.3
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install

9단계: Nagios 구성 파일 확인

이제 Nagios 구성이 모두 완료되었으며 이를 확인하려면 다음 명령을 입력하세요. 모든 것이 순조롭게 진행되면 아래 출력과 비슷하게 표시됩니다.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Nagios Core 4.4.9
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2022-11-16
License: GPL

Website: https://www.nagios.org
Reading configuration data...
   Read main config file okay...
   Read object config files okay...

Running pre-flight check on configuration data...

Checking objects...
	Checked 8 services.
	Checked 1 hosts.
	Checked 1 host groups.
	Checked 0 service groups.
	Checked 1 contacts.
	Checked 1 contact groups.
	Checked 24 commands.
	Checked 5 time periods.
	Checked 0 host escalations.
	Checked 0 service escalations.
Checking for circular paths...
	Checked 1 hosts
	Checked 0 service dependencies
	Checked 0 host dependencies
	Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check

10단계: 시스템 시작에 Nagios 서비스 추가

재부팅 후에도 Nagios가 작동하도록 하려면 systemctl 명령을 사용하여 시스템 시작 시 nagioshttpd를 활성화해야 합니다.

systemctl enable nagios
systemctl enable httpd

그런 다음 Nagios를 다시 시작하여 새 설정을 적용하세요.

systemctl restart nagios

11단계: 방화벽에서 Nagios 웹 허용

Nagios 웹 인터페이스에 액세스하려면 다음 명령을 실행하여 Apache 포트를 열어야 합니다.

firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

12단계: Nagios 웹 인터페이스에 로그인

Nagios가 작동할 준비가 되었습니다. "http://Your-server-IP-address/nagios" 또는 "http://FQDN/nagios 를 사용하여 브라우저에서 엽니다. ” 및 사용자 이름 “nagiosadmin ” 및 비밀번호를 제공합니다.

Nagios 웹 대시보드

호스트 보기

Nagios 개요

서비스 보기

프로세스 보기

축하해요! Nagios와 해당 플러그인을 성공적으로 설치하고 구성했습니다. 이제 막 모니터링 여정을 시작하셨습니다.

Nagios 3.x를 Nagios Core 4.x로 업그레이드

이미 이전 버전의 Nagios를 실행하고 있다면 언제든지 업그레이드할 수 있습니다. 그러기 위해서는 최신 nagios 소스 tar 아카이브를 다운로드하고 아래와 같이 구성하면 됩니다.

systemctl stop nagios
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.9.tar.gz
tar -zxvf nagios-4.4.9.tar.gz
cd nagios-4.4.9
./configure
make all
make install
systemctl start nagios
결론

지금은 그게 다입니다. 다음 기사에서는 Linux, Windows, 프린터, 스위치, <를 추가하는 방법을 보여 드리겠습니다.장치를 Nagios 모니터링 서버에 추가합니다.

설치하는 동안 문제가 발생하면 댓글을 통해 문의해 주세요. 그때까지 계속 지켜봐주시고 Tecmint에 연결되어 계시도록 좋아요하고 공유하여 널리 알리는 것을 잊지 마세요.

추가 읽기:

  • Nagios 모니터링 서버에 Linux 호스트를 추가하는 방법
  • Nagios 모니터링 서버에 Windows 호스트를 추가하는 방법