コンピュータシステムおよびネットワークの統合監視アプリケーションであるNagiosをVPSのCentOS7にインストールした際の備忘録です。
◆バージョン
最新版のNagios Coreは、バージョン 4.4.6(2020.4.28リリース)
プラグインパッケージのバージョン 2.3.3
◆システム要件
Webサーバ(推奨はApahe)が構築済み
CGIの稼働およびGDライブラリ
# yum install httpd php php-cli gd gd-devel openssl-devel
追加されていない場合は、これらのパッケージが必要なのでインストールします。
◆インストール
# yum install nagios nagios-plugins-all
読み込んだプラグイン:langpacks, versionlock
依存性の解決をしています
~ 中略 ~
依存性を解決しました
======================================================================================================================
Package アーキテクチャー バージョン リポジトリー 容量
======================================================================================================================
インストール中:
nagios x86_64 4.4.6-4.el7 epel 1.8 M
nagios-plugins-all x86_64 2.3.3-2.el7 epel 21 k
依存性関連でのインストールをします:
~ 中略 ~
トランザクションの要約
======================================================================================================================
インストール 2 パッケージ (+49 個の依存関係のパッケージ)
総ダウンロード容量: 3.8 M
インストール容量: 12 M
Is this ok [y/d/N]: y
~ 中略 ~
インストール:
nagios.x86_64 0:4.4.6-4.el7 nagios-plugins-all.x86_64 0:2.3.3-2.el7
依存性関連をインストールしました:
nagios-plugins.x86_64 0:2.3.3-2.el7 nagios-plugins-breeze.x86_64 0:2.3.3-2.el7
nagios-plugins-by_ssh.x86_64 0:2.3.3-2.el7 nagios-plugins-cluster.x86_64 0:2.3.3-2.el7
nagios-plugins-dhcp.x86_64 0:2.3.3-2.el7 nagios-plugins-dig.x86_64 0:2.3.3-2.el7
nagios-plugins-disk.x86_64 0:2.3.3-2.el7 nagios-plugins-disk_smb.x86_64 0:2.3.3-2.el7
nagios-plugins-dns.x86_64 0:2.3.3-2.el7 nagios-plugins-dummy.x86_64 0:2.3.3-2.el7
nagios-plugins-file_age.x86_64 0:2.3.3-2.el7 nagios-plugins-flexlm.x86_64 0:2.3.3-2.el7
nagios-plugins-fping.x86_64 0:2.3.3-2.el7 nagios-plugins-game.x86_64 0:2.3.3-2.el7
nagios-plugins-hpjd.x86_64 0:2.3.3-2.el7 nagios-plugins-http.x86_64 0:2.3.3-2.el7
nagios-plugins-icmp.x86_64 0:2.3.3-2.el7 nagios-plugins-ide_smart.x86_64 0:2.3.3-2.el7
nagios-plugins-ircd.x86_64 0:2.3.3-2.el7 nagios-plugins-ldap.x86_64 0:2.3.3-2.el7
nagios-plugins-load.x86_64 0:2.3.3-2.el7 nagios-plugins-log.x86_64 0:2.3.3-2.el7
nagios-plugins-mailq.x86_64 0:2.3.3-2.el7 nagios-plugins-mrtg.x86_64 0:2.3.3-2.el7
nagios-plugins-mrtgtraf.x86_64 0:2.3.3-2.el7 nagios-plugins-mysql.x86_64 0:2.3.3-2.el7
nagios-plugins-nagios.x86_64 0:2.3.3-2.el7 nagios-plugins-nt.x86_64 0:2.3.3-2.el7
nagios-plugins-ntp.x86_64 0:2.3.3-2.el7 nagios-plugins-ntp-perl.x86_64 0:2.3.3-2.el7
nagios-plugins-nwstat.x86_64 0:2.3.3-2.el7 nagios-plugins-oracle.x86_64 0:2.3.3-2.el7
nagios-plugins-overcr.x86_64 0:2.3.3-2.el7 nagios-plugins-perl.x86_64 0:2.3.3-2.el7
nagios-plugins-pgsql.x86_64 0:2.3.3-2.el7 nagios-plugins-ping.x86_64 0:2.3.3-2.el7
nagios-plugins-procs.x86_64 0:2.3.3-2.el7 nagios-plugins-real.x86_64 0:2.3.3-2.el7
nagios-plugins-rpc.x86_64 0:2.3.3-2.el7 nagios-plugins-sensors.x86_64 0:2.3.3-2.el7
nagios-plugins-smtp.x86_64 0:2.3.3-2.el7 nagios-plugins-snmp.x86_64 0:2.3.3-2.el7
nagios-plugins-ssh.x86_64 0:2.3.3-2.el7 nagios-plugins-swap.x86_64 0:2.3.3-2.el7
nagios-plugins-tcp.x86_64 0:2.3.3-2.el7 nagios-plugins-time.x86_64 0:2.3.3-2.el7
nagios-plugins-ups.x86_64 0:2.3.3-2.el7 nagios-plugins-users.x86_64 0:2.3.3-2.el7
nagios-plugins-wave.x86_64 0:2.3.3-2.el7
完了しました!
1行目:Nagios Core本体とプラグインパッケージをEPELリポジトリからインストール
32行目以降:依存性関連で各プラグインがインストールされる
◆インストールディレクトリ
Nagios Core
/etc/nagios
├── cgi.cfg CGI設定ファイル
├── nagios.cfg Nagios本体の設定ファイル
├── objects
│ ├── commands.cfg 監視サービスコマンド設定ファイル
│ ├── contacts.cfg 通知先設定ファイル
│ ├── localhost.cfg ローカルマシン(Linux)監視設定ファイル
│ ├── printer.cfg ネットワークプリンタ監視設定ファイル
│ ├── switch.cfg ネットワークスイッチ監視設定ファイル
│ ├── templates.cfg オブジェクト定義テンプレートファイル
│ ├── timeperiods.cfg 監視・通知時間設定ファイル
│ └── windows.cfg Windowsサーバ監視設定ファイル
├── passwd Nagiosパスワード設定ファイル
└── private
└── resource.cfg ユーザー情報設定ファイル
Plugins
/usr/lib64/nagios
├── cgi-bin
│ └── *.cgi
└── plugins
└── check_* 各監視サービスプラグイン
Nagios Web Page
/usr/share/nagios Nagiosウェブページファイル
HTTPD
/etc/httpd/conf.d/nagios.conf httpd用Nagios設定ファイル
Log Files
/var/log/nagios
├── archives ログファイルアーカイブ格納ディレクトリ
└── nagios.log ログファイル
◆設定
・nagios.cfg
# vi /etc/nagios/nagios.cfg
# DATE FORMAT OPTION
# This option determines how short dates are displayed. Valid options
# include:
# us (MM-DD-YYYY HH:MM:SS)
# euro (DD-MM-YYYY HH:MM:SS)
# iso8601 (YYYY-MM-DD HH:MM:SS)
# strict-iso8601 (YYYY-MM-DDTHH:MM:SS)
#
date_format=iso8601
1行目:nagios.cfgファイル編集
12行目:日付表示書式を変更(任意)
・contacts.cfg
# vi /etc/nagios/objects/contacts.cfg
define contact {
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
email nagios@localhost ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}
1行目:contacts.cfgファイル編集
8行目:emailを通知先メールアドレスに変更
・localhost.cfg
# vi /etc/nagios/objects/localhost.cfg
define service {
use local-service ; Name of service template to use
host_name localhost
service_description SSH
check_command check_ssh
notifications_enabled 1
}
# Define a service to check HTTP on the local machine.
# Disable notifications for this service by default, as not all users may have HTTP enabled.
define service {
use local-service ; Name of service template to use
host_name localhost
service_description HTTP
check_command check_http
notifications_enabled 1
}
1行目:localhost.cfgファイル編集
9行目:SSH状態監視有効化
23行目:HTTP状態監視有効化
・nagios.conf(httpd)
# vi /etc/httpd/conf.d/nagios.conf
ScriptAlias /nagios/cgi-bin "/usr/lib64/nagios/cgi-bin/"
<Directory "/usr/lib64/nagios/cgi-bin/">
# SSLRequireSSL
Options ExecCGI
AllowOverride None
<IfVersion >= 2.3>
<RequireAll>
<RequireAny>
# Require all granted
# Require host 127.0.0.1
Require host example.jp
</RequireAny>
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /etc/nagios/passwd
Require valid-user
</RequireAll>
</IfVersion>
<IfVersion < 2.3>
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /etc/nagios/passwd
Require valid-user
</IfVersion>
</Directory>
Alias /nagios "/usr/share/nagios/html"
<Directory "/usr/share/nagios/html">
# SSLRequireSSL
Options None
AllowOverride None
<IfVersion >= 2.3>
<RequireAll>
<RequireAny>
# Require all granted
# Require host 127.0.0.1
Require host example.jp
</RequireAny>
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /etc/nagios/passwd
Require valid-user
</RequireAll>
</IfVersion>
<IfVersion < 2.3>
Order allow,deny
Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /etc/nagios/passwd
Require valid-user
</IfVersion>
</Directory>
1行目:httpd設定用nagios.confファイル編集
11,15(45,49)行目:RequireAnyディレクティブの追加
12(46)行目:すべての接続を許可をコメントアウト
14(48)行目:アクセス許可するホスト名(ドメイン名)を指定、IPアドレスで指定する場合は、「Require ip」で指定
◆起動
・httpdリロード
# systemctl reload httpd
・nagiosサービス自動起動設定
# systemctl enable nagios.service
Created symlink from /etc/systemd/system/multi-user.target.wants/nagios.service to /usr/lib/systemd/system/nagios.service.
・nagiosサービス起動
# systemctl start nagios
・確認
サイトにアクセスして確認します。

