LoginSignup
1
3

More than 5 years have passed since last update.

Linux-HA環境でフェイルオーバ発生時、Zabbix Serverに通知してみる

Last updated at Posted at 2018-02-21

はじめに

Pacemaker+Corosyncを利用したLinux-HA環境でフェイルオーバが発生した場合、zabbix_senderを利用したリソースエージェントを実装し、Zabbixサーバに通知してみました。

前提条件

この投稿では、前回「シングル構成のRADIUSサーバを、HA環境に移行した時のメモ」の環境を使って実装しました。
またクラスタ各ノードにはZabbixエージェントを導入し、監視環境が整っていることとします。

Zabbixサーバ側準備

テンプレート作成

メニューから[設定]>[テンプレート]>[テンプレートの作成]をクリック。
Template Linux HAという名前のテンプレートを新規作成
zabbix_001.png

アイテム作成

Template Linux HAテンプレートにアイテムTakeoverを作成
zabbix_002.png

項目
名前 Takeover
タイプ Zabbixトラッパー
キー takeover
データ型 文字列
アプリケーション 任意のアプリケーション
今回はAlertを新しく作成

トリガー作成

Template Linux HAテンプレートにトリガー作成
zabbix_003.png

項目
名前 Resource takeover occurred on {HOST.NAME}
条件式 {Template Linux HA:takeover.str(example)}=0 and {Template Linux HA:takeover.nodata(30)}=0
障害イベントを継続して生成 On
深刻度 メール発報する深刻度を選択

テンプレートのリンク

Zabbixサーバに登録されているクラスタ構成のホストに対し、作成したテンプレートをリンク
zabbix_004.png

クラスタ側設定

zabbix_senderインストール

zabbix_senderはエージェントに同梱されていない為、別途インストール

(nfs01, nfs02)$ sudo yum -y install zabbix-sender --enablerepo=zabbix

リソースエージェント作成

全ノードの/usr/lib/ocf/resource.d/heartbeat/内に、RAZabbixSenderを新規作成
※今回作成したRAをGitHubに置いています。

RAに実行権限付与

(nfs01, nfs02)$ sudo chmod +x /usr/lib/ocf/resource.d/heartbeat/ZabbixSender

RA用例の確認

$ sudo pcs resource describe ZabbixSender
Assumed agent name 'ocf:heartbeat:ZabbixSender' (deduced from 'ZabbixSender')
ocf:heartbeat:ZabbixSender - Notifies zabbix server by sender in the event of
                             resource takeover

This is a resource agent for zabbix sender. It sends email to zabbix server whenever
a takeover occurs.

Resource options:
  confpath: Path of zabbix agent configuration file. (default:
            /etc/zabbix/zabbix_agentd.conf)
  server: IP address or Hostname of zabbix server.
  port: Port number of zabbix server. (default: 10051)
  host: Destination host name registered on zabbix server.
  item (required): Item key of destination host on zabbix server.

Default operations:
  start: interval=0s timeout=10
  stop: interval=0s timeout=10
  monitor: interval=10 timeout=10

クラスタにリソース追加

CIBエクスポート

(nfs01)$ sudo pcs cluster cib ~/output.cib

リソースzabbix-senderを追加

(nfs01) $ sudo pcs -f ~/output.cib resource create zabbix-sender ocf:heartbeat:ZabbixSender \
                     confpath=/etc/zabbix/zabbix_agentd.conf item=takeover \
                     op start   timeout=60s on-fail=restart \
                     op stop    timeout=60s on-fail=block \
                     op monitor interval=20s timeout=60s on-fail=restart

既リソースグループにzabbix-senderを追加

(nfs01)$ sudo pcs -f ~/output.cib resource group add group-nfs zabbix-sender

CIBインポート

(nfs01)$ sudo pcs cluster cib-push ~/output.cib
(nfs01)$ sudo pcs status
Cluster name: nfs-cluster
Stack: corosync
Current DC: nfs02 (version 1.1.16-12.el7_4.7-94ff4df) - partition with quorum
Last updated: Wed Feb 21 16:10:57 2018
Last change: Wed Feb 21 14:08:42 2018 by root via cibadmin on nfs01

3 nodes configured
10 resources configured

Online: [ nfs01 nfs02 ]

Full list of resources:

 Master/Slave Set: ms-drbd [drbd]
     Masters: [ nfs01 ]
     Slaves: [ nfs02 ]
 Resource Group: group-nfs
     fs (ocf::heartbeat:Filesystem):    Started nfs01
     virtual_ip (ocf::heartbeat:IPaddr2):       Started nfs01
     route-change-1     (ocf::heartbeat:route-change):  Started nfs01
     route-change-2     (ocf::heartbeat:route-change):  Started nfs01
     nfsserver  (ocf::heartbeat:nfsserver):     Started nfs01
     exportfs   (ocf::heartbeat:exportfs):      Started nfs01
     zabbix-sender      (ocf::heartbeat:ZabbixSender):  Started nfs01

Daemon Status:
  corosync: active/enabled
  pacemaker: active/enabled
  pcsd: active/disabled

通知内容

以上の設定により、フェイルオーバー時(&初回のリソース登録時)次のようなメールが通知される。

  • 件名: Resource takeover occurred on <ホスト名>
  • 本文:
    • リソースを引き継いだノード(≒リソースが開始されたノード)
      • 最新値: Takeover in progress at <発生日付&時刻> on <ホスト名>
    • リソースで障害が発生したノード(≒リソースが停止したノード)
      • 最新値: Migrating resource away at <発生日付&時刻> from <ホスト名>

Tips

Zabbixエージェントレスのノードから通知

今回作成したRAZabbixSenderは、エージェントレスのノードからも通知することができる。
その場合はリソース登録時、次のようにZabbixサーバの情報をパラメータで指定する必要がある。

(nfs01) $ sudo pcs -f ~/output.cib resource create zabbix-sender ocf:heartbeat:ZabbixSender \
                     server=<ZabbixサーバIP or ホスト名> port=<Zabbixサーバ待受ポート> \
              host=<Zabbixサーバに登録済のホスト名> item=takeover \
                     op start   timeout=60s on-fail=restart \
                     op stop    timeout=60s on-fail=block \
                     op monitor interval=20s timeout=60s on-fail=restart
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3