title: ZooKeeper Multi-Server Setup by Example
body: <p>From the <a href="https://zookeeper.apache.org/doc/r3.3.2/zookeeperAdmin.html#sc_zkMulitServerSetup" rel="nofollow">ZooKeeper multi-server config docs</a> they show the following configs that can be placed inside of <code>zoo.cfg</code> (ZK's config file) on each server:</p>
  
  <pre><code>tickTime=2000
  dataDir=/var/zookeeper/
  clientPort=2181
  initLimit=5
  syncLimit=2
  server.1=zoo1:2888:3888
  server.2=zoo2:2888:3888
  server.3=zoo3:2888:3888
  </code></pre>
  
  <p>Furthermore, they state that you need a <code>myid</code> file on each ZK node whose content matches one of the <code>server.id</code> values above. So for example, in a 3-node "ensemble" (ZK cluster), the first node's <code>myid</code> file would simply contain the value <code>1</code>. The second node's <code>myid</code> file would contain <code>2</code>, and so forth.</p>
  
  <p>I have a few practical questions about what this looks like in the real world:</p>
  
  <p><strong>1. Can <code>localhost</code> be used?</strong> If <code>zoo.cfg</code> has to be repeated on each node in the ensemble, is it OK to define the current server as <code>localhost</code>? For example, in a 3-node ensemble, would it be OK for Server #2's <code>zoo.cfg</code> to look like:</p>
  
  <pre><code>tickTime=2000
  dataDir=/var/zookeeper/
  clientPort=2181
  initLimit=5
  syncLimit=2
  server.1=zoo1:2888:3888
  server.2=localhost:2888:3888    # Afterall, we're on server #2!
  server.3=zoo3:2888:3888
  </code></pre>
  
  <p>Or is this not advised/not possible?</p>
  
  <p><strong>2. Do they server ids have to be numerical?</strong> For instance, could I have a 5-node ensemble where each server's <code>zoo.cfg</code> looks like:</p>
  
  <pre><code>tickTime=2000
  dataDir=/var/zookeeper/
  clientPort=2181
  initLimit=5
  syncLimit=2
  server.red=zoo1:2888:3888
  server.green=zoo2:2888:3888
  server.blue=zoo3:2888:3888
  server.orange=zoo1:2888:3888
  server.purple=zoo2:2888:3888
  </code></pre>
  
  <p>And, say, Server 1's <code>myid</code> would contain the value <code>red</code> inside of it (etc.)?</p>