naigosの監視サイト「domain/nagios/」にアクセスし、ログイン認証画面でユーザー名「nagiosadmin」パスワード(初期)「nagiosadmin」でログインします。

ログイン後、左ツリーから「Services」をクリックすると、サービスの状態監視画面が表示され、「Services」一覧にはデフォルトの監視項目「Current Load(CPU負荷)」、「Current Users(ログインユーザー数)」、「PING(ネットワーク疎通状況)」、「Root Partition(ディスク空き状況)」、「Swap Usage(SWAP空き状況)」、「Total Processes(プロセス数)」および有効化設定した「SSH(SSHサーバー稼動状況)」、「HTTP(Webサーバー稼動状況)」を含め、「Status」がOKとなっているのが確認できます。
◆その他
・パスワード変更
# htpasswd -c /etc/nagios/passwd nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
ユーザパスワードを変更する場合の要領です。
・nagios.cfg設定ファイル確認コマンド
# nagios -v /etc/nagios/nagios.cfg
Nagios Core 4.4.6
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2020-04-28
License: GPL
Website: https://www.nagios.org
Reading configuration data...
Read main config file okay...
Read object config files okay...
Running pre-flight check on configuration data...
Checking objects...
Checked 8 services.
Checked 1 hosts.
Checked 1 host groups.
Checked 0 service groups.
Checked 1 contacts.
Checked 1 contact groups.
Checked 24 commands.
Checked 5 time periods.
Checked 0 host escalations.
Checked 0 service escalations.
Checking for circular paths...
Checked 1 hosts
Checked 0 service dependencies
Checked 0 host dependencies
Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
設定ファイルのチェックをすることで機能状態の確認をすることができます。
初期の設定として監視できる状態になりました。
次回は、監視項目を調整していきたいとおもいます。