Nagiosインストール · 3 min read · Oct 19, 2025
CentOSにNagios Coreをインストールする方法
Nagiosは、システムおよびネットワーク監視のためのオープンソースソフトウェアです。Nagiosはホストとそのサービスの活動を監視し、サーバーで何か悪いことが起こった場合に警告/アラートを提供します。NagiosはLinuxオペレーティングシステムで実行でき、CentOS 8サーバーを使用します。
このチュートリアルでは、CentOS 8システムにNagios Coreをインストールする方法を示します。EPELリポジトリからNagios Core 4.4.5をインストールし、その後NagiosサーバーにCentOS 8ホストモニターを追加します。
前提条件
- 2つのCentOS 8サーバー - Nagiosサーバー - ホスト名: hakase-nagios、IP: 10.5.5.20
- CentOSクライアント - ホスト名: client01、IP: 10.5.5.21
- ルート権限
私たちが行うこと:
- EPELリポジトリをインストール
- Nagios Core 4.4.5をインストール
- NagiosプラグインとNRPEプラグインをインストール
- Nagiosサーバーに監視するホストを追加
- ホストモニターの設定を追加
- テスト
ステップ1 - EPELリポジトリをインストール
まず、CentOS 8システムにEPEL(Enterprise Linux用の追加パッケージ)リポジトリを追加します。EPELリポジトリからNagiosパッケージをインストールします。
以下のdnfコマンドを使用してEPELリポジトリをインストールします。
sudo dnf install epel-releaseインストールが完了したら、システム上のすべての利用可能なリポジトリを確認します。
sudo dnf repolistこれでEPELリポジトリがCentOS 8システムに追加されました。

ステップ2 - Nagios Coreをインストールおよび設定
このステップでは、CentOS 8システムにNagiosサーバー4.4.5の最新の安定版をインストールおよび設定します。そして、EPELリポジトリから提供されるnagiosパッケージを使用します。
‘nagios’という名前のすべての利用可能なパッケージを確認します。
dnf search nagios次に、’nagios’パッケージの詳細を確認します。
dnf info nagios以下のようにnagiosパッケージの詳細が表示されます。

- Nagios Core 4.4.5をインストールおよび設定
以下のdnfコマンドを使用して’nagios’をインストールします。
sudo dnf install nagiosインストールが完了したら、’/etc/nagios’ディレクトリに移動し、設定ファイル’nagios.cfg’を編集します。
cd /etc/nagios/
vim nagios.cfg以下の行のコメントを解除します。
cfg_dir=/etc/nagios/servers保存して閉じます。
次に、すべてのホストモニター設定を保存するための新しいディレクトリを作成します。
mkdir -p /etc/nagios/servers次に、連絡先設定ファイル’objects/contacts.cfg’を編集します。
vim objects/contacts.cfgメールアドレスを自分のものに変更します。
email [email protected]保存して閉じます。
これでNagiosサーバーの設定が完了しました。
- Nagios認証の設定
認証のために、NagiosはApache2ウェブサーバーによって提供される基本的なhttpd認証を使用しています。
以下のhtpasswdコマンドを使用して、ユーザー’nagiosadmin’のための新しいApache基本認証を作成します。
htpasswd /etc/nagios/passwd nagiosadmin強力なパスワードを入力して繰り返し、Nagiosサーバーの基本認証が作成されました。
次に、’/var/www/html’ディレクトリに移動し、index.htmlファイルを作成します。
cd /var/www/html
echo "This is index.html for Apache" > index.html
次に、httpdサービスを開始し、システム起動時に追加します。
systemctl enable --now httpd
systemctl status httpdこれでNagiosサーバーのための新しいユーザー’nagiosadmin’が作成されました。

- ファイアウォールの設定
新しいサービスhttpとhttpsをfirewalldサービスリストに追加します。
firewall-cmd --add-service=http --permanent
firewall-cmd --add-service=https --permanentfirewalldを再読み込みします。
firewall-cmd --reloadこれでhttpとhttpsサービスがfirewalldに追加されました。その結果、Nagiosサーバーはウェブブラウザからアクセス可能になります。

