Ubuntu14.04にNagiosをインストールする手順
Ubuntu14.04にNagiosをinstallする手順です
以下のサイトを参考にさせて頂きました
手順
1. nagiosのインストール
apt-get install nagios3 nagios-plugins-basic vi /etc/nagios3/nagios.cfg =============================================== 145 check_external_commands=1 # 1に変更 =============================================== /etc/init.d/nagios3 restart
インストールと初期設定が無事完了したら、以下のアドレスからnagiosにアクセスできます
- http://IP/nagios3/
- user名はnagiosadmin
- passwordはinstall時に設定したパスワードです
2. アラートメールの設定
apt-get install postfix sasl2-bin mv -i /etc/postfix/main.cf{,.org} cp -ip /usr/lib/postfix/main.cf /etc/postfix/main.cf vi /etc/postfix/main.cf ======================================================= # 59行目:コメント解除 mail_owner = postfix # 76行目:コメント解除しホスト名指定 myhostname = mail.hogehoge.fugafuga.com # 83行目:コメント解除しドメイン名指定 mydomain = hogehoge.fugafuga.com # 104行目:コメント解除 myorigin = $mydomain # 118行目:コメント解除 inet_interfaces = all # 166行目:コメント解除 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain # 209行目:コメント解除 local_recipient_maps = unix:passwd.byname $alias_maps # 268行目:自ネットワーク追記 mynetworks = 127.0.0.0/8, 192.168.33.11/24 # vagrantで構築した場合 # 388行目:コメント解除 alias_maps = hash:/etc/aliases # 399行目:コメント解除 alias_database = hash:/etc/aliases # 421行目:コメント解除 ( Maildir形式へ移行 ) home_mailbox = Maildir/ # 557行目:コメントにしてその下に追記 #smtpd_banner = $myhostname ESMTP $mail_name (@@DISTRO@@) smtpd_banner = $myhostname ESMTP # 631行目:追記 sendmail_path = /usr/sbin/postfix # 636行目:追記 newaliases_path = /usr/bin/newaliases # 641行目:追記 mailq_path = /usr/bin/mailq # 647行目:追記 setgid_group = postdrop # 651行目:コメント化 #html_directory = # 655行目:コメント化 #manpage_directory = # 660行目:コメント化 #sample_directory = # 664行目:コメント化 #readme_directory = # 最終行へ追記:送受信メールサイズを10Mに制限 message_size_limit = 10485760 # メールボックスサイズを1Gに制限 mailbox_size_limit = 1073741824 # 以下SMTP-Auth用 smtpd_sasl_type = dovecot smtpd_sasl_path = private/auth smtpd_sasl_auth_enable = yes smtpd_sasl_security_options = noanonymous smtpd_sasl_local_domain = $myhostname smtpd_recipient_restrictions = permit_mynetworks,permit_auth_destination,permit_sasl_authenticated,reject ======================================================= newaliases /etc/init.d/postfix restart vi /etc/nagios3/conf.d/contacts_nagios2.cfg ================================================= # 26行目:通知メールを受け取るアドレス email root@localhost # 自分のメールアドレスに変更 ================================================= /etc/init.d/nagios3 restart
これでメールの設定は完了です
3. 閾値の設定
確認のために一時的に閾値を低くしてWarnとCriticalを発生させます
vi /etc/nagios3/conf.d/localhost_nagios2.cfg ======================================================= 18 define service{ 19 use generic-service ; Name of service template to use 20 host_name localhost 21 service_description Disk Space 22 #check_command check_all_disks!20%!10% 23 check_command check_all_disks!99%!10% # 絶対warnになるように設定を変更 24 } 25 26 27 28 # Define a service to check the number of currently logged in 29 # users on the local machine. Warning if > 20 users, critical 30 # if > 50 users. 31 32 define service{ 33 use generic-service ; Name of service template to use 34 host_name localhost 35 service_description Current Users 36 #check_command check_users!20!50 37 check_command check_users!0!1 # 絶対Criticalになるように設定を変更 38 } ======================================================== /etc/init.d/nagios3 restart
閾値を変更すると以下のようにWarnとCriticalのアラート表示に変更することが確認できます
指定したメールアドレスへ以下のようなメールが届きます
4. 監視項目追加
vi /etc/nagios3/commands.cfg ===================================================== # 最終行に追記 define command{ command_name check_ntp_time command_line $USER1$/check_ntp_time -H $ARG1$ -w $ARG2$ -c $ARG3$ } ===================================================== vi /etc/nagios3/conf.d/localhost_nagios2.cfg ===================================================== # 最終行に追記 ( NTPサーバーとの時間が1秒差で Warning, 2秒差で Critical ) define service{ use generic-service host_name localhost service_description NTP_TIME check_command check_ntp_time!ntp1.jst.mfeed.ad.jp!1!2 } ======================================================= /etc/init.d/nagios3 restart
5. 監視対象ホスト追加(masterから)
root@dlp:~# vi /etc/nagios3/conf.d/node01.cfg ============================================================= # 新規作成 define host{ use generic-host host_name node01 alias node01 address 10.0.0.51 } define service{ use generic-service host_name node01 service_description PING check_command check_ping!100.0,20%!500.0,60% } ============================================================= /etc/init.d/nagios3 restart
以下のようにnode01のping情報が追加されます
6. 監視対象サーバの追加
より詳しい情報を監視したい時は、監視対象サーバにクライアントをインストールして情報を送ります
監視対象サーバにて
apt-get install nagios-nrpe-server vi /etc/nagios/nrpe.cfg =========================================================== # 81行目:接続を許可するIPを追記 (マスターサーバーを指定) allowed_hosts=127.0.0.1, 192.168.33.13 # 97行目:コマンドの引数を許可 dont_blame_nrpe=1 =============================================================== /etc/init.d/nagios-nrpe-server restart
- nrpeはnagios-remote-plugin-executeの略
マスター側にて
apt-get install nagios-nrpe-plugin vi /etc/nagios3/conf.d/node01.cfg =========================================== # 新規作成 define host{ use generic-host host_name node01 alias node01 address 10.0.0.51 } define service{ use generic-service host_name node01 service_description PING check_command check_ping!100.0,20%!500.0,60% } # カレントユーザー数 define service{ use generic-service host_name node01 service_description Current Users check_command check_nrpe_1arg!check_users } # カレントロード define service{ use generic-service host_name node01 service_description Current Load check_command check_nrpe_1arg!check_load } =========================================== /etc/init.d/nagios3 restart
- check_nrpe_1argは/etc/nagios-plugins/config/check_nrpe.cfgで設定されています
追加したサーバ(node01)の項目が表示されるようになりました