zookeeperStarted.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <meta content="Apache Forrest" name="Generator">
  6. <meta name="Forrest-version" content="0.8">
  7. <meta name="Forrest-skin-name" content="pelt">
  8. <title></title>
  9. <link type="text/css" href="skin/basic.css" rel="stylesheet">
  10. <link media="screen" type="text/css" href="skin/screen.css" rel="stylesheet">
  11. <link media="print" type="text/css" href="skin/print.css" rel="stylesheet">
  12. <link type="text/css" href="skin/profile.css" rel="stylesheet">
  13. <script src="skin/getBlank.js" language="javascript" type="text/javascript"></script><script src="skin/getMenu.js" language="javascript" type="text/javascript"></script><script src="skin/fontsize.js" language="javascript" type="text/javascript"></script>
  14. <link rel="shortcut icon" href="images/favicon.ico">
  15. </head>
  16. <body onload="init()">
  17. <script type="text/javascript">ndeSetTextSize();</script>
  18. <div id="top">
  19. <!--+
  20. |breadtrail
  21. +-->
  22. <div class="breadtrail">
  23. <a href="http://www.apache.org/">Apache</a> &gt; <a href="http://hadoop.apache.org/">Hadoop</a> &gt; <a href="http://hadoop.apache.org/zookeeper/">ZooKeeper</a><script src="skin/breadcrumbs.js" language="JavaScript" type="text/javascript"></script>
  24. </div>
  25. <!--+
  26. |header
  27. +-->
  28. <div class="header">
  29. <!--+
  30. |start group logo
  31. +-->
  32. <div class="grouplogo">
  33. <a href="http://hadoop.apache.org/"><img class="logoImage" alt="Hadoop" src="images/hadoop-logo.jpg" title="Apache Hadoop"></a>
  34. </div>
  35. <!--+
  36. |end group logo
  37. +-->
  38. <!--+
  39. |start Project Logo
  40. +-->
  41. <div class="projectlogo">
  42. <a href="http://hadoop.apache.org/zookeeper/"><img class="logoImage" alt="ZooKeeper" src="images/zookeeper_small.gif" title="The Hadoop database"></a>
  43. </div>
  44. <!--+
  45. |end Project Logo
  46. +-->
  47. <!--+
  48. |start Search
  49. +-->
  50. <div class="searchbox">
  51. <form action="http://www.google.com/search" method="get" class="roundtopsmall">
  52. <input value="hadoop.apache.org" name="sitesearch" type="hidden"><input onFocus="getBlank (this, 'Search the site with google');" size="25" name="q" id="query" type="text" value="Search the site with google">&nbsp;
  53. <input name="Search" value="Search" type="submit">
  54. </form>
  55. </div>
  56. <!--+
  57. |end search
  58. +-->
  59. <!--+
  60. |start Tabs
  61. +-->
  62. <ul id="tabs">
  63. <li>
  64. <a class="unselected" href="http://hadoop.apache.org/zookeeper/">Project</a>
  65. </li>
  66. <li>
  67. <a class="unselected" href="http://wiki.apache.org/hadoop/ZooKeeper">Wiki</a>
  68. </li>
  69. <li class="current">
  70. <a class="selected" href="index.html">ZooKeeper Documentation</a>
  71. </li>
  72. </ul>
  73. <!--+
  74. |end Tabs
  75. +-->
  76. </div>
  77. </div>
  78. <div id="main">
  79. <div id="publishedStrip">
  80. <!--+
  81. |start Subtabs
  82. +-->
  83. <div id="level2tabs"></div>
  84. <!--+
  85. |end Endtabs
  86. +-->
  87. <script type="text/javascript"><!--
  88. document.write("Last Published: " + document.lastModified);
  89. // --></script>
  90. </div>
  91. <!--+
  92. |breadtrail
  93. +-->
  94. <div class="breadtrail">
  95. &nbsp;
  96. </div>
  97. <!--+
  98. |start Menu, mainarea
  99. +-->
  100. <!--+
  101. |start Menu
  102. +-->
  103. <div id="menu">
  104. <div onclick="SwitchMenu('menu_selected_1.1', 'skin/')" id="menu_selected_1.1Title" class="menutitle" style="background-image: url('skin/images/chapter_open.gif');">Documentation</div>
  105. <div id="menu_selected_1.1" class="selectedmenuitemgroup" style="display: block;">
  106. <div class="menuitem">
  107. <a href="index.html">Welcome</a>
  108. </div>
  109. <div class="menuitem">
  110. <a href="zookeeperOver.html">Zookeeper Overview</a>
  111. </div>
  112. <div class="menupage">
  113. <div class="menupagetitle">Getting Started</div>
  114. </div>
  115. <div class="menuitem">
  116. <a href="zookeeperProgrammers.html">Programmer's Guide</a>
  117. </div>
  118. <div class="menuitem">
  119. <a href="recipes.html">Recipes</a>
  120. </div>
  121. <div class="menuitem">
  122. <a href="zookeeperAdmin.html">Administrator's Guide</a>
  123. </div>
  124. <div class="menuitem">
  125. <a href="api/index.html">API Docs</a>
  126. </div>
  127. <div class="menuitem">
  128. <a href="http://wiki.apache.org/hadoop/ZooKeeper">Wiki</a>
  129. </div>
  130. <div class="menuitem">
  131. <a href="http://wiki.apache.org/hadoop/ZooKeeper/FAQ">FAQ</a>
  132. </div>
  133. <div class="menuitem">
  134. <a href="http://hadoop.apache.org/zookeeper/mailing_lists.html">Mailing Lists</a>
  135. </div>
  136. <div class="menuitem">
  137. <a href="zookeeperOtherInfo.html">Other Info</a>
  138. </div>
  139. </div>
  140. <div id="credit"></div>
  141. <div id="roundbottom">
  142. <img style="display: none" class="corner" height="15" width="15" alt="" src="skin/images/rc-b-l-15-1body-2menu-3menu.png"></div>
  143. <!--+
  144. |alternative credits
  145. +-->
  146. <div id="credit2"></div>
  147. </div>
  148. <!--+
  149. |end Menu
  150. +-->
  151. <!--+
  152. |start content
  153. +-->
  154. <div id="content">
  155. <div title="Portable Document Format" class="pdflink">
  156. <a class="dida" href="zookeeperStarted.pdf"><img alt="PDF -icon" src="skin/images/pdfdoc.gif" class="skin"><br>
  157. PDF</a>
  158. </div>
  159. <div id="minitoc-area">
  160. <ul class="minitoc">
  161. <li>
  162. <a href="#Getting+Started%3A+Coordinating+Distributed+Applications+with%0A++++++ZooKeeper">Getting Started: Coordinating Distributed Applications with
  163. ZooKeeper</a>
  164. <ul class="minitoc">
  165. <li>
  166. <a href="#sc_InstallingSingleMode">Installing and Running ZooKeeper in Single Server Mode</a>
  167. </li>
  168. <li>
  169. <a href="#sc_ConnectingToZooKeeper">Connecting to ZooKeeper</a>
  170. </li>
  171. <li>
  172. <a href="#sc_ProgrammingToZooKeeper">Programming to ZooKeeper</a>
  173. </li>
  174. <li>
  175. <a href="#sc_RunningReplicatedZooKeeper">Running Replicated ZooKeeper</a>
  176. </li>
  177. <li>
  178. <a href="#Other+Optimizations">Other Optimizations</a>
  179. </li>
  180. </ul>
  181. </li>
  182. </ul>
  183. </div>
  184. <title>ZooKeeper Getting Started Guide</title>
  185. <a name="N1000A"></a><a name="Getting+Started%3A+Coordinating+Distributed+Applications+with%0A++++++ZooKeeper"></a>
  186. <h2 class="h3">Getting Started: Coordinating Distributed Applications with
  187. ZooKeeper</h2>
  188. <div class="section">
  189. <p>This document contains information to get you started quickly with
  190. Zookeeper. It is aimed primarily at developers hoping to try it out, and
  191. contains simple installation instructions for a single ZooKeeper server, a
  192. few commands to verify that it is running, and a simple programming
  193. example. Finally, as a convenience, there are a few sections regarding
  194. more complicated installations, for example running replicated
  195. deployments, and optimizing the transaction log. However for the complete
  196. instructions for commercial deployments, please refer to the <a href="zookeeperAdmin.html">Zookeeper
  197. Administrator's Guide</a>.</p>
  198. <a name="N10017"></a><a name="sc_InstallingSingleMode"></a>
  199. <h3 class="h4">Installing and Running ZooKeeper in Single Server Mode</h3>
  200. <p>Setting up a ZooKeeper server in standalone mode is
  201. straightforward. The server is contained in a single JAR file, so
  202. installation consists of copying a JAR file and creating a
  203. configuration.</p>
  204. <div class="note">
  205. <div class="label">Note</div>
  206. <div class="content">
  207. <p>Zookeeper requires Java 1.5 or more recent.</p>
  208. </div>
  209. </div>
  210. <p>[tbd: should we start w/ a word here about were to get the source,
  211. exactly what to download, how to unpack it, and where to put it? Also,
  212. does the user need to be in sudo, or can they be under their regular
  213. login?]</p>
  214. <p>Once you have downloaded the ZooKeeper source, cd to the root of
  215. your ZooKeeper source, and run "ant jar". For example:<pre class="code">$ cd ~/dev/zookeeper
  216. $ ~/dev/zookeeper/: ant jar</pre>
  217. </p>
  218. <p>This should generate a JAR file called zookeeper.jar. To start
  219. Zookeeper, compile and run zookeeper.jar. <em>[tbd, some more
  220. instruction here. Perhaps a command line? Are these two steps or
  221. one?]</em>
  222. </p>
  223. <p>To start ZooKeeper you need a configuration file. Here is a sample
  224. file:</p>
  225. <p>
  226. <pre class="code">tickTime=2000
  227. dataDir=/var/zookeeper/
  228. clientPort=2181
  229. </pre>
  230. </p>
  231. <p>This file can be called anything, but for the sake of this
  232. discussion, call it <strong>zoo.cfg</strong>. Here are
  233. the meanings for each of the fields:</p>
  234. <dl>
  235. <dt>
  236. <term>
  237. <strong>tickTime</strong>
  238. </term>
  239. </dt>
  240. <dd>
  241. <p>the basic time unit in milliseconds used by ZooKeeper. It is
  242. used to do heartbeats and the minimum session timeout will be
  243. twice the tickTime.</p>
  244. </dd>
  245. </dl>
  246. <dl>
  247. <dt>
  248. <term>
  249. <strong>dataDir</strong>
  250. </term>
  251. </dt>
  252. <dd>
  253. <p>the location to store the in-memory database snapshots and,
  254. unless specified otherwise, the transaction log of updates to the
  255. database.</p>
  256. </dd>
  257. <dt>
  258. <term>
  259. <strong>clientPort</strong>
  260. </term>
  261. </dt>
  262. <dd>
  263. <p>the port to listen for client connections</p>
  264. </dd>
  265. </dl>
  266. <p>Now that you created the configuration file, you can start
  267. ZooKeeper:</p>
  268. <p>
  269. <pre class="code">java -cp zookeeper-dev.jar:java/lib/log4j-1.2.15.jar:conf org.apache.zookeeper.server.quorum.QuorumPeerMain zoo.cfg</pre>
  270. </p>
  271. <p>ZooKeeper logs messages using log4j -- more detail available in
  272. the <a href="zookeeperProgrammers.html#Logging">Logging</a>
  273. section of the Programmer's Guide.<remark revision="include_tbd">[tbd:
  274. real reference needed]</remark> You will see log messages coming to the
  275. console and/or a log file depending on the log4j configuration.</p>
  276. <p>The steps outlined here run ZooKeeper in standalone mode. There is
  277. no replication, so if Zookeeper process fails, the service will go down.
  278. This is fine for most development situations, but to run Zookeeper in
  279. replicated mode, please see <a href="#sc_RunningReplicatedZooKeeper">Running Replicated
  280. Zookeeper</a>.</p>
  281. <p></p>
  282. <a name="N1007A"></a><a name="sc_ConnectingToZooKeeper"></a>
  283. <h3 class="h4">Connecting to ZooKeeper</h3>
  284. <p>Once ZooKeeper is running, you have several option for connection
  285. to it:</p>
  286. <ul>
  287. <li>
  288. <p>
  289. <strong>Java</strong>: Use java -cp
  290. zookeeper.jar:java/lib/log4j-1.2.15.jar:conf
  291. org.apache.zookeeper.ZooKeeperMain 127.0.0.1:2181</p>
  292. <p>This lets you perform simple, file-like operations.</p>
  293. </li>
  294. <li>
  295. <p>
  296. <strong>C</strong>: compile cli_mt
  297. (multi-threaded) or cli_st (single-threaded) by running
  298. <span class="codefrag command">_make cli_mt_</span> or <span class="codefrag command">_make cli_st_</span>
  299. in the c subdirectory in the ZooKeeper sources.</p>
  300. <p>You can run the program using <em>LD_LIBRARY_PATH=.
  301. cli_mt 127.0.0.1:2181</em> or <em>LD_LIBRARY_PATH=.
  302. cli_st 127.0.0.1:2181</em>. This will give you a simple shell
  303. to execute file system like operations on ZooKeeper.</p>
  304. </li>
  305. </ul>
  306. <a name="N100AB"></a><a name="sc_ProgrammingToZooKeeper"></a>
  307. <h3 class="h4">Programming to ZooKeeper</h3>
  308. <p>ZooKeeper has a Java bindings and C bindings. They are
  309. functionally equivalent. The C bindings exist in two variants: single
  310. threaded and multi-threaded. These differ only in how the messaging loop
  311. is done. <remark>[tbd: what is the messaging loop? Do we talk about it
  312. anywyhere? is this too much info for a getting started guide?]</remark>
  313. For more information, see the <a href="zookeeperProgrammers.html#ch_programStructureWithExample.html">Programming
  314. Examples in the Zookeeper Programmer's Guide</a> for
  315. sample code using of the different APIs.</p>
  316. <a name="N100BC"></a><a name="sc_RunningReplicatedZooKeeper"></a>
  317. <h3 class="h4">Running Replicated ZooKeeper</h3>
  318. <p>Running ZooKeeper in standalone mode is convenient for evaluation,
  319. some development, and testing. But in production, you should run
  320. ZooKeeper in replicated mode. A replicated group of servers in the same
  321. application is called a <em>quorum</em>, and in replicated
  322. mode, all servers in the quorum have copies of the same configuration
  323. file. The file is similar to the one used in standalone mode, but with a
  324. few differences. Here is an example:</p>
  325. <p>
  326. <pre class="code">tickTime=2000
  327. dataDir=/var/zookeeper/
  328. clientPort=2181
  329. initLimit=5
  330. syncLimit=2
  331. server.1=zoo1:2888 server.2=zoo2:2888
  332. server.3=zoo3:2888 </pre>
  333. </p>
  334. <p>The new entry, <strong>initLimit</strong> is
  335. timeouts ZooKeeper uses to limit the length of time the Zookeeper
  336. servers in quorum have to connect to a leader. The entry <strong>syncLimit</strong> limits how far out of date a server can
  337. be from a leader. [TBD: someone please verify that the previous is
  338. true.]</p>
  339. <p>With both of these timeouts, you specify the unit of time using
  340. <strong>tickTime</strong>. In this example, the timeout
  341. for initLimit is 5 ticks at 2000 milleseconds a tick, or 10
  342. seconds.</p>
  343. <p>The entries of the form <em>server.X</em> list the
  344. servers that make up the ZooKeeper service. When the server starts up,
  345. it knows which server it is by looking for the file *myid* in the data
  346. directory. That file has the contains the server number, in
  347. ASCII.</p>
  348. <p>Finally, note the "2888" port numbers after each server name.
  349. These are the "electionPort" numbers of the servers (as opposed to
  350. clientPorts), that is ports for <remark>[tbd: feedback need: what are
  351. these ports, exactly?]</remark>.</p>
  352. <div class="note">
  353. <div class="label">Note</div>
  354. <div class="content">
  355. <p>If you want to test multiple servers on a single machine, define
  356. the electionPort for each server in that server's config file, using
  357. the line <span class="codefrag command">electionPort=xxxx</span> as means of avoiding
  358. clashes.</p>
  359. </div>
  360. </div>
  361. <a name="N100F2"></a><a name="Other+Optimizations"></a>
  362. <h3 class="h4">Other Optimizations</h3>
  363. <p>There are a couple of other configuration parameters that can
  364. greatly increase performance:</p>
  365. <ul>
  366. <li>
  367. <p>To get low latencies on updates it is important to have a
  368. dedicated transaction log directory. By default transaction logs are
  369. put in the same directory as the data snapshots and *myid* file. The
  370. dataLogDir parameters indicates a different directory to use for the
  371. transaction logs.</p>
  372. </li>
  373. <li>
  374. <p>
  375. <remark>[tbd: feedback need: what is the other config param?
  376. (I believe two are mentioned above.)]</remark>
  377. </p>
  378. </li>
  379. </ul>
  380. </div>
  381. <p align="right">
  382. <font size="-2"></font>
  383. </p>
  384. </div>
  385. <!--+
  386. |end content
  387. +-->
  388. <div class="clearboth">&nbsp;</div>
  389. </div>
  390. <div id="footer">
  391. <!--+
  392. |start bottomstrip
  393. +-->
  394. <div class="lastmodified">
  395. <script type="text/javascript"><!--
  396. document.write("Last Published: " + document.lastModified);
  397. // --></script>
  398. </div>
  399. <div class="copyright">
  400. Copyright &copy;
  401. 2008 <a href="http://www.apache.org/licenses/">The Apache Software Foundation.</a>
  402. </div>
  403. <!--+
  404. |end bottomstrip
  405. +-->
  406. </div>
  407. </body>
  408. </html>