Ubuntu 18.04 LTS에 Nagios 모니터링 소프트웨어를 설치하는 방법
이 튜토리얼은 다음 OS 버전에 대해 존재합니다.
- Ubuntu 10.04(Lucid Lynx)
이 페이지에서
- 1단계 - 패키지 종속성 설치
- 2단계 - Nagios Core 4.4.5 설치
- Nagios Core 4.4.5 다운로드
- Nagios 컴파일 및 설치
- nagiosadmin 사용자 만들기
- UFW 방화벽 설정\n
- Client01 서버에 NRPE 서버 설치
- Nagios 서버에 호스트 구성 추가\n
Nagios는 시스템 및 네트워크 모니터링을 위한 오픈 소스 소프트웨어입니다. Nagios는 호스트 및 해당 서비스의 활동을 모니터링하고 서버에서 문제가 발생하면 경고/알림을 제공할 수 있습니다. Nagios는 Linux 운영 체제에서 실행할 수 있으며 Ubuntu 18.04 서버를 사용합니다.
이 튜토리얼에서는 Ubuntu 18.04에 Nagios 4.4.x를 설치하는 단계별 과정을 보여줍니다. 소스에서 Nagios Core 4.4.x를 설치하고 nrpe 및 nagios 플러그인을 설치한 다음 모니터링할 호스트를 Nagios 서버에 추가합니다.
전제 조건
- Ubuntu 18.04 서버 2개
- Nagios 서버 - 호스트 이름: hakase-nagios, IP: 10.5.5.11\n
- Ubuntu 클라이언트 - 호스트 이름: client01, IP: 10.5.5.12\n
우리가 할 일:
- 패키지 종속성 설치
- Nagios Core 4.4.5 설치
- Nagios 플러그인 및 NRPE 플러그인 설치\n
- 모니터할 호스트를 Nagios 서버에 추가\n
- 테스트
1단계 - 패키지 종속성 설치
먼저 Ubuntu 리포지토리를 업데이트하고 Nagios 설치를 위한 일부 패키지 종속성을 설치합니다.
아래의 apt 명령을 사용하여 Ubuntu 리포지토리를 업데이트합니다.
sudo apt update
그런 다음 Nagios 설치를 위한 패키지 종속성을 설치합니다.
sudo apt install -y autoconf bc gawk dc build-essential gcc libc6 make wget unzip apache2 php libapache2-mod-php7.2 libgd-dev libmcrypt-dev make libssl-dev snmp libnet-snmp-perl gettext
그리고 Nagios 서버에 대한 패키지 종속성을 설치했습니다.
2단계 - Nagios Core 4.4.5 설치
이 단계에서는 최신 안정 버전인 Nagios Core 4.4.5를 설치합니다. 그리고 소스에서 수동으로 설치하겠습니다.
나기오스 코어 4.4.5 다운로드
홈 디렉토리로 이동하여 Nagios Core 소스 코드를 다운로드합니다.
cd ~/
wget https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.5.tar.gzNagios 패키지를 추출하고 추출된 Nagios 디렉토리로 이동합니다.
tar xzf nagios-4.4.5.tar.gz
cd nagioscore-nagios-4.4.5/Nagios 컴파일 및 설치
먼저 Nagios 소스 코드를 컴파일하고 Nagios용 Apache 가상 호스트 구성을 정의합니다.
sudo ./configure --with-httpd-conf=/etc/apache2/sites-enabled
sudo make allNagios 사용자 및 그룹을 생성하고 www-data Apache 사용자를 nagios 그룹에 추가합니다.
sudo make install-groups-users
sudo usermod -a -G nagios www-dataNagios 바이너리, 서비스 데몬 스크립트 및 명령 모드를 설치합니다.
sudo make install
sudo make install-daemoninit
sudo make install-commandmode그런 다음 샘플 스크립트 구성을 설치합니다.
sudo make install-config
그런 다음 Nagios용 Apache 구성을 설치하고 mod_rewrite 및 mode_cgi 모듈을 활성화합니다.
sudo make install-webconf
sudo a2enmod rewrite cgi이제 Apache 서비스를 다시 시작하십시오.
systemctl restart apache2
그리고 Nagios Core 4.4.5를 설치했습니다.
nagiosadmin 사용자 생성
Nagios Core를 설치한 후 Nagios 대시보드에 액세스하기 위한 기본 인증을 추가합니다. 그리고 기본 Apache 인증을 사용할 것입니다.
사용자 "nagiosadmin"에 대한 새 Apache 기본 인증을 만듭니다.
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
강력한 암호를 입력하십시오.
그리고 Nagios 대시보드 인증을 위해 새로운 사용자 nagiosadmin을 생성했습니다.
UFW 방화벽 설정
방화벽 구성을 위해 Apache 서비스와 Nagios 서버 포트를 UFW 방화벽에 추가해야 합니다.
아래 ufw 명령을 사용하여 Apache HTTP 포트와 Nagios 포트를 추가합니다.
sudo ufw allow Apache
이제 UFW 방화벽을 다시 로드하십시오.
sudo ufw reload
그리고 Ubuntu 18.04 서버에 Nagios Core 설치를 완료했습니다.
3단계 - Nagios 플러그인 및 NRPE 플러그인 설치
Nagios Core를 설치한 후 Nagios 플러그인과 NRPE 플러그인을 설치합니다.
Nagios 및 NRPE 플러그인은 기본적으로 Ubuntu 리포지토리에서 사용할 수 있습니다. 아래의 apt 명령을 사용하여 해당 패키지를 설치할 수 있습니다.
sudo apt install nagios-plugins nagios-nrpe-plugin
설치가 완료되면 nagios 설치 디렉토리 "/usr/local/nagios"로 이동하여 구성 파일 "nagios.cfg"를 편집합니다.
cd /usr/local/nagios/
vim nagios.cfg서버에 대한 추가 구성 디렉토리의 주석을 제거하십시오.
cfg_dir=/usr/local/nagios/etc/servers
저장하고 닫습니다.
이제 호스트 모니터 구성을 저장하는 데 사용할 새 디렉토리 "/usr/local/nagios/etc/servers"를 만듭니다.
mkdir -p /usr/local/nagios/etc/servers
그런 다음 "/usr/local/nagios/etc/" 디렉토리로 이동하여 "resurces.cfg" 구성 파일을 편집합니다.
cd /usr/local/nagios/etc/
vim resources.cfg아래와 같이 Nagios 플러그인의 기본 디렉토리를 변경합니다.
$USER1$=/usr/lib/nagios/plugins
저장하고 닫습니다.
다음으로 "objects/contacts.cfg" 구성 파일을 편집하여 nagios admin 연락처를 추가합니다.
vim objects/contacts.cfg
자신의 이메일 주소로 변경하십시오.
define contact{
......
email
}저장하고 닫습니다.
다음으로 구성 파일 "objects/commands.cfg"를 편집하여 nrpe 검사 명령을 정의합니다.
vim objects/commands.cfg
다음 구성을 줄 끝에 붙여넣습니다.
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}저장하고 닫습니다.
이제 Nagios 서비스를 시작하고 시스템 부팅에 추가하십시오.
systemctl start nagios
systemctl enable nagiosNagios 서비스가 실행 중입니다. 다음 명령을 사용하여 확인하십시오.
systemctl status nagios
아래는 결과입니다.
다음으로 새 Nagios 구성을 적용하려면 Apache 서비스를 다시 시작해야 합니다.
systemctl restart apache2
그런 다음 웹 브라우저를 열고 "nagios" URL 경로에 따라 서버 IP 주소를 입력합니다.
http://10.5.5.11/nagios/
"nagiosadmin" 사용자로 로그인하고 비밀번호를 입력하십시오.
그러면 아래와 같이 Nagios 대시보드가 표시됩니다.
결과적으로 Ubuntu 18.04 서버에 Nagios를 설치했습니다. 그리고 Nagios 서버에 호스트를 추가할 수 있습니다.
5단계 - 모니터에 Linux 호스트 추가
이 단계에서는 호스트 이름이 "client01"이고 IP 주소가 "10.5.5.12"인 Ubuntu 서버를 Nagios 서버에 추가합니다.
Client01 서버에 NRPE 서버 설치
ssh를 사용하여 "client01" 서버에 로그인합니다.
ssh
로그인한 후 Ubuntu 리포지토리를 업데이트하고 Nagios 플러그인 및 NRPE 서버를 설치합니다.
sudo apt update
sudo apt install nagios-nrpe-server nagios-plugins다음으로 NRPE 설치 디렉토리 "/etc/nagios"로 이동하여 구성 파일 "nrpe.cfg"를 편집합니다.
cd /etc/nagios/
vim nrpe.cfg"server_address" 행의 주석을 제거하고 "client01" IP 주소로 값을 변경하십시오.
server_address=10.5.5.12
"allowed_hosts" 줄 중 하나에 Nagios 서버 IP 주소 "10.5.5.11"을 추가합니다.
allowed_hosts=127.0.0.1,::1,10.5.5.11
저장하고 닫습니다.
다음으로 "nrpe_local.cfg" 구성을 편집합니다.
vim nrpe_local.cfg
"client01" IP 주소로 IP 주소를 변경하고 구성을 붙여넣습니다.
command[check_root]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /
command[check_ping]=/usr/lib/nagios/plugins/check_ping -H 10.5.5.12 -w 100.0,20% -c 500.0,60% -p 5
command[check_ssh]=/usr/lib/nagios/plugins/check_ssh -4 10.5.5.12
command[check_http]=/usr/lib/nagios/plugins/check_http -I 10.5.5.12
command[check_apt]=/usr/lib/nagios/plugins/check_apt저장하고 닫습니다.
이제 NRPE 서비스를 다시 시작하고 시스템 부팅에 추가합니다.
systemctl restart nagios-nrpe-server
systemctl enable nagios-nrpe-server그리고 Nagios NRPE 서버가 가동 및 실행 중입니다.
다음 명령을 사용하여 NRPE 서비스를 확인합니다.
systemctl status nagios-nrpe-server
NRPE 서비스가 실행 중입니다.
그런 다음 Nagios 서버로 돌아가 "client01" NRPE 서버를 확인합니다.
/usr/lib/nagios/plugins/check_nrpe -H 10.5.5.12
/usr/lib/nagios/plugins/check_nrpe -H 10.5.5.12 -c check_ping그러면 아래와 같은 결과를 얻게 됩니다.
그리고 "client01" 호스트에 Nagios NRPE 서버와 Nagios 플러그인을 설치했습니다.
Nagios 서버에 호스트 구성 추가
Nagios 서버 터미널로 돌아가서 "/usr/local/nagios/etc" 디렉토리로 이동하고 새 구성 "server/client01.cfg"를 만듭니다.
cd /usr/local/nagios/etc
vim servers/client01.cfgIP 주소와 호스트 이름을 자신의 것으로 변경하고 구성을 붙여넣습니다.
# Ubuntu Host configuration file1
define host {
use linux-server
host_name client01
alias Ubuntu Host
address 10.5.5.12
register 1
}
define service {
host_name client01
service_description PING
check_command check_nrpe!check_ping
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 client01
service_description Check Users
check_command check_nrpe!check_users
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 client01
service_description Check SSH
check_command check_nrpe!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 client01
service_description Check Root / Disk
check_command check_nrpe!check_root
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 client01
service_description Check APT Update
check_command check_nrpe!check_apt
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 client01
service_description Check HTTP
check_command check_nrpe!check_http
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
}저장하고 닫습니다.
이제 Nagios 서버를 다시 시작하십시오.
systemctl restart nagios
5단계 - 테스트
브라우저로 돌아가서 몇 분 동안 기다립니다.
"Hosts" 메뉴를 클릭하면 "client01"이 추가된 것을 볼 수 있습니다.
다음은 "client01" 서버에 대한 모니터링 내역입니다.
이제 모니터링할 호스트를 Nagios 서버에 추가했습니다.
그리고 Ubuntu 18.04 Server에 Nagios 4.4.5 설치가 성공적으로 완료되었습니다.
참조
- https://support.nagios.com/kb/