[Linux]
Nagios
管理コンソールを見てみる
前回までで、とりあえず死活監視っぽい画面がでてきたぞ
- Host
- Service
リモートサーバーを監視するためには?
このFreeStyleWikiではNagiosをサーバ内に同居させているので、リモートからの監視用途はない。しかし、リモートからの監視を行いたい場合はNRPE(Nagios Remote Plugin Executor)をインストールする必要がある。
メール通知
以下を参考に
# vim /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 [email protected] ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** + email [email protected] ; とりあえずこれに送れるように }
さて、これを動かすにはコマンドでメールを送れる必要がある。Debian勉強会関連でわたしも送ったことがあるので、ここは手順を復習しておこう。
- メールを送るコマンド
環境が整えば、以下のコマンドが動くはず
# echo "本文" | mail -s "タイトル" -r [email protected] [email protected]
Postfixの設定
2段階認証も含めたGmail+Postfixの設定は以下がくわしい
// postfixを入れる # yum install postfix cyrus-sasl-plain // 以下の設定をまるまる追記 # vim /etc/postfix/main.cf + relayhost = smtp.gmail.com:587 + + # SASL Authentication + smtp_sasl_auth_enable = yes + smtp_sasl_password_maps = hash:/etc/postfix/gmail_passwd + smtp_sasl_security_options = noanonymous + smtp_sasl_mechanism_filter = plain + + # TLS Settings + smtp_use_tls = yes + smtp_tls_security_level = encrypt + tls_random_source = dev:/dev/urandom
アプリ パスワードはhttps://security.google.com/settings/security/apppasswordsの「端末を選択」で「その他(名前を入力)でPostfixなどと入力して取得する。
2段階認証をする場合はこれが必要になる(→上のリンクからpostfix用のパスワードを作る)。そうでない場合は自分のGoogleアカウントのパスワードを入れる。
- /etc/postfix/gmail_passwd にファイルを作成
smtp.gmail.com:587 アカウント@gmail.com:パスワード
- あとは以下のようにコマンドを実行
# postmap /etc/postfix/gmail_passwd # rm -f /etc/postfix/gmail_passwd # systemctl start postfix # systemctl status postfix ● postfix.service - Postfix Mail Transport Agent Loaded: loaded (/usr/lib/systemd/system/postfix.service; disabled; vendor preset: disabled) Active: active (running) since 日 2016-08-21 09:06:23 EDT; 4s ago Process: 15038 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS) Process: 15035 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS) Process: 15027 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS) Main PID: 15109 (master) CGroup: /system.slice/postfix.service ├─15109 /usr/libexec/postfix/master -w ├─15110 pickup -l -t unix -u └─15111 qmgr -l -t unix -u 8月 21 09:06:23 freestylewiki systemd[1]: Starting Postfix Mail Transport Agent... 8月 21 09:06:23 freestylewiki sendmail[15030]: alias database /etc/aliases rebuilt by root 8月 21 09:06:23 freestylewiki aliasesdb[15027]: /etc/aliases: 76 aliases, longest 10 bytes, 771 bytes total 8月 21 09:06:23 freestylewiki postfix/postfix-script[15107]: starting the Postfix mail system 8月 21 09:06:23 freestylewiki postfix/master[15109]: daemon started -- version 2.10.1, configuration /etc/postfix 8月 21 09:06:23 freestylewiki systemd[1]: Started Postfix Mail Transport Agent.
- 他のメールシステムが入っている場合はpostfixに変更しておく
# alternatives --config mta 3 プログラムがあり 'mta' を提供します。 選択 コマンド ----------------------------------------------- *+ 1 /usr/sbin/sendmail.sendmail 2 /usr/sbin/sendmail.ssmtp 3 /usr/sbin/sendmail.postfix
- cyrus-sasl-plain を入れてないと、メール送信失敗するから注意
Aug 21 09:18:35 freestylewiki postfix/smtp[15325]: warning: SASL authentication failure: No worthy mechs found Aug 21 09:18:35 freestylewiki postfix/smtp[15325]: 497E71009A6: SASL authentication failed; cannot authenticate to server smtp.gmail.com[74.125.21.109]: no mechanism available Aug 21 09:18:35 freestylewiki postfix/smtp[15325]: warning: SASL authentication failure: No worthy mechs found Aug 21 09:18:35 freestylewiki postfix/smtp[15325]: 497E71009A6: SASL authentication failed; cannot authenticate to server smtp.gmail.com[74.125.21.108]: no mechanism available Aug 21 09:18:35 freestylewiki postfix/smtp[15325]: warning: SASL authentication failure: No worthy mechs found Aug 21 09:18:35 freestylewiki postfix/smtp[15325]: 497E71009A6: to=<[email protected]>, relay=smtp.gmail.com[2607:f8b0:4002:c06::6d]:587, delay=0.42, delays=0.07/0.01/0.34/0, dsn=4.7.0, status=deferred (SASL authentication failed; cannot authenticate to server smtp.gmail.com[2607:f8b0:4002:c06::6d]: no mechanism available)
メール通知のテスト
- 画面の右側に Send custom service notification というのがあるので押す
- 適当にCommentを設定して、Commitすると、あなたのGmailあてにアラートが届くはず
nagios_host.png
nagios_service.png
service_to_test_notification.png