| Pgpool-II 4.0.4 文書 | |||
|---|---|---|---|
| 前のページ | 上に戻る | 第 7章設定の例 | 次のページ | 
ここではwatchdogの機能を簡単に試す方法を説明します。 Linux マシン2台にそれぞれ Pgpool-II がインストールされているものとします。 また、いずれかのマシンか第 3 のマシンに、PostgreSQL がインストールされて稼働しているものとします。 バックエンドノードは1台でかまいません。 Pgpool-II がどのモードで稼働していても(レプリケーションモードでもマスタースレーブモードでも)、watchdogを利用することができます。
この例では、「osspc16」をActiveノードとして、「osspc20」をStandbyノードとして使います。 「someserver」は、これらのどちらかということを意味しています。
アクティブとスタンバイの両サーバで以下を設定します。
上流のサーバ(アプリケーションサーバなど)を指定します。 空欄にしておいても構いません。
trusted_servers = ''
                                    # trusted server list which are used
                                    # to confirm network connection
                                    # (hostA,hostB,hostC,...)
          
仮想IPをdelegate_IPに設定します。
delegate_IP = '133.137.177.143'
                                    # delegate IP address
          
注意: 仮想IPに設定されるIPアドレスは空いており他のマシンで使用されていないことを確認してください。
次に、それぞれのPgpool-IIで以下のパラメータを設定します。 other_pgpool_hostname、other_pgpool_port、other_wd_portを他のPgpool-IIの値で設定します。
other_pgpool_hostname0 = 'osspc20'
                                    # Host name or IP address to connect to for other pgpool 0
other_pgpool_port0 = 9999
                                    # Port number for other pgpool 0
other_wd_port0 = 9000
                                    # Port number for other watchdog 0
          
other_pgpool_hostname0 = 'osspc16'
                                    # Host name or IP address to connect to for other pgpool 0
other_pgpool_port0 = 9999
                                    # Port number for other pgpool 0
other_wd_port0 = 9000
                                    # Port number for other watchdog 0
          
両方のサーバでPgpool-IIをrootユーザで、"-n"オプションを付けて起動し、ログメッセージはpgpool.logファイルにリダイレクトします。
最初に、Active サーバでPgpool-IIを起動します。
[user@osspc16]$ su -
[root@osspc16]# {installed_dir}/bin/pgpool -n -f {installed_dir}/etc/pgpool.conf > pgpool.log 2>&1
          ログから、仮想IP アドレスを使用し、またwatchdogプロセス起動したことが確認できます。
LOG:  I am announcing my self as master/coordinator watchdog node
LOG:  I am the cluster leader node
DETAIL:  our declare coordinator message is accepted by all nodes
LOG:  I am the cluster leader node. Starting escalation process
LOG:  escalation process started with PID:59449
LOG:  watchdog process is initialized
LOG:  watchdog: escalation started
LOG:  I am the master watchdog node
DETAIL:  using the local backend node status
          
次に、StandbyサーバでPgpool-IIを起動します。
[user@osspc20]$ su -
[root@osspc20]# {installed_dir}/bin/pgpool -n -f {installed_dir}/etc/pgpool.conf > pgpool.log 2>&1
          ログメッセージからPgpool-IIがwatchdogクラスタにスタンバイとして参加したことがわかります。
LOG:  watchdog cluster configured with 1 remote nodes
LOG:  watchdog remote node:0 on Linux_osspc16_9000:9000
LOG:  interface monitoring is disabled in watchdog
LOG:  IPC socket path: "/tmp/.s.PGPOOLWD_CMD.9000"
LOG:  watchdog node state changed from [DEAD] to [LOADING]
LOG:  new outbound connection to Linux_osspc16_9000:9000
LOG:  watchdog node state changed from [LOADING] to [INITIALIZING]
LOG:  watchdog node state changed from [INITIALIZING] to [STANDBY]
LOG:  successfully joined the watchdog cluster as standby node
DETAIL:  our join coordinator request is accepted by cluster leader node "Linux_osspc16_9000"
LOG:  watchdog process is initialized
          
仮想 IP アドレスに、pingが通ることを確認します。
[user@someserver]$ ping 133.137.177.143
PING 133.137.177.143 (133.137.177.143) 56(84) bytes of data.
64 bytes from 133.137.177.143: icmp_seq=1 ttl=64 time=0.328 ms
64 bytes from 133.137.177.143: icmp_seq=2 ttl=64 time=0.264 ms
64 bytes from 133.137.177.143: icmp_seq=3 ttl=64 time=0.412 ms
      先にPgpool-IIを起動したActiveサーバが、仮想IPアドレスを使っていることを確認します。
