웹사이트 검색

CentOS 6에 Nagios를 설치하는 방법


상태: 더 이상 사용되지 않음

이 문서에서는 더 이상 지원되지 않는 CentOS 버전에 대해 설명합니다. 현재 CentOS 6을 실행하는 서버를 운영 중인 경우 지원되는 버전의 CentOS로 업그레이드하거나 마이그레이션하는 것이 좋습니다.

이유:

대신 참조:

다음 DigitalOcean 튜토리얼은 CentOS 7 서버에 Nagios를 설치하는 방법을 설명하므로 즉시 관심을 가질 수 있습니다.

  • CentOS 7에서 Nagios 4를 설치하고 서버를 모니터링하는 방법

1단계 - 모니터링 서버에 패키지 설치

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
yum -y install nagios nagios-plugins-all nagios-plugins-nrpe nrpe php httpd
chkconfig httpd on && chkconfig nagios on
service httpd start && service nagios start

또한 이 드롭릿에서 최소 2GB의 SWAP 메모리를 활성화해야 합니다.

dd if=/dev/zero of=/swap bs=1024 count=2097152
mkswap /swap && chown root. /swap && chmod 0600 /swap && swapon /swap
echo /swap swap swap defaults 0 0 >> /etc/fstab
echo vm.swappiness = 0 >> /etc/sysctl.conf && sysctl -p

2단계 - 암호 보호 설정

Nagios 관리자 패널 비밀번호 설정:

htpasswd -c /etc/nagios/passwd nagiosadmin

이 사용자 이름을 "nagiosadmin"으로 유지해야 합니다. 그렇지 않으면 /etc/nagios/cgi.cfg를 변경하고 인증된 관리자를 다시 정의해야 합니다.

이제 드롭릿 IP 주소 http://IP/nagios로 이동하여 로그인할 수 있습니다.

2단계에서 설정한 비밀번호를 입력하라는 메시지가 표시됩니다.

Nagios 관리자 패널은 다음과 같습니다.

새로 설치하는 것이므로 현재 모니터링 중인 호스트가 없습니다.

이제 Nagios에서 모니터링할 호스트를 추가해야 합니다. 예를 들어 cloudmail.tk(198.211.107.218) 및 emailocean.tk(198.211.112.99)를 사용합니다.

공용 포트에서 ping, 웹 서버, 이메일 서버 등과 같은 열린 포트를 모니터링할 수 있습니다.

MySQL, memcached, 시스템 서비스와 같이 localhost에서 수신하는 내부 서비스의 경우 NRPE를 사용해야 합니다.

4단계 - 클라이언트에 NRPE 설치

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
yum -y install nagios nagios-plugins-all nrpe
chkconfig nrpe on

다음 단계에서는 모니터링 서버가 NRPE를 통해 이러한 클라이언트 호스트에 보낼 수 있는 수동 명령을 지정합니다.

allowed_hosts를 원하는 값으로 변경해야 합니다.

/etc/nagios/nrpe.cfg 편집

log_facility=daemon
pid_file=/var/run/nrpe/nrpe.pid
server_port=5666
nrpe_user=nrpe
nrpe_group=nrpe
allowed_hosts=198.211.117.251
dont_blame_nrpe=1
debug=0
command_timeout=60
connection_timeout=300
include_dir=/etc/nrpe.d/
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_disk]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/vda
command[check_zombie_procs]=/usr/lib64/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib64/nagios/plugins/check_procs -w 150 -c 200
command[check_procs]=/usr/lib64/nagios/plugins/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$

메모:

위의 check_disk에서 확인 중인 파티션은 /dev/vda입니다. df -h /를 실행하여 드롭릿에 동일한 파티션이 있는지 확인하세요.

또한 모니터링 서버에서 해당 클라이언트로의 연결을 허용하고 다른 모든 사용자를 차단하도록 방화벽 규칙을 설정해야 합니다.

iptables -N NRPE
iptables -I INPUT -s 0/0 -p tcp --dport 5666 -j NRPE
iptables -I NRPE -s 198.211.117.251 -j ACCEPT
iptables -A NRPE -s 0/0 -j DROP
/etc/init.d/iptables save

이제 모든 클라이언트 호스트에서 NRPE를 시작할 수 있습니다.

service nrpe start

5단계 - 모니터링 서버에 서버 구성 추가

모니터링 서버로 돌아가서 각 클라이언트 서버에 대한 구성 파일을 만들어야 합니다.

echo "cfg_dir=/etc/nagios/servers" >> /etc/nagios/nagios.cfg
cd /etc/nagios/servers
touch cloudmail.tk.cfg
touch emailocean.tk.cfg

각 클라이언트 구성 파일을 편집하고 모니터링할 서비스를 정의합니다.

nano /etc/nagios/servers/cloudmail.tk.cfg

다음 줄을 추가합니다.

define host {
        use                     linux-server
        host_name               cloudmail.tk
        alias                   cloudmail.tk
        address                 198.211.107.218
        }

define service {
        use                             generic-service
        host_name                       cloudmail.tk
        service_description             PING
        check_command                   check_ping!100.0,20%!500.0,60%
        }

define service {
        use                             generic-service
        host_name                       cloudmail.tk
        service_description             SSH
        check_command                   check_ssh
        notifications_enabled           0
        }

define service {
        use                             generic-service
        host_name                       cloudmail.tk
        service_description             Current Load
        check_command                   check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
        }

원하는 대로 모니터링할 서비스를 더 추가할 수 있습니다. IP 주소와 host_name이 다른 두 번째 클라이언트 emailocean.tk에 대해 동일한 구성을 추가해야 합니다.

이것은 /etc/nagios/servers/emailocean.tk.cfg의 스니펫입니다.

define host {
        use                     linux-server
        host_name               emailocean.tk
        alias                   emailocean.tk
        address                 198.211.112.99
        }

...

모니터링할 추가 클라이언트를 /etc/nagios/servers/AnotherHostName.cfg로 추가할 수 있습니다.

마지막으로 모든 클라이언트 구성을 추가한 후 폴더 권한을 올바르게 설정하고 모니터링 서버에서 Nagios를 다시 시작해야 합니다.

chown -R nagios. /etc/nagios
service nagios restart

6단계 - Nagios에서 호스트 모니터링

모니터링 서버 IP 주소 http://IP/nagios로 이동하여 2단계에서 설정한 비밀번호를 입력합니다.

이제 모든 호스트와 서비스를 볼 수 있습니다.

그리고 당신은 모두 끝났습니다!