オープンソースの統合監視ソフトウェア「Nagios Server」
Nagiosは、Linux 上で実行するオープンソースの監視ソリューションです。
ネットワーク、アプリケーション、またはサーバーの重要なパラメーターを定期的にチェックするように設計されています。これらのパラメータには、マイクロプロセッサの負荷、実行中のプロセス数、ログ ファイル、ディスクおよびメモリの使用量の他、SMTP (Simple Mail Transfer Protocol)、HTTP (Hypertext Transfer Protocol)、POP3 ( Post Office Protocol 3)の他の多くのサービスもチェックできます。
Nagoisを実行するにはPHP、MySQLなどのデータベース、ApacheやNginxなどのWebサーバーが必要です。今回はこれらすべてが構成済みという前提で進めます。
1. 必要なパッケージをインストール
# dnf -y install gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel unzip wget gettext autoconf net-snmp-utils automake perl-Net-SNMP
2. Nagios Coreのインストール
①ダウンロード・展開
# wget https://go.nagios.org/get-core/4-5-12
# tar zxvf 4-5-12
# cd nagios-4.5.12
# ./configure
# make all
➁Nagios ユーザーとグループを作成
# make install-groups-users
groupadd -r nagios
useradd -g nagios nagios
➂Nagios グループに Apache ユーザーを追加
# usermod -aG nagios apache
④Nagios Core をインストール
# make install
⑤外部コマンド ファイルと権限をインストール
# make install-commandmode
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw
*** External command directory configured ***
⑥Nagios 構成ファイルをインストール
# make install-config
*** 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.
⑦Nagios 用の Apache 構成ファイルをインストール
# make install-webconf
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-available/nagios.conf
if [ 1 -eq 1 ]; then \
ln -s /etc/apache2/sites-available/nagios.conf /etc/apache2/sites-enabled/nagios.conf; \
fi
*** Nagios/Apache conf file installed ***
# systemctl restart httpd
⑧Systemdサービスファイルを作成(systemdユニットファイルをインストール)
# make install-daemoninit
/usr/bin/install -c -m 755 -d -o root -g root /lib/systemd/system
/usr/bin/install -c -m 755 -o root -g root startup/default-service /lib/systemd/system/nagios.service
Created symlink '/etc/systemd/system/multi-user.target.wants/nagios.service' → '/usr/lib/systemd/system/nagios.service'.
*** Init script installed ***
3. Nagios プラグインをインストール
①Nagiosプラグインに必要な前提条件をインストール
# dnf install -y gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils postgresql-devel openldap-devel bind-utils samba-client fping openssh-clients lm_sensors perl-Net-SNMP
➁Nagios Pluginsページから最新の codeをダウンロード
# cd
# wget https://nagios-plugins.org/download/nagios-plugins-2.5.tar.gz
➂インストール
# tar -xvf nagios-plugins-2.5.tar.gz
# cd nagios-plugins-2.5
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# make
# make install
下記のとおりnagios-pluginsが利用可能である
# ls /usr/local/nagios/libexec
check_apt check_dummy check_ifstatus check_mrtgtraf check_overcr check_snmp check_uptime
check_breeze check_file_age check_imap check_nagios check_pgsql check_spop check_users
check_by_ssh check_flexlm check_ircd check_nntp check_ping check_ssh check_wave
check_clamd check_fping check_jabber check_nntps check_pop check_ssl_validity negate
check_cluster check_ftp check_ldap check_nt check_procs check_ssmtp remove_perfdata
check_dhcp check_hpjd check_ldaps check_ntp check_real check_swap urlize
check_dig check_http check_load check_ntp_peer check_rpc check_tcp utils.pm
check_disk check_icmp check_log check_ntp_time check_sensors check_time utils.sh
check_disk_smb check_ide_smart check_mailq check_nwstat check_simap check_udp
check_dns check_ifoperstatus check_mrtg check_oracle check_smtp check_ups
4. Nagios Web ユーザーの作成
Nagios Web ダッシュボードにアクセスするためのユーザー アカウントを作成する。このユーザーアカウントは、認証に使用される。
ユーザーのデフォルト名はnagiosadminで、/usr/local/nagios/etc/cgi.cfgファイル内に優先ユーザー名として定義されています。
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password: [password]
Re-type new password: [again password]
Adding password for user nagiosadmin
所有権と権限を設定
# chown apache:apache /usr/local/nagios/etc/htpasswd.users
# chmod 640 /usr/local/nagios/etc/htpasswd.users
5. Nagios 起動
Apache を再起動
# systemctl restart httpd
Nagios サービスを開始と有効
# systemctl enable nagios --now
# systemctl start nagios
サービスが実行しているか確認
# systemctl status nagios
● nagios.service - Nagios Core 4.5.12
Loaded: loaded (/usr/lib/systemd/system/nagios.service; enabled; preset: disabled)
Active: active (running) since Thu 2026-06-04 14:20:50 JST; 27s ago
Invocation: fb46e7bbbaf642819737e8e3e238e4d3
Docs: https://www.nagios.org/documentation
Process: 44911 ExecStartPre=/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (code=exited, status=0>
Process: 44913 ExecStart=/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SU>
Main PID: 44914 (nagios)
Tasks: 6 (limit: 22808)
Memory: 6.9M (peak: 8.4M)
CPU: 210ms
CGroup: /system.slice/nagios.service
├─44914 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
├─44916 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
├─44917 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
├─44918 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
├─44919 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
└─44927 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
Jun 04 14:20:50 Lepard nagios[44914]: qh: Socket '/usr/local/nagios/var/rw/nagios.qh' successfully initialized
Jun 04 14:20:50 Lepard nagios[44914]: qh: core query handler registered
Jun 04 14:20:50 Lepard nagios[44914]: qh: echo service query handler registered
Jun 04 14:20:50 Lepard nagios[44914]: qh: help for the query handler registered
Jun 04 14:20:50 Lepard nagios[44914]: wproc: Successfully registered manager as @wproc with query handler
Jun 04 14:20:50 Lepard nagios[44914]: wproc: Registry request: name=Core Worker 44916;pid=44916
Jun 04 14:20:50 Lepard nagios[44914]: wproc: Registry request: name=Core Worker 44917;pid=44917
Jun 04 14:20:50 Lepard nagios[44914]: wproc: Registry request: name=Core Worker 44919;pid=44919
Jun 04 14:20:50 Lepard nagios[44914]: wproc: Registry request: name=Core Worker 44918;pid=44918
Jun 04 14:20:51 Lepard nagios[44914]: Successfully launched command file worker with pid 44927
6. Nagios Web インターフェイスにアクセス
任意のブラウザで http://[IP_Address]/nagios/にアクセスし[Username]にnagiosadmin、[Password]には上記でユーザーを作成したとき指定したパスワードを入力し、[ログイン]

ログインに成功すると、以下のダッシュボードが表示されます。

ホストの可用性を表示
左メニューの[Hosts]をクリック
現状ではNagios Serverのみ表示されている

左メニューの [Tactical Overview] をクリックすると監視データを閲覧できる

左メニューの [Current Status] [Services] をクリック : 現在の監視サービス内容が表示される

7. Nagios エージェントの構成
エージェントを監視するため。以下をインストールする
• プラグインを実行するNRPE Agent
① Nagios NRPE Agentのインストール
# cd
# wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-4.1.3/nrpe-4.1.3.tar.gz
# tar zxvf nrpe-4.1.3.tar.gz
# cd nrpe-4.1.3
# ./configure
# make check_nrpe
# make install-plugin
➁ファイアウォールでNRPEのポートを開く
NRPEはデフォルトでTCP 5666ポートを使用します。ファイアウォールが動作している場合は、Nagiosモニタリングサーバーからの外部チェックを許可するために、このポートを開きます。
# firewall-cmd --add-port=5666/tcp
# firewall-cmd --reload
8. 監視ホストの追加
下記サーバーをホストに追加し、 単純なPing による死活監視対象として設定
OS : RockyLinux10.1
IPアドレス : 192.168.11.85
①設定ファイル編集
# vi /usr/local/nagios/etc/nagios.cfg
51行目 : コメント解除
cfg_dir=/usr/local/nagios/etc/servers
➁ ディレクトリー作成
# mkdir /usr/local/nagios/etc/servers
# chgrp nagios /usr/local/nagios/etc/servers
# chmod 750 /usr/local/nagios/etc/servers
➂ 定義ファイル新規作成
"korodes.cfg" 名称は任意でよい
# vi /usr/local/nagios/etc/servers/korodes.cfg
define host {
use linux-server
host_name korodes
alias korodes
address 192.168.11.85
}
define service {
use generic-service
host_name korodes
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
④ Nagiosサーバー再起動
# systemctl restart nagios.service
Nagios サーバーにログイン(http://[サーバーIPアドレス]/nagios)しHostsを見るとホストが追加されている

9. 監視サービスの追加
上記で追加したホストに監視サービスを追加する
OS : RockyLinux10.1
IPアドレス : 192.168.11.85
NRPEデーモンとNagiosプラグインをインストールする必要があります。
9.1 監視対象サーバー側の設定
①Nagiosプラグインをインストール
# dnf install -y gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils postgresql-devel openldap-devel bind-utils samba-client fping openssh-clients lm_sensors perl-Net-SNMP
# cd
# wget https://nagios-plugins.org/download/nagios-plugins-2.5.tar.gz
# tar -xvf nagios-plugins-2.5.tar.gz
# cd nagios-plugins-2.5
# ./configure
# make
# make install
➁ 監視対象ホストにNRPEエージェントをインストール
# dnf install -y gcc glibc glibc-common openssl openssl-devel perl wget
# cd
# wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-4.1.3/nrpe-4.1.3.tar.gz
# tar zxvf nrpe-4.1.3.tar.gz
# cd nrpe-4.1.3
# ./configure --enable-command-args
# make all
ユーザーとグループを作成
# make install-groups-users
groupadd -r nagios
useradd -r -g nagios nagios
NRPEバイナリ、NRPEデーモン、およびcheck_npreプラグインをインストール
# make install
設定ファイルをインストール
# make install-config
サービスファイルを更新
# sh -c "echo >> /etc/services"
# sh -c "echo '# Nagios services' >> /etc/services"
# sh -c "echo 'nrpe 5666/tcp' >> /etc/services"
NPREサービスデーモンをインストール
# make install-init
# systemctl enable nrpe
➂ファイアウォールでNRPEのポートを開く
NRPEはデフォルトでTCP 5666ポートを使用します。ファイアウォールが動作している場合は、Nagiosモニタリングサーバーからの外部チェックを許可するために、このポートを開きます。
# firewall-cmd --add-port=5666/tcp
# firewall-cmd --add-port=5666/udp
# firewall-cmd --reload
④ 設定ファイル編集
# vi /usr/local/nagios/etc/nrpe.cfg
106行目 : 接続を許可するホストを追記 (Nagios サーバーを指定)
allowed_hosts=127.0.0.1,::1,192.168.11.83
122行目 : コマンドの引数を許可
dont_blame_nrpe=1
300-304行目コメントにし、その下に追加
# command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
# command[check_load]=/usr/lib/nagios/plugins/check_load -r -w .15,.10,.05 -c .30,.25,.20
# command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1
# command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z
# command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200
pluginの一部を追加する
command[check_by_ssh]=/usr/lib/nagios/plugins/check_by_ssh $ARG1$
command[check_dhcp]=/usr/lib/nagios/plugins/check_dhcp $ARG1$
command[check_disk]=/usr/lib/nagios/plugins/check_disk $ARG1$
command[check_file_age]=/usr/lib/nagios/plugins/check_file_age $ARG1$
command[check_ftp]=/usr/lib/nagios/plugins/check_ftp $ARG1$
command[check_http]=/usr/lib/nagios/plugins/check_http $ARG1$
command[check_imap]=/usr/lib/nagios/plugins/check_imap $ARG1$
command[check_load]=/usr/lib/nagios/plugins/check_load $ARG1$
command[check_log]=/usr/lib/nagios/plugins/check_log $ARG1$
command[check_mysql]=/usr/lib/nagios/plugins/check_mysql $ARG1$
command[check_ntp]=/usr/lib/nagios/plugins/check_ntp $ARG1$
command[check_ntp_peer]=/usr/lib/nagios/plugins/check_ntp_peer $ARG1$
command[check_ntp_time]=/usr/lib/nagios/plugins/check_ntp_time $ARG1$
command[check_ping]=/usr/lib/nagios/plugins/check_ping $ARG1$
command[check_pop]=/usr/lib/nagios/plugins/check_pop $ARG1$
command[check_spop]=/usr/lib/nagios/plugins/check_spop $ARG1$
command[check_procs]=/usr/lib/nagios/plugins/check_procs $ARG1$
command[check_smtp]=/usr/lib/nagios/plugins/check_smtp $ARG1$
command[check_ssmtp]=/usr/lib/nagios/plugins/check_ssmtp $ARG1$
command[check_ssh]=/usr/lib/nagios/plugins/check_ssh $ARG1$
command[check_swap]=/usr/lib/nagios/plugins/check_swap $ARG1$
command[check_tcp]=/usr/lib/nagios/plugins/check_tcp $ARG1$
command[check_udp]=/usr/lib/nagios/plugins/check_udp $ARG1$
command[check_ups]=/usr/lib/nagios/plugins/check_ups $ARG1$
command[check_users]=/usr/lib/nagios/plugins/check_users $ARG1$
⑤ nrpeサーバー有効化、起動
# systemctl start nrpe
※NRPEが動作しているか確認のためNagiosサーバー側で下記コマンドを実行して下記のようになればOK
# /usr/local/nagios/libexec/check_nrpe -H 192.168.11.85
NRPE v4.1.3
9.2 Nagios サーバー側の設定
① nrpeプラグインのインストール
# dnf install -y gcc glibc glibc-common openssl openssl-devel perl wget
# cd
# wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-4.1.3/nrpe-4.1.3.tar.gz
# tar zxvf nrpe-4.1.3.tar.gz
# cd nrpe-4.1.3
# ./configure --enable-command-args
# make all
➁NRPEバイナリ、NRPEデーモン、およびcheck_npreプラグインをインストール
# make install
➂設定ファイルをインストール
# make install-config
④サービスファイルを更新
# sh -c "echo >> /etc/services"
# sh -c "echo '# Nagios services' >> /etc/services"
# sh -c "echo 'nrpe 5666/tcp' >> /etc/services"
⑤NPREサービスデーモンをインストール
# make install-init
# systemctl enable nrpe
⑥ commands.cfg編集
# vi /usr/local/nagios/etc/objects/commands.cfg
最終行に追記
define command {
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
⑦先ほどホストを追加したときに作成した korodes.cfg を編集する
今回はHTTP,SSH,FTPを追加してみる
# vi /usr/local/nagios/etc/servers/korodes.cfg
# 以下を追加する
# 'HTTP' command definition
define service{
use local-service
host_name korodes
service_description HTTP
check_command check_http
}
# 'SSH' command definition
define service{
use local-service
host_name korodes
service_description SSH
check_command check_ssh
}
# 'FTP' command definition
define service{
use local-service
host_name korodes
service_description FTP
check_command check_ftp
}
⑧ Nagios 再起動
# systemctl restart nagios.service
⑨ http://[Nagios Server IP Address]/nagios にアクセスする
下図のように新しく追加した監視サービスが追加されている