ステップ3 - NRPEプラグインとNagiosプラグインをインストール
NRPE(Nagios Remote Plugin Executor)は、リモートシステムがリモート監視システムで’Nagiosプラグイン’スクリプトを実行できるようにするNagiosエージェントです。
以下のコマンドを使用してNagiosプラグインとNRPEプラグインをインストールします。
sudo dnf install nagios-plugins nrpe nagios-plugins-nrpeすべてのインストールが完了したら、sshサービス、ディスクスペース、ユーザーログインなど、基本的なサーバー監視のためのいくつかのNagiosプラグインをインストールします。
すべての利用可能なNagiosプラグインを取得するには、以下のコマンドを実行します。
dnf search nagios-plugins以下のbashループコマンドを使用してNagiosプラグインをインストールできます。
for i in users uptime ssh ping procs load http swap disk; do dnf install nagios-plugins-$i -y; doneすべてのインストールが完了したら、’/etc/nagios’ディレクトリに移動し、設定ファイル’objects/commands.cfg’を編集します。
cd /etc/nagios/
vim objects/commands.cfg以下の設定を行の最後に貼り付けます。
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}保存して閉じます。
Nagiosサービスを開始し、システム起動時に追加します。
systemctl enable --now nagiosその後、Nagiosサービスの状態を確認します。
systemctl status nagiosNagiosサービスが稼働していることが確認できます。

ウェブブラウザを開き、以下のNagiosサーバーのURLを入力します。
ユーザー’nagiosadmin’とパスワードでログインします。

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

これで、CentOS 8システムにNagiosサーバー4.4.5をインストールしました。
ステップ4 - Nagiosサーバーに監視するホストを追加
このステップでは、CentOS 8システムをNagiosサーバーに追加します。IPアドレス’10.5.5.21’のCentOS 8サーバー’client01’をNagiosサーバーに追加します。
Nagiosサーバーにホストを追加するには、NRPEとNagiosプラグインをサーバーにインストールする必要があります。
‘client01’システムで、以下のコマンドを使用してNRPEサーバーをインストールします。
sudo dnf install nrpeその後、以下のbashループコマンドを使用していくつかのNagiosプラグインをインストールします。
for i in users uptime ssh ping procs load http swap disk; do dnf install nagios-plugins-$i -y; doneすべてのインストールが完了したら、’/etc/nagios’ディレクトリに移動し、nrpe設定ファイル’nrpe.conf’を編集します。
cd /etc/nagios/
vim nrpe.conf‘server_address’行のコメントを解除し、’client01’のIPアドレス’10.5.5.21’に変更します。
server_address = 10.5.5.71‘allowed_hosts’行にNagiosサーバーのIPアドレス’10.5.5.20’を追加します。
allowed_hosts=127.0.0.1,::1,10.5.5.70以下のように基本的な監視のためのいくつかのNagiosコマンドを定義します。
command[check_root]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /
command[check_ping]=/usr/lib64/nagios/plugins/check_ping -H 10.5.5.71 -w 100.0,20% -c 500.0,60% -p 5
command[check_ssh]=/usr/lib64/nagios/plugins/check_ssh -4 10.5.5.71
command[check_http]=/usr/lib64/nagios/plugins/check_http -I 10.5.5.71保存して閉じます。
NRPEサービスを開始し、システム起動時に追加します。
systemctl enable --now nrpe
NRPEサービスの状態を確認します。
systemctl status nrpeNRPEサービスが稼働していることが確認できます。

次に、nrpeポートをfirewalldに追加し、firewalld設定を再読み込みします。
firewall-cmd --add-port=5666/tcp --permanent
firewall-cmd --reloadこれでホストモニター’client01’のNRPE設定が完了しました。

Nagiosサーバーターミナルに戻り、nagios nrpeコマンドを使用して’client01’ホストを確認します。
/usr/lib64/nagios/plugins/check_nrpe -H 10.5.5.21
/usr/lib64/nagios/plugins/check_nrpe -H 10.5.5.21 -c check_pingこれにより、’client01’ホストのNRPEバージョンが表示され、’client01’へのpingコマンドが成功しました。

ステップ5 - ホストモニターの設定を追加
Nagiosサーバーに戻り、’/etc/nagios/server’ディレクトリに移動して、新しい設定’client01.cfg’を作成します。
cd /etc/nagios/servers/
vim client01.cfg以下の設定を貼り付けます。
define host {
use linux-server
host_name client01
alias CentOS 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 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サービスを再起動します。
sudo systemctl restart nagiosこれで’client01’ホストの設定がNagiosサーバーに追加されました。

ステップ6 - テスト
ウェブブラウザを開き、Nagiosダッシュボードにログインします。
‘ホスト’メニューをクリックすると、ホストリストに’client01’が表示されます。

ホスト名’client01’をクリックすると、’client01’サーバーのサービス監視に関する詳細が表示されます。

これで、CentOS 8システムにNagios 4.4.5をインストールし、監視するホスト’client01’をNagiosサーバーに追加しました。
参考
新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。