Ubuntu 16.04에 Nagios를 설치하는 방법
이 튜토리얼은 다음 OS 버전에 대해 존재합니다.
- Ubuntu 10.04(Lucid Lynx)
이 페이지에서
- 전제 조건
- 이 튜토리얼에서 수행할 작업:\n
- 1단계 - Nagios 코어 다운로드 및 추출
- 2단계 - Nagios 컴파일
- 3단계 - Nagios 플러그인 설치\n
- 4단계 - Nagios 구성
- 1단계 - Apache 모듈 활성화\n
- 2단계 - Nagios 가상 호스트 활성화\n
- 3단계 - Apache 및 Nagios 시작
- 1단계 - 우분투 호스트에 연결\n
- 2단계 - NRPE 서비스 설치
- 3단계 - NRPE 구성
- 4단계 - NRPE 다시 시작
- 5단계 - Nagios 서버에 Ubuntu 호스트 추가\n
- 6단계 - 모든 서비스 다시 시작
- 7단계 - Ubuntu 호스트 테스트\n
Nagios는 시스템 및 네트워크 모니터링을 위한 오픈 소스 소프트웨어입니다. Nagios는 호스트 및 해당 서비스의 활동을 모니터링할 수 있으며 서버에서 문제가 발생하면 경고/알림을 제공합니다. Nagios는 Linux 운영 체제에서 실행할 수 있습니다. 현재 우분투 16.04를 사용하여 설치하고 있습니다.
전제 조건
- Ubuntu 16.04 - 64비트 서버 2개
- 1 - IP가 있는 Nagios 호스트: 192.168.1.9\n
- 2 - IP가 있는 Ubuntu 클라이언트: 192.168.1.10
이 튜토리얼에서 우리가 할 것:
- LAMP 등과 같은 패키지 의존성을 소프트웨어화합니다.\n
- 사용자 및 그룹 구성.
- Nagios 설치.
- Apache 구성.
- Nagios 서버 테스트.
- 모니터에 호스트 추가.\n
필수 구성 요소 설치
Nagios는 컴파일을 위한 gcc 컴파일러 및 빌드 필수 요소, Nagios 웹 인터페이스를 위한 LAMP(Apache, PHP, MySQL) 및 서버에서 경고를 보내기 위한 Sendmail이 필요합니다. 모든 패키지를 설치하려면 다음 명령을 실행하십시오(한 줄).
sudo apt-get install wget build-essential apache2 php apache2-mod-php7.0 php-gd libgd-dev sendmail unzip
사용자 및 그룹 구성
Nagios를 실행하려면 Nagios에 대한 새 사용자를 생성해야 합니다. 사용자 이름을 "nagios"로 지정하고 추가로 "nagcmd"라는 그룹을 만듭니다. 아래와 같이 새 사용자를 그룹에 추가합니다.
useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagios,nagcmd www-data나기오스 설치
1단계 - Nagios 코어 다운로드 및 추출
cd ~
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.2.0.tar.gz
tar -xzf nagios*.tar.gz
cd nagios-4.2.02단계 - Nagios 컴파일
Nagios를 빌드하기 전에 이전에 생성한 사용자 및 그룹으로 Nagios를 구성해야 합니다.
./configure --with-nagios-group=nagios --with-command-group=nagcmd
자세한 내용은 ./configure --help를 사용하십시오.
이제 Nagios를 설치하려면:
make all
sudo make install
sudo make install-commandmode
sudo make install-init
sudo make install-config
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-available/nagios.conf그리고 evenhandler 디렉토리를 nagios 디렉토리에 복사합니다.
cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers3단계 - Nagios 플러그인 설치
Nagios 플러그인 다운로드 및 추출:
cd ~
wget https://nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz
tar -xzf nagios-plugins*.tar.gz
cd nagios-plugin-2.1.2/아래 명령을 사용하여 Nagios 플러그인을 설치합니다.
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
make
make install4단계 - Nagios 구성
설치 단계가 완료되면 /usr/local/nagios/에서 Nagios의 기본 구성을 찾을 수 있습니다.
Nagios 및 Nagios 연락처를 구성합니다.
vim으로 기본 nagios 구성 편집:
vim /usr/local/nagios/etc/nagios.cfg
호스트 모니터 구성에 대한 51행의 주석을 제거하십시오.
cfg_dir=/usr/local/nagios/etc/servers
저장 및 종료.
서버라는 새 폴더를 추가합니다.
mkdir -p /usr/local/nagios/etc/servers
Nagios 연락처는 contact.cfg 파일에서 구성할 수 있습니다. 그것을 열려면 다음을 사용하십시오.
vim /usr/local/nagios/etc/objects/contacts.cfg
그런 다음 기본 이메일을 자신의 이메일로 바꿉니다.
아파치 구성
1단계 - Apache 모듈 활성화
sudo a2enmod rewrite
sudo a2enmod cgihtpasswd 명령을 사용하여 nagios 웹 인터페이스에 대한 사용자 nagiosadmin을 구성할 수 있습니다.
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
비밀번호를 입력합니다.
2단계 - Nagios 가상 호스트 활성화
sudo ln -s /etc/apache2/sites-available/nagios.conf /etc/apache2/sites-enabled/
3단계 - Apache 및 Nagios 시작
service apache2 restart
service nagios startNagios가 시작되면 다음 오류가 표시될 수 있습니다.
Starting nagios (via systemctl): nagios.serviceFailed
이를 수정하는 방법은 다음과 같습니다.
cd /etc/init.d/
cp /etc/init.d/skeleton /etc/init.d/nagios이제 Nagios 파일을 편집합니다.
vim /etc/init.d/nagios
... 그리고 다음 코드를 추가합니다.
DESC="Nagios"
NAME=nagios
DAEMON=/usr/local/nagios/bin/$NAME
DAEMON_ARGS="-d /usr/local/nagios/etc/nagios.cfg"
PIDFILE=/usr/local/nagios/var/$NAME.lock실행 가능하게 만들고 Nagios를 시작합니다.
chmod +x /etc/init.d/nagios
service apache2 restart
servuce nagios startNagios 서버 테스트
브라우저를 열고 Nagios 서버 IP(저의 경우 http://192.168.1.9/nagios)에 액세스하세요.
아파치 htpasswd로 Nagios 로그인.
Nagios 관리자 대시보드
모니터에 호스트 추가
이 튜토리얼에서는 위에서 만든 Nagios 서버에 모니터링할 Ubuntu 호스트를 추가합니다.
Nagios Server IP : 192.168.1.9
Ubuntu Host IP : 192.168.1.101단계 - 우분투 호스트에 연결
ssh
2단계 - NRPE 서비스 설치
sudo apt-get install nagios-nrpe-server nagios-plugins
3단계 - NRPE 구성
설치가 완료되면 nrpe 파일 /etc/nagios/nrpe.cfg를 편집합니다.
vim /etc/nagios/nrpe.cfg
... Nagios Server IP 192.168.1.9를 server_address에 추가합니다.
server_address=192.168.1.9
4단계 - NRPE 다시 시작
service nagios-nrpe-server restart
5단계 - Nagios 서버에 Ubuntu 호스트 추가
Nagios 서버에 연결하십시오:
ssh
그런 다음 /usr/local/nagios/etc/servers/에서 호스트 구성을 위한 새 파일을 만듭니다.
vim /usr/local/nagios/etc/servers/ubuntu_host.cfg
다음 줄을 추가합니다.
# Ubuntu Host configuration file define host { use linux-server host_name ubuntu_host alias Ubuntu Host address 192.168.1.10 register 1 } define service { host_name ubuntu_host service_description PING check_command check_ping!100.0,20%!500.0,60% max_check_attempts 2 check_interval 2 retry_interval 2 check_period 24x7 check_freshness 1 contact_groups admins notification_interval 2 notification_period 24x7 notifications_enabled 1 register 1 } define service { host_name ubuntu_host service_description Check Users check_command check_local_users!20!50 max_check_attempts 2 check_interval 2 retry_interval 2 check_period 24x7 check_freshness 1 contact_groups admins notification_interval 2 notification_period 24x7 notifications_enabled 1 register 1 } define service { host_name ubuntu_host service_description Local Disk check_command check_local_disk!20%!10%!/ max_check_attempts 2 check_interval 2 retry_interval 2 check_period 24x7 check_freshness 1 contact_groups admins notification_interval 2 notification_period 24x7 notifications_enabled 1 register 1 } define service { host_name ubuntu_host service_description Check SSH check_command check_ssh max_check_attempts 2 check_interval 2 retry_interval 2 check_period 24x7 check_freshness 1 contact_groups admins notification_interval 2 notification_period 24x7 notifications_enabled 1 register 1 } define service { host_name ubuntu_host service_description Total Process check_command check_local_procs!250!400!RSZDT max_check_attempts 2 check_interval 2 retry_interval 2 check_period 24x7 check_freshness 1 contact_groups admins notification_interval 2 notification_period 24x7 notifications_enabled 1 register 1 }
/usr/local/nagios/etc/objects/commands.cfg 파일에서 많은 check_command를 찾을 수 있습니다. DHCP, POP 등과 같은 더 많은 서비스를 추가하려면 여기를 참조하십시오.
이제 구성을 확인합니다.
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
... 구성이 올바른지 확인합니다.
6단계 - 모든 서비스 다시 시작
Ubuntu 호스트에서 NRPE 서비스를 시작합니다.
service nagios-nrpe-server restart
... 그리고 Nagios 서버에서 Apache와 Nagios를 시작합니다.
service apache2 restart
service nagios restart7단계 - Ubuntu 호스트 테스트
브라우저에서 Nagios 서버를 열고 모니터링 중인 ubuntu_host를 확인합니다.
Ubuntu 호스트는 모니터링되는 호스트에서 사용할 수 있습니다.
모든 서비스는 오류 없이 모니터링됩니다.
결론
Nagios는 시스템 모니터링을 위한 오픈 소스 애플리케이션입니다. Nagios는 구성이 쉽기 때문에 널리 사용되었습니다. 다양한 플러그인에서 Nagios를 지원하며 자신만의 플러그인을 만들 수도 있습니다. 자세한 내용은 여기를 참조하십시오.