mirror of https://github.com/status-im/consul.git
25 lines
7.3 KiB
HTML
25 lines
7.3 KiB
HTML
<!DOCTYPE html> <html lang=en> <head> <meta charset=utf-8> <meta name=viewport content="width=device-width, initial-scale=1.0"> <meta name=description content=""> <meta name=author content=""> <title>Join a Cluster - Serf</title> <link href="/stylesheets/bootstrap.min-82fe1490.css" media=screen rel=stylesheet /><link href="/stylesheets/main-e5014f86.css" media=screen rel=stylesheet /> <!--[if lt IE 9]><script src="/javascripts/html5shiv-310dd184.js"></script> <script src="/javascripts/respond.min-88c91176.js"></script><![endif]--> <script>
|
|
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
|
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
|
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
|
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
|
|
|
ga('create', 'UA-45101516-1', 'serfdom.io');
|
|
ga('send', 'pageview');
|
|
|
|
</script> </head> <body class="page-Join a Cluster"> <div id=header> <div class=container> <a class="navbar-brand logo" href="/"> <span></span> </a> <a class="navbar-brand text rls-l" href="/">SERF</a> <ul class="buttons nav navbar-nav navbar-right rls-sb"> <li class=first><a href="/downloads.html">Download</a></li> <li><a href="https://github.com/hashicorp/serf">Github</a></li> </ul> <ul class="main-links nav navbar-nav navbar-right rls-sb"> <li><a href="/intro/index.html">Intro</a></li> <li><a href="/docs/index.html">Docs</a></li> <li><a href="/community.html">Community</a></li> </ul> </div> </div> <div class=container> <div class=col-md-4> <div class="docs-sidebar hidden-print affix-top" role=complementary> <ul class="nav docs-sidenav"> <li> <a href="/intro/index.html">What is Serf?</a> </li> <li> <a href="/intro/use-cases.html">Use Cases</a> </li> <li> <a href="/intro/vs-other-sw.html">Serf vs. Other Software</a> <ul class=nav> <li> <a href="/intro/vs-zookeeper.html">ZooKeeper, doozerd, etcd</a> </li> <li> <a href="/intro/vs-chef-puppet.html">Chef, Puppet, etc.</a> </li> <li> <a href="/intro/vs-fabric.html">Fabric</a> </li> <li> <a href="/intro/vs-custom.html">Custom Solutions</a> </li> </ul> </li> <li class=active> <a href="/intro/getting-started/install.html">Getting Started</a> <ul class=nav> <li> <a href="/intro/getting-started/install.html">Install Serf</a> </li> <li> <a href="/intro/getting-started/agent.html">Run the Agent</a> </li> <li class=active> <a href="/intro/getting-started/join.html">Join a Cluster</a> </li> <li> <a href="/intro/getting-started/event-handlers.html">Event Handlers</a> </li> <li> <a href="/intro/getting-started/user-events.html">Custom User Events</a> </li> <li> <a href="/intro/getting-started/next-steps.html">Next Steps</a> </li> </ul> </li> </ul> </div> </div> <div class=col-md-8 role=main> <div class=bs-docs-section> <h1 id=toc_0>Join a Cluster</h1> <p>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.</p> <p>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 <em>join</em> an existing cluster. To join an existing cluster, Serf only needs to know about a <em>single</em> existing member. After it joins, the agent will gossip with this member and quickly discover the other members in the cluster.</p> <h2 id=toc_1>Starting the Agents</h2> <p>First, let's start two agents. Serf agents must all listen on a unique IP and port pair, so we must bind each agent to a different ports.</p> <p>The first agent we'll start will listen on <code>127.0.0.1:7946</code>. We also will 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 since we'll be running multiple agents on a single machine, we'll manually override it.</p> <pre><code>$ serf agent -node=agent-one -bind=127.0.0.1:7946
|
|
...
|
|
</code></pre> <p>Then, in another terminal, start a second agent. We'll bind this agent to <code>127.0.0.1:7947</code>. In addition to overriding the node name, we're also going to override the RPC address. The RPC address is the address that Serf binds to for RPC operations. The other <code>serf</code> commands communicate with a running Serf agent over RPC. We left the first agent with the default RPC address so lets select another for this agent.</p> <pre><code>$ serf agent -node=agent-two -bind=127.0.0.1:7947 -rpc-addr=127.0.0.1:7374
|
|
...
|
|
</code></pre> <p>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 <code>serf members</code> against each agent and noting that only one member is a part of each.</p> <h2 id=toc_2>Joining a Cluster</h2> <p>Now, let's tell the first agent to join the second agent by running the following command in a new terminal:</p> <pre><code>$ serf join 127.0.0.1:7947
|
|
Successfully joined cluster by contacting 1 nodes.
|
|
</code></pre> <p>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 <code>serf members</code> against each agent, you'll see that both agents now know about each other:</p> <pre><code>$ serf members
|
|
agent-one 127.0.0.1:7946 alive
|
|
agent-two 127.0.0.1:7947 alive
|
|
|
|
$ serf members -rpc-addr=127.0.0.1:7374
|
|
agent-two 127.0.0.1:7947 alive
|
|
agent-one 127.0.0.1:4946 alive
|
|
</code></pre> <div class="alert alert-block alert-info"> <p><strong>Remember:</strong> To join a cluster, a Serf agent needs to only learn about <em>one existing member</em>. After joining the cluster, the agents gossip with each other to propagate full membership information. </p> </div> <p>In addition to using <code>serf join</code> you can use the <code>-join</code> flag on <code>serf agent</code> to join a cluster as part of starting up the agent.</p> <h2 id=toc_3>Leaving a Cluster</h2> <p>To leave the cluster, you can either gracefully quit an agent (using <code>Ctrl-C</code>) or force kill one of the agents. Gracefully leaving allows the node to transition into the <em>left</em> state, otherwise other nodes will detect it as having <em>failed</em>. The difference is covered in more detail <a href="/intro/getting-started/agent.html#toc_3">here</a>.</p> </div> </div> </div> <div id=footer> <div class=container> <div class=footer-links> <ul class="main-links nav navbar-nav rls-sb"> <li><a href="/intro/index.html">Intro</a></li> <li class=active><a href="/docs/index.html">Docs</a></li> <li><a href="/community.html">Community</a></li> </ul> <ul class="buttons nav navbar-nav rls-sb"> <li class=first><a href="/downloads.html">Download</a></li> <li><a href="https://github.com/hashicorp/serf">Github</a></li> </ul> </div> <div class=footer-logo> <span></span> </div> <div class="footer-hashi os"> <span>© 2013. A <a href="//www.hashicorp.com">HashiCorp</a> Project.</span> <a href="//www.hashicorp.com"><img src="/images/hashi-logo-s-3644fe63.png"></a> </div> </div> </div> <script src="javascripts/lib/d3.v3.min.js"></script> <script src="javascripts/app/deploy/site.js"></script> <script>
|
|
Serf.initialize();
|
|
</script> </body> </html> |