今回は『OSS編~オーケストレーションツール Serf 01 インストール編~』と題して、オーケストレーションのSerfのインストールから基本操作までを試してみたいと思います。
Serfとは
Vagrantで有名な HashiCorp社 がGo言語で開発しているサービスディスカバリーやオーケストレーションのための分散型ツールです。
以下の3つの特徴があります。
・クラスタリング
Serfではクラスターを形成してメンバーのリストを持ち、参加・離脱等が発生した際にイベントとして伝播をしてスクリプトの実行が出来ます。
イベントとの伝播にはGossipプロトコルを利用しています。
・障害検知とリカバリ
Serfは自動的に失敗したノードを検出して、残りのメンバーリストに対して伝播します。
リカバリでは定期的に失敗したノードに再接続して回復しようとします。
・カスタムイベントの伝播
クラスターに対してカスタムイベントとクエリーを伝播する事が出来ます。
これにより任意の処理をユーザーが実行出来ます。
※ 公式サイト
今回は GitHub にのっているQuick Startを試してみたいと思います。
Serfの実行
1.Serfのインストール
Serfは該当のプラットフォームのバイナリファイルをダウンロードして設置するだけで利用できます。
1$ wget https://dl.bintray.com/mitchellh/serf/0.6.4_linux_amd64.zip2$ unzip 0.6.4_linux_amd64.zip3$ sudo mv serf /usr/local/bin/実際にコマンドで確認してみます。
$ serf version
Serf v0.6.4
Agent Protocol: 4 (Understands back to: 2)
2.Serfの起動
次のコマンドでSerfを起動してみます。
1$ serf agent -node=foo -bind=127.0.0.1:5000 -rpc-addr=127.0.0.1:73732==> Starting Serf agent...3==> Starting Serf agent RPC...4==> Serf agent running!5 Node name: 'foo'6 Bind addr: '127.0.0.1:5000'7 RPC addr: '127.0.0.1:7373'8 Encrypted: false9 Snapshot: false10 Profile: lan1112==> Log data will now stream in as it occurs:1314 2015/03/05 18:34:14 [INFO] agent: Serf agent starting15 2015/03/05 18:34:14 [INFO] serf: EventMemberJoin: foo 127.0.0.116 2015/03/05 18:34:15 [INFO] agent: Received event: member-join続いて別のターミナルを立ち上げて2つ目のエージェントを立ち上げます。
※一台で行っている為、ポートを変える事で対応しています。
1$ serf agent -node=bar -bind=127.0.0.1:5001 -rpc-addr=127.0.0.1:73742==> Starting Serf agent...3==> Starting Serf agent RPC...4==> Serf agent running!5 Node name: 'bar'6 Bind addr: '127.0.0.1:5001'7 RPC addr: '127.0.0.1:7374'8 Encrypted: false9 Snapshot: false10 Profile: lan1112==> Log data will now stream in as it occurs:1314 2015/03/05 18:35:42 [INFO] agent: Serf agent starting15 2015/03/05 18:35:42 [INFO] serf: EventMemberJoin: bar 127.0.0.116 2015/03/05 18:35:43 [INFO] agent: Received event: member-join3.クラスターへの参加
それでは三個目のターミナルを立ち上げて1つ目のエージェントを2つ目のクラスターに参加させます。
1$ serf join 127.0.0.1:50012Successfully joined cluster by contacting 1 nodes.ストリームされているログでも確認出来ます。
12015/03/05 18:39:43 [INFO] agent.ipc: Accepted client: 127.0.0.1:486612 2015/03/05 18:39:43 [INFO] agent: joining: [127.0.0.1:5001] replay: false3 2015/03/05 18:39:43 [INFO] serf: EventMemberJoin: bar 127.0.0.14 2015/03/05 18:39:43 [INFO] agent: joined: 1 nodes5 2015/03/05 18:39:44 [INFO] agent: Received event: member-joinメンバーコマンドでリストを確認してみます。
1$ serf members2foo 127.0.0.1:5000 alive3bar 127.0.0.1:5001 aliveクラスタリングされているのが分かります。
起動しているエージェントを止めて確認してみます。
1$ serf members2bar 127.0.0.1:5001 left3foo 127.0.0.1:5000 aliveいかがでしたでしょうか?
次回もお楽しみに!!!