オープンソースの統合監視ソフトウェア「Nagios Server」インストール
Nagiosは、Linux 上で実行するオープンソースの監視ソリューションです。
Nagiosは、 Ethan Galstadによって開発され、 1999 年に最初にリリースされました。その後、このプロジェクトは、いくつかの貢献者によってオープンソース プロジェクトとして改良されました。
Nagiosは、ネットワーク、アプリケーション、またはサーバーの重要なパラメーターを定期的にチェックするように設計されています。これらのパラメータには、マイクロプロセッサの負荷、実行中のプロセス数、ログ ファイル、ディスクおよびメモリの使用量の他、SMTP (Simple Mail Transfer Protocol)、HTTP (Hypertext Transfer Protocol)、POP3 ( Post Office Protocol 3)の他の多くのサービスもチェックできます。
Nagoisを実行するにはPHP、MySQLなどのデータベース、ApacheやNginxなどのWebサーバーが必要です。今回はこれらすべてが構成済みという前提で進めます。
1. 必要なパッケージをインストール
# apt update
# apt install -y autoconf gcc libc6 make wget unzip libgd-dev
2. Nagios Coreのインストール
①ダウンロード/インストール
# wget https://go.nagios.org/get-core/4-5-12
# apt install libssl-dev
# 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 www-data
④Nagios Core をインストール
# make install
⑤Nagios の init スクリプトをインストール
# make install-init
/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
⑥外部コマンド ファイルと権限をインストール
# 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 ***
# a2enmod cgi
# systemctl restart apache2
3. Nagios プラグインをインストール
①Nagios Pluginsページから最新の codeをダウンロード
# wget https://nagios-plugins.org/download/nagios-plugins-2.4.9.tar.gz
②インストール
# tar -xvf nagios-plugins-2.4.9.tar.gz
# cd nagios-plugins-2.4.9
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
# make
# make install
③必要なディレクトリを作成
# mkdir -p /usr/local/nagios/var/spool/checkresults
# chown -R nagios:nagios /usr/local/nagios/var/spool/checkresults
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 www-data:www-data /usr/local/nagios/etc/htpasswd.users
# chmod 640 /usr/local/nagios/etc/htpasswd.users
Apache を再起動
# systemctl restart apache2
ファイアウォールで HTTP サービスポートを解放します
# ufw allow http
# ufw reload
Nagios サービスを開始と有効
# systemctl enable nagios --now
Created symlink /etc/systemd/system/multi-user.target.wants/nagios.service → /lib/systemd/system/nagios.service.
サービスが実行しているか確認
# systemctl status nagios
● nagios.service - Nagios Core 4.5.12
Loaded: loaded (/lib/systemd/system/nagios.service; enabled; preset: enabled)
Active: active (running) since Fri 2026-05-29 15:22:49 JST; 36s ago
Docs: https://www.nagios.org/documentation
Process: 44724 ExecStartPre=/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (code=exited, s>
Process: 44725 ExecStart=/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg (code=exited, stat>
Main PID: 44726 (nagios)
Tasks: 6 (limit: 4554)
Memory: 5.7M
CPU: 201ms
CGroup: /system.slice/nagios.service
tq44726 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
tq44727 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
tq44728 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
tq44729 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
tq44730 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
mq44731 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
May 29 15:22:49 Lepard nagios[44726]: qh: Socket '/usr/local/nagios/var/rw/nagios.qh' successfully initialized
May 29 15:22:49 Lepard nagios[44726]: qh: core query handler registered
May 29 15:22:49 Lepard nagios[44726]: qh: echo service query handler registered
May 29 15:22:49 Lepard nagios[44726]: qh: help for the query handler registered
May 29 15:22:49 Lepard nagios[44726]: wproc: Successfully registered manager as @wproc with query handler
5. Nagios Web インターフェイスにアクセス
任意のブラウザで http://[IP_Address]/nagios/にアクセスし[Username]にnagiosadmin、[Password]には上記でユーザーを作成したとき指定したパスワードを入力し、[Sign in]
ログインに成功すると、以下のダッシュボードが表示されます。

ホストの可用性を表示
左メニューの[Hosts]をクリック
nagios serverのみ表示される

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

左メニューの [Current Status] [Services] をクリック

6. Nagios エージェントの構成
エージェントを監視するため。以下をインストールする
• プラグインを実行するNRPE Agent
6.1 Nagios NRPE Agentのインストール
NRPE エージェントは、デフォルトの Debian リポジトリで利用可能
# apt-cache policy nagios-nrpe-server
nagios-nrpe-server:
Installed: (none)
Candidate: 4.1.0-1+b1
Version table:
4.1.0-1+b1 500
500 http://deb.debian.org/debian bookworm/main amd64 Packages
# apt install -y nagios-nrpe-server
バージョン確認
# nrpe -V
NRPE - Nagios Remote Plugin Executor
Version: 4.1.0
サービスを開始して有効にする
# systemctl enable --now nagios-nrpe-server
Synchronizing state of nagios-nrpe-server.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable nagios-nrpe-server
NRPEエージェントのステータスを確認
# systemctl status nagios-nrpe-server
● nagios-nrpe-server.service - Nagios Remote Plugin Executor
Loaded: loaded (/lib/systemd/system/nagios-nrpe-server.service; enabled; preset: enabled)
Active: active (running) since Fri 2026-05-29 15:35:09 JST; 1min 36s ago
Docs: http://www.nagios.org/documentation
Main PID: 44952 (nrpe)
Tasks: 1 (limit: 4554)
Memory: 1.2M
CPU: 6ms
CGroup: /system.slice/nagios-nrpe-server.service
mq44952 /usr/sbin/nrpe -c /etc/nagios/nrpe.cfg -f
May 29 15:35:09 Lepard systemd[1]: Started nagios-nrpe-server.service - Nagios Remote Plugin Executor.
May 29 15:35:09 Lepard nrpe[44952]: Starting up daemon
May 29 15:35:09 Lepard nrpe[44952]: Server listening on 0.0.0.0 port 5666.
May 29 15:35:09 Lepard nrpe[44952]: Server listening on :: port 5666.
May 29 15:35:09 Lepard nrpe[44952]: Listening for connections on port 5666
May 29 15:35:09 Lepard nrpe[44952]: Allowing connections from: 127.0.0.1,::1
ファイアウォールでNRPEのポートを開く
NRPEはデフォルトでTCP 5666ポートを使用します。ファイアウォールが動作している場合は、Nagiosモニタリングサーバーからの外部チェックを許可するために、このポートを開きます。
# ufw allow 5666/tcp
# ufw reload
ポート5666/tcpがリッスンされているか確認
# ss -altnp | grep 5666
LISTEN 0 5 0.0.0.0:5666 0.0.0.0:* users:(("nrpe",pid=44952,fd=4))
LISTEN 0 5 [::]:5666 [::]:* users:(("nrpe",pid=44952,fd=5))
7. 監視ホストの追加
下記サーバーをホストに追加し、 単純なPing による死活監視対象として設定
OS : Debian12.11
IPアドレス : 192.168.11.85
7.1 設定ファイル編集
# vi /usr/local/nagios/etc/nagios.cfg
51行目 : コメント解除
cfg_dir=/usr/local/nagios/etc/servers
7.2 ディレクトリー作成
# mkdir /usr/local/nagios/etc/servers
# chgrp nagios /usr/local/nagios/etc/servers
# chmod 750 /usr/local/nagios/etc/servers
7.3 定義ファイル新規作成
korodes.cfgのkorodesは任意の名称でよい
# 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%
}
7.4 Nagiosサーバー再起動
# systemctl restart nagios.service
Nagios サーバーにログイン(http://[サーバーIPアドレス]/nagios)しHostsを見るとホストが追加されている

8. 監視サービスの追加
上記で追加したホストに監視サービスを追加する
OS : Debian12.11
IPアドレス : 192.168.11.85
8.1 監視対象サーバー側の設定
8.1.1 監視対象ホストにエージェントをインストール
# apt install -y nagios-nrpe-server
8.1.2 設定ファイル編集
# vi /etc/nagios/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
以下追加
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$
8.1.3 nrpeサーバー有効化、起動
# /etc/init.d/nagios-nrpe-server status
● nagios-nrpe-server.service - Nagios Remote Plugin Executor
Loaded: loaded (/lib/systemd/system/nagios-nrpe-server.service; enabled; preset: enabled)
Active: active (running) since Fri 2026-05-29 15:45:15 JST; 3min 10s ago
Docs: http://www.nagios.org/documentation
Main PID: 3199 (nrpe)
Tasks: 1 (limit: 2255)
Memory: 1.3M
CPU: 15ms
CGroup: /system.slice/nagios-nrpe-server.service
└─3199 /usr/sbin/nrpe -c /etc/nagios/nrpe.cfg -f
May 29 15:45:15 Lion systemd[1]: Started nagios-nrpe-server.service - Nagios Remote Plugin Executor.
May 29 15:45:15 Lion nrpe[3199]: Starting up daemon
May 29 15:45:15 Lion nrpe[3199]: Server listening on 0.0.0.0 port 5666.
May 29 15:45:15 Lion nrpe[3199]: Server listening on :: port 5666.
May 29 15:45:15 Lion nrpe[3199]: Listening for connections on port 5666
May 29 15:45:15 Lion nrpe[3199]: Allowing connections from: 127.0.0.1,::1
8.1.4 ファイアウォールでNRPEのポート5666/tcp,5666/udpを開く
# ufw allow 5666/tcp
# ufw allow 5666/udp
# ufw reload
8.2 Nagios サーバー側の設定
8.2.1 nrpeプラグインのインストール
# apt install nagios-nrpe-plugin
8.2.2 nagiosプラグインディレクトリーにコピー
# cp /usr/lib/nagios/plugins/check_nrpe /usr/local/nagios/libexec/
8.2.3 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$
}
8.2.4 先ほどホスト追加したときに作成した 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
}
8.2.5 Nagios 再起動
# systemctl restart nagios.service
8.2.6 http://[Nagios Server IP Address]/nagios にアクセスする
下図のように新しく追加した監視サービスが追加されている