[root@osspc16]# ifconfig
eth0      ...
eth0:0    inet addr:133.137.177.143 ...
lo        ...
      後からPgpool-IIを立ち上げたStandbサーバは、仮想IPアドレスを使っていないことを確認します。
[root@osspc20]# ifconfig
eth0      ...
lo        ...
      仮想IPアドレスを使って、PostgreSQL に接続をできることを確認します。
[user@someserver]$ psql -h 133.137.177.143 -p 9999 -l
      
Activeサーバがサービス供給不可な状態になったときに、Standbyがそれを引き継ぐのを確認します。 ActiveサーバのPgpool-IIを停止します。
[root@osspc16]# {installed_dir}/bin/pgpool stop
      するとStandbyサーバで、仮想IPアドレスを使用しはじめたというログメッセージが出力されます。
LOG:  remote node "Linux_osspc16_9000" is shutting down
LOG:  watchdog cluster has lost the coordinator node
LOG:  watchdog node state changed from [STANDBY] to [JOINING]
LOG:  watchdog node state changed from [JOINING] to [INITIALIZING]
LOG:  I am the only alive node in the watchdog cluster
HINT:  skipping stand for coordinator state
LOG:  watchdog node state changed from [INITIALIZING] to [MASTER]
LOG:  I am announcing my self as master/coordinator watchdog node
LOG:  I am the cluster leader node
DETAIL:  our declare coordinator message is accepted by all nodes
LOG:  I am the cluster leader node. Starting escalation process
LOG:  watchdog: escalation started
LOG:  watchdog escalation process with pid: 59551 exit with SUCCESS.
         仮想 IP アドレスに、pingが通ることを確認します。
[user@someserver]$ ping 133.137.177.143
PING 133.137.177.143 (133.137.177.143) 56(84) bytes of data.
64 bytes from 133.137.177.143: icmp_seq=1 ttl=64 time=0.328 ms
64 bytes from 133.137.177.143: icmp_seq=2 ttl=64 time=0.264 ms
64 bytes from 133.137.177.143: icmp_seq=3 ttl=64 time=0.412 ms
      Activeではもう仮想IPアドレスが使われなくなったのを確認します。
[root@osspc16]# ifconfig
eth0      ...
lo        ...
        Standbyで仮想IP アドレスが使われていることを確認します。
[root@osspc20]# ifconfig
eth0      ...
eth0:0    inet addr:133.137.177.143 ...
lo        ...
        仮想IPアドレスを使って、PostgreSQLに接続できることを確認します。
[user@someserver]$ psql -h 133.137.177.143 -p 9999 -l
        
watchdog の監視方法について設定するパラメータがあります。 監視間隔秒を指定するwd_interval、リトライ回数を指定するwd_life_point、 監視に使うクエリを指定するwd_lifecheck_query、死活監視のタイプを指定するwd_lifecheck_methodを記述します。
wd_lifecheck_method = 'query'
                                    # Method of watchdog lifecheck ('heartbeat' or 'query' or 'external')
                                    # (change requires restart)
wd_interval = 10
                                    # lifecheck interval (sec) > 0
wd_life_point = 3
                                    # lifecheck retry times
wd_lifecheck_query = 'SELECT 1'
                                    # lifecheck query to pgpool from watchdog
        
IP アドレスの切り替えコマンドについて設定するパラメータがあります。 仮想 IP を切り替える際に使うコマンドとしてif_up_cmd、if_down_cmd、そのパスを指定するif_cmd_pathを記述します。 また、仮想IP切り替え後のARPリクエスト送信コマンドを指定するarping_cmd、そのパスを指定するarping_pathを記述します。
ifconfig_path = '/sbin'
                                    # ifconfig command path
if_up_cmd = 'ifconfig eth0:0 inet $_IP_$ netmask 255.255.255.0'
                                    # startup delegate IP command
if_down_cmd = 'ifconfig eth0:0 down'
                                    # shutdown delegate IP command
arping_path = '/usr/sbin'           # arping command path
arping_cmd = 'arping -U $_IP_$ -w 1'
        wd_escalation_commandおよびwd_de_escalation_commandの設定を用いて仮想IPの起動・停止を行う同時にスクリプトを使うこともできます。