スクリプトを使用してPacemakerクラスタを監視する方法は?

スクリプトを使用してPacemakerクラスタを監視する方法は?

.NET Frameworkを使用して2ノードクラスタ(両方のノードがRHEL 7)を作成しましたpacemaker。カスタムアプリケーションを実行するために使用されます。次のリソースを作成してクラスタに割り当てました。

  1. アプリケーションデータ用の共有ストレージ
  2. 仮想IP

それは非常にうまく動作します。

今リクエストがあります。現在のフェイルオーバーは、サーバー全体に問題がある場合にのみ発生します。 Pacemakerはアクティブノードで実行されているアプリケーションの状態を認識せず、これを完全に無視します。アプリケーションに対してヘルスチェックを実行し、アプリケーションの状態に応じてtrue / false値を返すシェルスクリプトがあります。
誰もがこのシェルスクリプトを使用してクラスタのアクティブノード上のアプリケーションの状態を定期的に確認し、スクリプトがエラー値を返す場合にフェールオーバーを開始するようにペースメーカーを設定する方法を提案できますか?

http://127.0.0.1/samplepage.html私はWebサーバークラスタで人々がサンプルHTMLページを生成し、これをフェイスメーカーのリソースとして使用して、アクティブノード上のApache Webサーバーの状態を確認するいくつかの例を見ました。

シェルスクリプトを使用して同様の結果を得る方法を案内してください。

修正する:

私の設定は次のとおりです。

[root@node1 ~]# pcs status
Cluster name: webspheremq
Stack: corosync
Current DC: node1 (version 1.1.15-11.el7-e174ec8) - partition with quorum
Last updated: Wed Jun 14 20:38:48 2017          Last change: Tue Jun 13 20:04:58 2017 by root via crm_attribute on svdg-stg29

2 nodes and 3 resources configured: 2 resources DISABLED and 0 BLOCKED from being started due to failures

Online: [ node1 node2 ]

Full list of resources:

 Resource Group: websphere
     websphere_fs       (ocf::heartbeat:Filesystem):    Started node1
     websphere_vip      (ocf::heartbeat:IPaddr2):       Started node1
     FailOverScript     (ocf::heartbeat:Dummy): Started node1


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

アプリケーションを起動および停止するための2つのシェルスクリプトがあります。フェールオーバー中は、stop.shリソースが移動するノードとstart.shクラスタがフェールオーバーするノードで実行する必要があります。

いくつかの実験を行った結果、人々はこの要件を達成するために仮想リソースを使用していることを発見しました(障害対策中にスクリプトを実行)。

これまで私がしたことは次のとおりです。

FailOverScript次のように、アプリケーションの起動/停止スクリプトをテストするためのダミーリソース()を作成しました。

[root@node1 tmp]# pcs status resources
 Resource Group: websphere
     websphere_fs       (ocf::heartbeat:Filesystem):    Started node1
     websphere_vip      (ocf::heartbeat:IPaddr2):       Started node1
     **FailOverScript     (ocf::heartbeat:Dummy): Started node1**

現時点では、FailOverScriptリソースの開始および停止操作の下にテストスクリプトを含めました。この仮想リソースが起動および停止されると、それぞれスクリプト失敗開始script.shと失敗停止スクリプト.shを実行する必要があります。

[root@node1 heartbeat]# pwd
/usr/lib/ocf/resource.d/heartbeat
[root@node1  heartbeat]#
[root@node1  heartbeat]# grep -A5 "start()" FailOverScript
FailOverScript_start() {
    FailOverScript_monitor
    /usr/local/bin/failoverstartscript.sh
    if [ $? =  $OCF_SUCCESS ]; then
        return $OCF_SUCCESS
    fi
[root@node1  heartbeat]#
[root@node1  heartbeat]#
[root@node1  heartbeat]# grep -A5 "stop()" FailOverScript
FailOverScript_stop() {
    FailOverScript_monitor
    /usr/local/bin/failoverstopscript.sh
    if [ $? =  $OCF_SUCCESS ]; then
        rm ${OCF_RESKEY_state}
    fi

ただし、その仮想リソースを起動/停止した場合(手動フェールオーバーを介して)、スクリプトは実行されません。いろいろな方法を試してみましたが、まだ原因がわかりません。フェイルオーバー中にスクリプトが自動的に実行されない理由を見つけるのに役立ちます。

ベストアンサー1

anything任意のスクリプトを実行するために仮想RAを変更する代わりに、リソースエージェントの使用を検討することができます。

# pcs resource describe ocf:heartbeat:anything
ocf:heartbeat:anything - Manages an arbitrary service

This is a generic OCF RA to manage almost anything.

Resource options:
  binfile (required): The full name of the binary to be executed.
                      This is expected to keep running with the
                      same pid and not just do something and
                      exit.
  cmdline_options: Command line options to pass to the binary
  workdir: The path from where the binfile will be executed.
  pidfile: File to read/write the PID from/to.
  logfile: File to write STDOUT to
  errlogfile: File to write STDERR to
  user: User to run the command as
  monitor_hook: Command to run in monitor operation
  stop_timeout: In the stop operation: Seconds to wait for kill
                -TERM to succeed before sending kill -SIGKILL.
                Defaults to 2/3 of the stop operation timeout.

anythingパラメータとしてエージェントにスクリプトを割り当てることができ、実行中のpid(エージェントがデフォルトで実行するアクション)をbinfile=確認する以外にカスタムアプリケーションを監視する方法がある場合は、パラメータでそれを定義できます。anythingmonitor_hook

おすすめ記事