LoginSignup
1
1

More than 5 years have passed since last update.

Check! Serf ~ クラスタへの参加

Last updated at Posted at 2014-12-25

こんばんは、cloudpack@dz_ こと大平かづみ です。

Prologue - はじめに

前回に引き続き、Serf のドキュメントを読み進めますよ!

Serf: クラスタへの参加

Join a Cluster を読みます。

In the previous page, we started our first agent. While it showed how easy it is to run Serf, it wasn't very exciting since we simply made a cluster of one member. In this page, we'll create a real cluster with multiple members.

"前ページでは、最初のエージェントを起動しました。Serfを実行することがどんだに簡単かお見せできたと思いますが、1クラスタに1メンバーというシンプルなものなので、非常に興奮するというほどではありませんね。このページでは、複数メンバーを持つリアルなクラスタを作りましょう。"

When starting a Serf agent, it begins without knowledge of any other node, and is an isolated cluster of one. To learn about other cluster members, the agent must join an existing cluster. To join an existing cluster, Serf only needs to know about a single existing member. After it joins, the agent will gossip with this member and quickly discover the other members in the cluster.

"1つのSerfエージェントを起動するとき、他のノードに関する情報は持ち合わせておらず、一人きりの孤立したクラスタです。クラスタの他のメンバーについて把握するためには、エージェントは存在するクラスタに 参加 しないとなりません。既存のクラスタに参加するには、Serfはただ、1人の存在するメンバーのことを知ればよいのです。参加した後は、エージェントはこのメンバーとgossipで通信を始め、クラスタのほかのメンバーがすぐに気づきます。"

複数エージェントの起動

Starting the Agents
To simulate a more realistic cluster, we are using a two node cluster in Vagrant. The Vagrantfile can be found in the demo section of the repo [here][repo has vagrantfile].

より本物に近いクラスタをシミュレートするには、2つのノードクラスタを Vagrant を使って作ります。Vagrantfile は[このリポジトリ][repo has vagranfile]のデモのセクションをご参照ください。

We start the first agent on our first node and also specify a node name. The node name must be unique and is how a machine is uniquely identified. By default it is the hostname of the machine, but we'll manually override it. We are also providing a bind address. This is the address that Serf listens on, and it must be accessible by all other nodes in the cluster.

"私たちは最初のノードの最初のエージェントを起動し、ノード名を指定しましょう。ノード名はユニークでなければならず、これがマシンが一意で識別できる所以です。デフォルトでは、マシンのホストネームが割り当てられますが、手動で上書きできます。また、バインドするアドレスも与えることができます。これはSerfがListenするアドレスであり、クラスタのすべてのほかのノードからアクセスできる必要があります。"

$ serf agent -node=agent-one -bind=172.20.20.10
...

Then, in another terminal, start the second agent on the new node. This time, we set the bind address to match the IP of the second node as specified in the Vagrantfile. In production, you will generally want to provide a bind address or interface as well.

"それから、別のターミナルで、新しいノード上で2番目のエージェントを起動します。このとき、バインドアドレスを、Vagrantfileの中で指定している、2番目のノードのIPと合うものを設定します。本番環境では、同様に、一般的にバインドアドレスやインターフェースを与えたいだろう(?)。"

$ serf agent -node=agent-two -bind=172.20.20.11
...

At this point, you have two Serf agents running. The two Serf agents still don't know anything about each other, and are each part of their own clusters (of one member). You can verify this by running serf members against each agent and noting that only one member is a part of each.

"この段階では、2つのSerfエージェントが稼働している状態です。この2つのSerfエージェントはまだ互いのことを何も知らず、それぞれのクラスタ(メンバーは1人)に属している状態です。それぞれのエージェントに対して serf membars を実行することで、あなたはこれを確かめることができます。それぞれが1人のメンバーであることも確認できます。"

クラスタへの参加

Now, let's tell the first agent to join the second agent by running the following command in a new terminal:

"それでは、新しいターミナルから下記のコマンドを実行することによって、最初のエージェントに2番目のエージェントのクラスタに参加を通知してみましょう"

$ serf join 172.20.20.11
Successfully joined cluster by contacting 1 nodes.

You should see some log output in each of the agent logs. If you read carefully, you'll see that they received join information. If you run serf members against each agent, you'll see that both agents now know about each other:

"それぞれのエージェントのログで、あなたはログ出力を見ることができるでしょう。注意深く読んでみると、それらが参加の情報を受信したのだとわかるでしょう。あなたはそれぞれのエージェントに対して serf members を実行すると、今や互いのことを知っていることがわかるでしょう:"

$ serf members
agent-one     172.20.20.10:7946    alive
agent-two     172.20.20.11:7946    alive

Note: To join a cluster, a Serf agent needs to only learn about one existing member. After joining the cluster, the agents gossip with each other to propagate full membership information.

"クラスタに参加するには、Serfエージェントはただひとりのメンバーを知ってさえいればよいのです。クラスタへ参加した後は、メンバーシップの完全な情報を広めるために、エージェントは互いにgossipで通信をします。"

In addition to using serf join you can use the -join flag on serf agent to join a cluster as part of starting up the agent.

"serf join を使う他に、serf agent-join フラグをつけることで、エージェントの起動段階の一部としてクラスタへの参加を行うことができます。"

クラスタから離脱する

To leave the cluster, you can either gracefully quit an agent (using Ctrl-C) or force kill one of the agents. Gracefully leaving allows the node to transition into the left state, otherwise other nodes will detect it as having failed. The difference is covered in more detail [here][https://serfdom.io/intro/getting-started/agent.html#toc_3 "Run the Agent - Serf by HashiCorp"].

"クラスタから離脱するには、正常にエージェントを終了する
(Ctrl-C を用いて) か、エージェントのひとつを強制的に終了してください。正常な離脱は、そのノードを 離脱した 状態に遷移させます。もう一方では、他のノードは 障害が発生した と検知するでしょう。この違いについては、こちら を参照してください。"

Epilogue - おわりに

実は、この訳をしながら、 Amazon EC2 で実践しようとしたんですが…
Amazon EC2 上では Vagrant が動かないことを知りました…orz
理屈は周りに教えてもらって理解できました。
無理矢理 VirtualBox 載せようかと思いましたが、もう少し読み進めて、外部のインスタンスと通信できるようにして実験しようかと考えています。

初心者ではやはり行き詰まるところが出てきましたが、ゆっくりしっかり解決していきます。


Qiita での Serf 関連記事はこちらです。

Serf まとめ、Amazon Lambda について、こちらで記事書いているのでもしご興味あればどうぞ!

1
1
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
1