1 views
実現させる機能
サーバーに不具合が起きても、気づくまでに時間がかかるのが常です。統合監視システムNagios(ナギオス)は、サーバーに不具合が起きるとメールをくれるので、不具合に気づくまでの時間を短縮できます。今回は、パッケージから簡単インストールで構築してみました。最新版でないのが欠点ですが、初心者向けの構築法ではあります。監視項目を増やすと敷居も高くなりますが・・・。
事前準備
※Webサーバー構築済であること
※リポジトリ導入(EPEL,RPMforge)を参照してEPELリポジトリが導入済であること
Nagios導入手順
統合監視システムNagiosをyumでインストールし、バックアップしたファイルをコピーするという単純な手順です。
[root@ufuso ~]# yum -y install gd-devel ← 描画処理に必要なソフトをインストール インストール: gd-devel.x86_64 0:2.0.35-26.el7 依存性関連をインストールしました: fontconfig-devel.x86_64 0:2.10.95-7.el7 freetype-devel.x86_64 0:2.4.11-9.el7 libX11-devel.x86_64 0:1.6.0-2.1.el7 libXau-devel.x86_64 0:1.0.8-2.1.el7 libXpm-devel.x86_64 0:3.5.10-5.1.el7 libpng-devel.x86_64 2:1.5.13-5.el7 libxcb-devel.x86_64 0:1.9-5.el7 xorg-x11-proto-devel.noarch 0:7.7-8.el7.1 完了しました! [root@ufuso ~]# yum --enablerepo=epel -y install nagios ← EPELからNagiosを インストール インストール: nagios.x86_64 0:3.5.1-1.el7 依存性関連をインストールしました: nagios-common.x86_64 0:3.5.1-1.el7 完了しました! [root@ufuso ~]# yum --enablerepo=epel -y install nagios-plugins-all ← EPELから Nagiosのpluginをインストール インストール: nagios-plugins-all.x86_64 0:2.0.1-1.el7 依存性関連をインストールしました: fping.x86_64 0:3.5-3.el7 lm_sensors.x86_64 0:3.3.4-10.el7 nagios-plugins.x86_64 0:2.0.1-1.el7 nagios-plugins-breeze.x86_64 0:2.0.1-1.el7 nagios-plugins-by_ssh.x86_64 0:2.0.1-1.el7 nagios-plugins-cluster.x86_64 0:2.0.1-1.el7 nagios-plugins-dhcp.x86_64 0:2.0.1-1.el7 nagios-plugins-dig.x86_64 0:2.0.1-1.el7 nagios-plugins-disk.x86_64 0:2.0.1-1.el7 nagios-plugins-disk_smb.x86_64 0:2.0.1-1.el7 nagios-plugins-dns.x86_64 0:2.0.1-1.el7 nagios-plugins-dummy.x86_64 0:2.0.1-1.el7 nagios-plugins-file_age.x86_64 0:2.0.1-1.el7 nagios-plugins-flexlm.x86_64 0:2.0.1-1.el7 nagios-plugins-fping.x86_64 0:2.0.1-1.el7 nagios-plugins-game.x86_64 0:2.0.1-1.el7 nagios-plugins-hpjd.x86_64 0:2.0.1-1.el7 nagios-plugins-http.x86_64 0:2.0.1-1.el7 nagios-plugins-icmp.x86_64 0:2.0.1-1.el7 nagios-plugins-ide_smart.x86_64 0:2.0.1-1.el7 nagios-plugins-ircd.x86_64 0:2.0.1-1.el7 nagios-plugins-ldap.x86_64 0:2.0.1-1.el7 nagios-plugins-load.x86_64 0:2.0.1-1.el7 nagios-plugins-log.x86_64 0:2.0.1-1.el7 nagios-plugins-mailq.x86_64 0:2.0.1-1.el7 nagios-plugins-mrtg.x86_64 0:2.0.1-1.el7 nagios-plugins-mrtgtraf.x86_64 0:2.0.1-1.el7 nagios-plugins-mysql.x86_64 0:2.0.1-1.el7 nagios-plugins-nagios.x86_64 0:2.0.1-1.el7 nagios-plugins-nt.x86_64 0:2.0.1-1.el7 nagios-plugins-ntp.x86_64 0:2.0.1-1.el7 nagios-plugins-ntp-perl.x86_64 0:2.0.1-1.el7 nagios-plugins-nwstat.x86_64 0:2.0.1-1.el7 nagios-plugins-oracle.x86_64 0:2.0.1-1.el7 nagios-plugins-overcr.x86_64 0:2.0.1-1.el7 nagios-plugins-perl.x86_64 0:2.0.1-1.el7 nagios-plugins-pgsql.x86_64 0:2.0.1-1.el7 nagios-plugins-ping.x86_64 0:2.0.1-1.el7 nagios-plugins-procs.x86_64 0:2.0.1-1.el7 nagios-plugins-real.x86_64 0:2.0.1-1.el7 nagios-plugins-rpc.x86_64 0:2.0.1-1.el7 nagios-plugins-sensors.x86_64 0:2.0.1-1.el7 nagios-plugins-smtp.x86_64 0:2.0.1-1.el7 nagios-plugins-snmp.x86_64 0:2.0.1-1.el7 nagios-plugins-ssh.x86_64 0:2.0.1-1.el7 nagios-plugins-swap.x86_64 0:2.0.1-1.el7 nagios-plugins-tcp.x86_64 0:2.0.1-1.el7 nagios-plugins-time.x86_64 0:2.0.1-1.el7 nagios-plugins-ups.x86_64 0:2.0.1-1.el7 nagios-plugins-users.x86_64 0:2.0.1-1.el7 nagios-plugins-wave.x86_64 0:2.0.1-1.el7 net-snmp-utils.x86_64 1:5.7.2-18.el7 postgresql-libs.x86_64 0:9.2.7-1.el7 qstat.x86_64 0:2.11-13.20080912svn311.el7 完了しました! [root@ufuso ~]# vi /etc/nagios/objects/contacts.cfg ← contacts.cfgの設定 ############################################################################### # # CONTACTS # ############################################################################### ############################################################################### # Just one contact defined by default - the Nagios admin (that's you) # This contact definition inherits a lot of default values from the 'generic-contact' # template which is defined elsewhere. 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 ufuso@gmail.com ; ← Nagiosからのメールを受け取るアドレスに変更。「ufuso@gmail.com」は 例示[root@ufuso ~]# vi /etc/nagios/nagios.cfg ← 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 ← 日付表示をusをiso8601に変更 [root@ufuso ~]# htpasswd /etc/nagios/passwd nagiosadmin ← Nagios管理ユーザー (nagiosadmin)のパスワード作成 New password: ← nagiosadminのパスワード作成入力(表示されない) Re-type new password: ← 作成したパスワード再入力(表示されない) Updating password for user nagiosadmin [root@ufuso ~]# systemctl start nagios ← nagios起動 [root@ufuso ~]# chkconfig nagios on ← 自動起動の設定 |
■起動エラーがでる場合の処理手順
[root@ufuso ~]# /usr/sbin/nagios -v /etc/nagios/nagios.cfg ← エラーの内容を確認 Nagios Core 3.5.1 Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors Copyright (c) 1999-2009 Ethan Galstad Last Modified: 08-30-2013 License: GPL Website: http://www.nagios.org Reading configuration data... Read main config file okay... Processing object config file '/etc/nagios/objects/commands.cfg'... Processing object config file '/etc/nagios/objects/contacts.cfg'... Processing object config file '/etc/nagios/objects/timeperiods.cfg'... Processing object config file '/etc/nagios/objects/templates.cfg'... Processing object config file '/etc/nagios/objects/localhost.cfg'... Error: Unexpected start of object definition in file '/etc/nagios/objects/localhost.cfg' on line 164. Make sure you close preceding objects before starting a new one. ← localhost.cfgの164行目がエラー箇所だとわかる。 Error processing object config files! ***> One or more problems was encountered while processing the config files... Check your configuration file(s) to ensure that they contain valid directives and data defintions. If you are upgrading from a previous version of Nagios, you should be aware that some variables/definitions may have been removed or modified in this version. Make sure to read the HTML documentation regarding the config files, as well as the 'Whats New' section to find out what has changed. |
監視サービスの追加
(1)NTP※NTP導入済の場合のみ
[root@ufuso ~]# vi /etc/nagios/objects/commands.cfg ← commands.cfg編集 以下を最終行へ追加 # 'check_ntp' command definition define command{ command_name check_ntp command_line $USER1$/check_ntp -H $ARG1$ -w $ARG2$ -c $ARG3$ } [root@ufuso ~]# vi /etc/nagios/objects/localhost.cfg ← localhost.cfg編集 以下を最終行へ追加 define service{ use generic-service host_name localhost service_description NTP check_command check_ntp!210.173.160.27!1!2 } ← 外部NTPサーバー(「210.173.160.27」は例示)と時間が1秒ずれていたら 警告、2秒ずれていたら異状とする [root@ufuso ~]# systemctl restart nagios ← Nagios再起動 |
(2)DNS※BIND導入済の場合のみ
[root@ufuso ~]# vi /etc/nagios/objects/commands.cfg ← commands.cfg編集 以下を最終行へ追加 # 'check_dig' command definition define command{ command_name check_dig command_line $USER1$/check_dig -H $HOSTADDRESS$ -l $ARG1$ } [root@ufuso ~]# vi /etc/nagios/objects/localhost.cfg ← localhost.cfg編集 以下を最終行へ追加 define service{ use generic-service host_name localhost service_description DNS check_command check_dig!ufuso.dip.jp ← 名前解決ホスト名に自ドメイン 名を指定 } [root@ufuso ~]# systemctl restart nagios ← Nagios再起動 |
(3)SMTP※メールサーバー導入済の場合のみ
[root@ufuso ~]# vi /etc/nagios/objects/localhost.cfg ← localhost.cfg編集 以下を最終行へ追加 define service{ use generic-service host_name localhost service_description SMTP check_command check_smtp } [root@ufuso ~]# systemctl restart nagios ← Nagios再起動 |
(4)POP※メールサーバー導入済の場合のみ
[root@ufuso ~]# vi /etc/nagios/objects/commands.cfg ← commands.cfg編集 # 'check_pop' command definition define command{ command_name check_pop command_line $USER1$/check_pop -H $HOSTADDRESS$ $ARG1$ -s quit ← 「-s quit」追加 } ※「-s quit」はDovecotがpop3-login:Abortedlogin:rip=::ffff:127.0.0.1,lip=::ffff:127.0.0.1, securedというエラーメッセージをログに出力しないようにする対処 [root@ufuso ~]# vi /etc/nagios/objects/localhost.cfg ← localhost.cfg編集 以下を最終行へ追加 define service{ use generic-service host_name localhost service_description POP check_command check_pop } [root@ufuso ~]# systemctl restart nagios ← Nagios再起動 |
(5)IMAP※メールサーバー導入済の場合のみ
[root@ufuso ~]# vi /etc/nagios/objects/commands.cfg ← commands.cfg編集 # 'check_imap' command definition define command{ command_name check_imap command_line $USER1$/check_imap -H $HOSTADDRESS$ -s "A2 logout" ← 「$ARG1$」を削除して「-s "A2 logout"」追加 } ※「-s "A2 logout"」はDovecotがimap-login: Aborted login: rip=::ffff:127.0.0.1, lip=::ffff:127.0.0.1, securedというエラーメッセージをログに出力しないようにする対処 [root@ufuso ~]# vi /etc/nagios/objects/localhost.cfg ← localhost.cfg編集 以下を最終行へ追加 define service{ use generic-service host_name localhost service_description IMAP check_command check_imap } [root@ufuso ~]# systemctl restart nagios ← Nagios再起動 |
(6)Samba※Samba導入済の場合のみ
[root@ufuso ~]# vi /etc/nagios/objects/commands.cfg ← commands.cfg編集 以下を最終行へ追加 # 'check_disk_smb' command definition define command{ command_name check_disk_smb command_line $USER1$/check_disk_smb -H $ARG1$ -s $ARG2$ -W $ARG3$ -u $ARG4$ -p $ARG5$ } [root@ufuso ~]# vi /etc/nagios/objects/localhost.cfg ← localhost.cfg編集 以下を最終行へ追加 define service{ use generic-service host_name localhost service_description Samba check_command check_disk_smb!ufuso.dip.jp!public!workgroup!user!password } ← 「ufuso.dip.jp」はSambaサーバーホスト名の例示、「public」はSamba 共有名の例示、「workgroup」はSambaワークグループ名の例示、「user」はSambaユーザー 名の例示、「password」はSambaユーザーパスワードの例示。Sambaで設定したとおり入力 のこと。Sambaユーザーを設定してなければ「user!password」部分は「!」のみ [root@ufuso ~]# systemctl restart nagios ← Nagios再起動 |
(7)MariaDB※MariaDB導入済の場合のみ
[root@ufuso ~]# vi /etc/nagios/objects/commands.cfg ← commands.cfg編集 以下を最終行へ追加 # 'check_mysql' command definition define command{ command_name check_mysql command_line $USER1$/check_mysql -H $HOSTADDRESS$ -u $ARG1$ -p $ARG2$ } [root@ufuso ~]# vi /etc/nagios/objects/localhost.cfg ← localhost.cfg編集 以下を最終行へ追加 define service{ use generic-service host_name localhost service_description MySQL check_command check_mysql!root!password } ← 「password」はMySQLのrootユーザーパスワードの例示 [root@ufuso ~]# systemctl restart nagios ← Nagios再起動 |
(8)メモリ空き状況監視を追加する
[root@ufuso ~]# wget http://www.nagios-plugins.org/download/nagios-plugins-1.4.16.tar.gz ← Nagios-Pluginsのダウンロード `nagios-plugins-1.4.16.tar.gz' に保存中 100%[======================================>] 2,087,089 301K/s 時間 8.2s 2013-12-15 17:36:37 (247 KB/s) - `nagios-plugins-1.4.16.tar.gz' へ保存完了 [2087089/2087089] [root@ufuso ~]# tar zxvf nagios-plugins-1.4.16.tar.gz ← Nagios-Pluginsの展開 [root@ufuso ~]# cp nagios-plugins-1.4.16/contrib/check_mem.pl /usr/lib64/nagios/plugins/ ← check_mem.plをpluginsフォルダにコピー [root@ufuso ~]# vi /usr/lib64/nagios/plugins/check_mem.pl ← check_mem.plの編集 # This the unix command string that brings Perl the data #$command_line = `vmstat | tail -1 | awk '{print \$4,\$5}'`; ← 行頭に#を付加 して無効化 $command_line = `free | head -3 | tail -1 | awk '{print \$3,\$4}'`; ← 追記 [root@ufuso ~]# vi /etc/nagios/objects/commands.cfg ← commands.cfg編集 以下を最終行へ追加 # 'check_mem' command definition define command{ command_name check_mem command_line $USER1$/check_mem.pl -f -w $ARG1$ -c $ARG2$ } [root@ufuso ~]# vi /etc/nagios/objects/localhost.cfg ← localhost.cfg編集 以下を最終行へ追加 define service{ use generic-service host_name localhost service_description Memory Free check_command check_mem!20!10 ← 空きメモリ量が20%で 警告、10%で異常とする } [root@ufuso ~]# systemctl restart nagios ← Nagios再起動 [root@ufuso ~]# rm -rf nagios-plugins-1.4.16 ← 展開したフォルダの削除 [root@ufuso ~]# rm -f nagios-plugins-1.4.16.tar.gz ← ダウンロードしたファイル の削除 |
Nagiosの動作確認
1.http://サーバー名/nagios/へアクセスし、赤枠1のユーザー名に「nagiosiadmin」と入力し、設定したパスワードを下段に入力後、赤枠2の「OK」をクリック。
2.赤が障害(Critical)、黄色が警告(Warning)のある項目です。メールで教えてくれます。
3.我が家では16項目を監視しています。赤の障害(Critical)があるので、メールが飛んできました。早速エラーの解消に動きます。
以上です。