zookeeperAdmin.html 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056
  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="menuitem">
  113. <a href="zookeeperStarted.html">Getting Started</a>
  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="menupage">
  122. <div class="menupagetitle">Administrator's Guide</div>
  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="zookeeperAdmin.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="#Deployment">Deployment</a>
  163. <ul class="minitoc">
  164. <li>
  165. <a href="#sc_systemReq">System Requirements</a>
  166. </li>
  167. <li>
  168. <a href="#sc_zkMulitServerSetup">Clustered (Multi-Server) Setup</a>
  169. </li>
  170. <li>
  171. <a href="#sc_singleAndDevSetup">Single Server and Developer Setup</a>
  172. </li>
  173. </ul>
  174. </li>
  175. <li>
  176. <a href="#Administration">Administration</a>
  177. <ul class="minitoc">
  178. <li>
  179. <a href="#sc_configuration">Configuration Parameters</a>
  180. <ul class="minitoc">
  181. <li>
  182. <a href="#sc_minimumConfiguration">Minimum Configuration</a>
  183. </li>
  184. <li>
  185. <a href="#sc_advancedConfiguration">Advanced Configuration</a>
  186. </li>
  187. <li>
  188. <a href="#sc_clusterOptions">Cluster Options</a>
  189. </li>
  190. <li>
  191. <a href="#Unsafe+Options">Unsafe Options</a>
  192. </li>
  193. </ul>
  194. </li>
  195. <li>
  196. <a href="#sc_zkCommands">Zookeeper Commands: The Four Letter Words</a>
  197. </li>
  198. <li>
  199. <a href="#sc_monitoring">Monitoring</a>
  200. </li>
  201. <li>
  202. <a href="#sc_dataFileManagement">Data File Management</a>
  203. <ul class="minitoc">
  204. <li>
  205. <a href="#The+Data+Directory">The Data Directory</a>
  206. </li>
  207. <li>
  208. <a href="#The+Log+Directory">The Log Directory</a>
  209. </li>
  210. <li>
  211. <a href="#File+Management">File Management</a>
  212. </li>
  213. </ul>
  214. </li>
  215. <li>
  216. <a href="#sc_commonProblems">Things to Avoid</a>
  217. </li>
  218. <li>
  219. <a href="#sc_bestPractices">Best Practices</a>
  220. </li>
  221. </ul>
  222. </li>
  223. </ul>
  224. </div>
  225. <title>ZooKeeper Administrator's Guide</title>
  226. <subtitle>A Guide to Deployment and Administration</subtitle>
  227. <a name="N1000D"></a><a name="Deployment"></a>
  228. <h2 class="h3">Deployment</h2>
  229. <div class="section">
  230. <p>This chapter contains information about deploying Zookeeper and
  231. covers these topics:</p>
  232. <ul>
  233. <li>
  234. <p>
  235. <a href="#sc_systemReq">System Requirements</a>
  236. </p>
  237. </li>
  238. <li>
  239. <p>
  240. <a href="#sc_zkMulitServerSetup">Clustered (Multi-Server) Setup</a>
  241. </p>
  242. </li>
  243. <li>
  244. <p>
  245. <a href="#sc_singleAndDevSetup">Single Server and Developer Setup</a>
  246. </p>
  247. </li>
  248. </ul>
  249. <p>The first two sections assume you are interested in installing
  250. Zookeeper in a production environment such as a datacenter. The final
  251. section covers situations in which you are setting up Zookeeper on a
  252. limited basis - for evaluation, testing, or development - but not in a
  253. production environment.</p>
  254. <a name="N10034"></a><a name="sc_systemReq"></a>
  255. <h3 class="h4">System Requirements</h3>
  256. <p>Zookeeper runs in Java, release 1.6 or greater, as group of hosts
  257. called a quorum. Three Zookeeper hosts per quorum is the minimum
  258. recommended quorum size. At Yahoo!, Zookeeper is usually deployed on
  259. dedicated RHEL boxes, with dual-core processors, 2GB of RAM, and 80GB
  260. IDE harddrives.</p>
  261. <a name="N1003E"></a><a name="sc_zkMulitServerSetup"></a>
  262. <h3 class="h4">Clustered (Multi-Server) Setup</h3>
  263. <p>For reliable ZooKeeper service, you should deploy ZooKeeper in a
  264. cluster known as a <em>quorum</em>. As long as a majority
  265. of the quorum are up, the service will be available. Because Zookeeper
  266. requires a majority <remark>[tbd: why?]</remark>, it is best to use an
  267. odd number of machines. For example, with four machines ZooKeeper can
  268. only handle the failure of a single machine; if two machines fail, the
  269. remaining two machines do not constitute a majority. However, with five
  270. machines ZooKeeper can handle the failure of two machines. </p>
  271. <p>Here are the steps to setting a server that will be part of a
  272. quorum. These steps should be performed on every host in the
  273. quorum:</p>
  274. <ol>
  275. <li>
  276. <p>Install the Java JDK:</p>
  277. <pre class="code">$yinst -i jdk-1.6.0.00_3 -br test <remark>[y! prop - replace with open equiv]</remark>
  278. </pre>
  279. </li>
  280. <li>
  281. <p>Set the Java heap size. This is very important, to avoid
  282. swapping, which will seriously degrade Zookeeper performance. To
  283. determine the correct value, load tests, make sure you are well
  284. below the usage limit that would cause you to swap. Be conservative
  285. - use a maximum heap size of 3GB for a 4GB machine. <remark>[tbd:
  286. where would they do this? Environment variable,
  287. etc?]</remark>
  288. </p>
  289. </li>
  290. <li>
  291. <p>Install the Zookeeper Server Package:</p>
  292. <pre class="code">$ yinst install -nostart zookeeper_server <remark>[Y! prop - replace with open eq]</remark>
  293. </pre>
  294. </li>
  295. <li>
  296. <p>Create a configuration file. This file can be called anything.
  297. Use the following settings as a starting point:</p>
  298. <pre class="code">
  299. tickTime=2000
  300. dataDir=/var/zookeeper/
  301. clientPort=2181
  302. initLimit=5
  303. syncLimit=2
  304. server.1=zoo1:2888
  305. server.2=zoo2:2888
  306. server.3=zoo3:2888</pre>
  307. <p>You can find the meanings of these and other configuration
  308. settings in the section <a href="#sc_configuration">Configuration Parameters</a>. A word
  309. though about a few here:</p>
  310. <p>Every machine that is part of the ZooKeeper quorum should know
  311. about every other machine in the quorum. You accomplish this with
  312. the series of lines of the form <strong>server.id=host:port</strong>. The integers <strong>host</strong> and <strong>port</strong> are straightforward. You attribute the
  313. server id to each machine by creating a file named
  314. <span class="codefrag filename">myid</span>, one for each server, which resides in
  315. that server's data directory, as specified by the configuration file
  316. parameter <strong>dataDir</strong>. The myid file
  317. consists of a single line containing only the text of that machine's
  318. id. So <span class="codefrag filename">myid</span> of server 1 would contain the text
  319. "1" and nothing else. The id must be unique within the
  320. quorum.</p>
  321. </li>
  322. <li>
  323. <p>If your configuration file is set up, you can start
  324. Zookeeper:</p>
  325. <pre class="code">$ java -cp zookeeper-dev.jar:java/lib/log4j-1.2.15.jar:conf \
  326. org.apache.zookeeper.server.quorum.QuorumPeerMain zoo.cfg</pre>
  327. </li>
  328. <li>
  329. <p>Test your deployment by connecting to the hosts:</p>
  330. <ul>
  331. <li>
  332. <p>In Java, you can run the following command to execute
  333. simple operations:<remark> [tbd: also, maybe give some of those
  334. simple operations?]</remark>
  335. </p>
  336. <pre class="code">$ java -cp zookeeper.jar:java/lib/log4j-1.2.15.jar:conf \
  337. org.apache.zookeeper.ZooKeeperMain 127.0.0.1:2181</pre>
  338. </li>
  339. <li>
  340. <p>In C, you can compile either the single threaded client or
  341. the multithreaded client: or n the c subdirectory in the
  342. Zookeeper sources. This compiles the single threaded
  343. client:</p>
  344. <pre class="code">$ _make cli_st_</pre>
  345. <p>And this compiles the mulithreaded client:</p>
  346. <pre class="code">$ _make cli_mt_</pre>
  347. </li>
  348. </ul>
  349. <p>Running either program gives you a shell in which to execute
  350. simple file-system-like operations. <remark>[tbd: again, sample
  351. operations?]</remark> To connect to Zookeeper with the multithreaded
  352. client, for example, you would run:</p>
  353. <pre class="code">$ cli_mt 127.0.0.1:2181</pre>
  354. </li>
  355. </ol>
  356. <a name="N100CE"></a><a name="sc_singleAndDevSetup"></a>
  357. <h3 class="h4">Single Server and Developer Setup</h3>
  358. <p>If you want to setup Zookeeper for development purposes, you will
  359. probably want to setup a single server instance of Zookeeper, and then
  360. install either the Java or C client-side libraries and bindings on your
  361. development machine.</p>
  362. <p>The steps to setting up a single server instance are the similar
  363. to the above, except the configuration file is simpler. You can find the
  364. complete instructions in the <a href="zookeeperStarted.html#sc_InstallingSingleMode">Installing
  365. and Running Zookeeper in SIngle Server Mode</a> section of the
  366. <a href="zookeeperStarted.html">Zookeeper
  367. Getting Started Guide</a>.</p>
  368. <p>For information on installing the client side libraries, refer to
  369. the <a href="zookeeperProgrammers.html#Bindings">Bindings</a>
  370. section of the <a href="zookeeperProgrammers.html">Zookeeper
  371. Programmer's Guide</a>.</p>
  372. </div>
  373. <a name="N100EF"></a><a name="Administration"></a>
  374. <h2 class="h3">Administration</h2>
  375. <div class="section">
  376. <p>This chapter contains information about running and maintaining
  377. ZooKeeper and covers these topics: <ul>
  378. <li>
  379. <p>
  380. <a href="#sc_configuration">Configuration Parameters</a>
  381. </p>
  382. </li>
  383. <li>
  384. <p>
  385. <a href="#sc_zkCommands">Zookeeper Commands: The Four Letter Words</a>
  386. </p>
  387. </li>
  388. <li>
  389. <p>
  390. <a href="#sc_dataFileManagement">Data File Management</a>
  391. </p>
  392. </li>
  393. <li>
  394. <p>
  395. <a href="#sc_commonProblems">Things to Avoid</a>
  396. </p>
  397. </li>
  398. <li>
  399. <p>
  400. <a href="#sc_bestPractices">Best Practices</a>
  401. </p>
  402. </li>
  403. </ul>
  404. </p>
  405. <a name="N10122"></a><a name="sc_configuration"></a>
  406. <h3 class="h4">Configuration Parameters</h3>
  407. <p>ZooKeeper's behavior is governed by the ZooKeeper configuration
  408. file. This file is designed so that the exact same file can be used by
  409. all the servers that make up a ZooKeeper server assuming the disk
  410. layouts are the same. If servers use different configuration files,
  411. care must be taken to ensure that the list of servers in all of the
  412. different configuration files match.<remark> [tbd: reformat in
  413. standard form, with legal values, etc]</remark>
  414. </p>
  415. <a name="N1012D"></a><a name="sc_minimumConfiguration"></a>
  416. <h4>Minimum Configuration</h4>
  417. <p>Here are the minimum configuration keywords that must be
  418. defined in the configuration file:</p>
  419. <dl>
  420. <dt>
  421. <term>clientPort</term>
  422. </dt>
  423. <dd>
  424. <p>the port to listen for client connections; that is, the
  425. port that clients attempt to connect to.</p>
  426. </dd>
  427. <dt>
  428. <term>dataDir</term>
  429. </dt>
  430. <dd>
  431. <p>the location where Zookeeper will store the in-memory
  432. database snapshots and, unless specified otherwise, the
  433. transaction log of updates to the database.</p>
  434. <div class="note">
  435. <div class="label">Note</div>
  436. <div class="content">
  437. <p>Be careful where you put the transaction log. A
  438. dedicated transaction log device is key to consistent good
  439. performance. Putting the log on a busy device will adversely
  440. effect performance.</p>
  441. </div>
  442. </div>
  443. </dd>
  444. <dt>
  445. <term>tickTime</term>
  446. </dt>
  447. <dd>
  448. <p>the length of a single tick, which is the basic time
  449. unit used by ZooKeeper, as measured in milliseconds. It is
  450. used to regulate heartbeats, and timeouts. For example, the
  451. minimum session timeout will be two ticks.</p>
  452. </dd>
  453. </dl>
  454. <a name="N10154"></a><a name="sc_advancedConfiguration"></a>
  455. <h4>Advanced Configuration</h4>
  456. <p>The configuration settings in the section are optional. You
  457. can use them to further fine tune the behaviour of your Zookeeper
  458. servers. Some can also be set using Java system properties,
  459. generally of the form <em>zookeeper.keyword</em>. The
  460. exact system property, when available, is noted below.</p>
  461. <dl>
  462. <dt>
  463. <term>dataLogDir</term>
  464. </dt>
  465. <dd>
  466. <p>(No Java system property)</p>
  467. <p>This option will direct the machine to write the
  468. transaction log to the <strong>dataLogDir</strong> rather than the <strong>dataDir</strong>. This allows a dedicated log
  469. device to be used, and helps avoid competition between logging
  470. and snaphots.</p>
  471. <div class="note">
  472. <div class="label">Note</div>
  473. <div class="content">
  474. <p>Having a dedicated log device has a large impact on
  475. throughput and stable latencies. It is highly recommened to
  476. dedicate a log device and set <strong>dataLogDir</strong> to point to a directory on
  477. that device, and then make sure to point <strong>dataDir</strong> to a directory
  478. <em>not</em> residing on that device.</p>
  479. </div>
  480. </div>
  481. </dd>
  482. <dt>
  483. <term>globalOutstandingLimit</term>
  484. </dt>
  485. <dd>
  486. <p>(Java system property: <strong>zookeeper.globalOutstandingLimit.</strong>)</p>
  487. <p>Clients can submit requests faster than ZooKeeper can
  488. process them, especially if there are a lot of clients. To
  489. prevent ZooKeeper from running out of memory due to queued
  490. requests, ZooKeeper will throttle clients so that there is no
  491. more than globalOutstandingLimit outstanding requests in the
  492. system. The default limit is 1,000.</p>
  493. </dd>
  494. <dt>
  495. <term>preAllocSize</term>
  496. </dt>
  497. <dd>
  498. <p>(Java system property: <strong>zookeeper.preAllocSize</strong>)</p>
  499. <p>To avoid seeks ZooKeeper allocates space in the
  500. transaction log file in blocks of preAllocSize kilobytes. The
  501. default block size is 64M. One reason for changing the size of
  502. the blocks is to reduce the block size if snapshots are taken
  503. more often. (Also, see <strong>snapCount</strong>).</p>
  504. </dd>
  505. <dt>
  506. <term>snapCount</term>
  507. </dt>
  508. <dd>
  509. <p>(Java system property: <strong>zookeeper.snapCount</strong>)</p>
  510. <p>Clients can submit requests faster than ZooKeeper can
  511. process them, especially if there are a lot of clients. To
  512. prevent ZooKeeper from running out of memory due to queued
  513. requests, ZooKeeper will throttle clients so that there is no
  514. more than globalOutstandingLimit outstanding requests in the
  515. system. The default limit is 1,000.ZooKeeper logs transactions
  516. to a transaction log. After snapCount transactions are written
  517. to a log file a snapshot is started and a new transaction log
  518. file is started. The default snapCount is 10,000.</p>
  519. </dd>
  520. <dt>
  521. <term>traceFile</term>
  522. </dt>
  523. <dd>
  524. <p>(Java system property: <strong>requestTraceFile</strong>)</p>
  525. <p>If this option is defined, requests will be will logged
  526. to a trace file named traceFile.year.month.day. Use of this
  527. option provides useful debugging information, but will impact
  528. performance. (Note: The system property has no zookeeper
  529. prefix, and the configuration variable name is different from
  530. the system property. Yes - it's not consistent, and it's
  531. annoying.<remark> [tbd: is there any explanation for
  532. this?]</remark>)</p>
  533. </dd>
  534. </dl>
  535. <a name="N101B7"></a><a name="sc_clusterOptions"></a>
  536. <h4>Cluster Options</h4>
  537. <p>The options in this section are designed for use in quorums --
  538. that is, when deploying clusters of servers.</p>
  539. <dl>
  540. <dt>
  541. <term>electionAlg:</term>
  542. </dt>
  543. <dd>
  544. <p>(No Java system property)</p>
  545. <p>Election implementation to use. A value of "0"
  546. corresponds to the original UDP-based version, "1" corresponds
  547. to the non-authenticated UDP-based version of fast leader
  548. election, "2" corresponds to the authenticated UDP-based
  549. version of fast leader election, and "3" corresponds to
  550. TCP-based version of fast leader election</p>
  551. </dd>
  552. <dt>
  553. <term>electionPort</term>
  554. </dt>
  555. <dd>
  556. <p>(No Java system property)</p>
  557. <p>Port used for leader election. It is only used when the
  558. election algorithm is not "0". When the election algorithm is
  559. "0" a UDP port with the same port number as the port listed in
  560. the <strong>server.num</strong> option will be
  561. used. <remark>[tbd: should that be <strong>server.id</strong>? Also, why isn't server.id
  562. documented anywhere?]</remark>
  563. </p>
  564. </dd>
  565. <dt>
  566. <term>initLimit</term>
  567. </dt>
  568. <dd>
  569. <p>(No Java system property)</p>
  570. <p>Amount of time, in ticks (see <a href="#id_tickTime">tickTime</a>), to allow followers to
  571. connect and sync to a leader. Increased this value as needed,
  572. if the amount of data managed by ZooKeeper is large.</p>
  573. </dd>
  574. <dt>
  575. <term>leaderServes</term>
  576. </dt>
  577. <dd>
  578. <p>(Java system property: zookeeper.<strong>leaderServes</strong>)</p>
  579. <p>Leader accepts client connections. Default value is
  580. "yes". The leader machine coordinates updates. For higher
  581. update throughput at thes slight expense of read throughput
  582. the leader can be configured to not accept clients and focus
  583. on coordination. The default to this option is yes, which
  584. means that a leader will accept client connections.
  585. <remark>[tbd: how do you specifiy which server is the
  586. leader?]</remark>
  587. </p>
  588. <div class="note">
  589. <div class="label">Note</div>
  590. <div class="content">
  591. <p>Turning on leader selection is highly recommended when
  592. you have more than three Zookeeper servers in a
  593. quorum.</p>
  594. </div>
  595. </div>
  596. </dd>
  597. <dt>
  598. <term>server.x=[hostname]:nnnn, etc</term>
  599. </dt>
  600. <dd>
  601. <p>(No Java system property)</p>
  602. <p>servers making up the Zookeeper quorum. When the server
  603. starts up, it determines which server it is by looking for the
  604. file <span class="codefrag filename">myid</span> in the data directory.<remark>
  605. [tdb: should we mention somewhere about creating this file,
  606. myid, in the setup procedure?]</remark> That file contains the
  607. server number, in ASCII, and it should match <strong>x</strong> in <strong>server.x</strong> in the left hand side of this
  608. setting.</p>
  609. <p>The list of servers that make up ZooKeeper servers that
  610. is used by the clients must match the list of ZooKeeper
  611. servers that each ZooKeeper server has.</p>
  612. <p>The port numbers <strong>nnnn</strong>
  613. in this setting are the <em>electionPort</em>
  614. numbers of the servers (as opposed to clientPorts).
  615. <remark>[tbd: is the next sentence explanation an of what the
  616. election port or is it a description of a special case?]
  617. </remark>If you want to test multiple servers on a single
  618. machine, the individual choices of electionPort for each
  619. server can be defined in each server's config files using the
  620. line electionPort=xxxx to avoid clashes.</p>
  621. </dd>
  622. <dt>
  623. <term>syncLimit</term>
  624. </dt>
  625. <dd>
  626. <p>(No Java system property)</p>
  627. <p>Amount of time, in ticks (see <a href="#id_tickTime">tickTime</a>), to allow followers to
  628. sync with ZooKeeper. If followers fall too far behind a
  629. leader, they will be dropped. <remark>[tbd: is this a correct
  630. rewording: if followers fall beyond this limit, they are
  631. dropped?]</remark>
  632. </p>
  633. </dd>
  634. </dl>
  635. <p></p>
  636. <a name="N10232"></a><a name="Unsafe+Options"></a>
  637. <h4>Unsafe Options</h4>
  638. <p>The following options can be useful, but be careful when you
  639. use them. The risk of each is explained along with the explanation
  640. of what the variable does.</p>
  641. <dl>
  642. <dt>
  643. <term>forceSync</term>
  644. </dt>
  645. <dd>
  646. <p>(Java system property: <strong>zookeeper.forceSync</strong>)</p>
  647. <p>Requires updates to be synced to media of the
  648. transaction log before finishing processing the update. If
  649. this option is set to no, ZooKeeper will not require updates
  650. to be synced to the media. <remark>[tbd: useful because...,
  651. dangerous because...]</remark>
  652. </p>
  653. </dd>
  654. <dt>
  655. <term>jute.maxbuffer:</term>
  656. </dt>
  657. <dd>
  658. <p>(Java system property:<strong>
  659. jute.maxbuffer</strong>)</p>
  660. <p>This option can only be set as a Java system property.
  661. There is no zookeeper prefix on it. It specifies the maximum
  662. size of the data that can be stored in a znode. The default is
  663. 0xfffff, or just under 1M. If this option is changed, the
  664. system property must be set on all servers and clients
  665. otherwise problems will arise. This is really a sanity check.
  666. ZooKeeper is designed to store data on the order of kilobytes
  667. in size.</p>
  668. </dd>
  669. <dt>
  670. <term>skipACL</term>
  671. </dt>
  672. <dd>
  673. <p>(Java system property: <strong>zookeeper.skipACL</strong>)</p>
  674. <p>Skips ACL checks. <remark>[tbd: when? where?]</remark>
  675. This results in a boost in throughput, but opens up full
  676. access to the data tree to everyone.</p>
  677. </dd>
  678. </dl>
  679. <a name="N10269"></a><a name="sc_zkCommands"></a>
  680. <h3 class="h4">Zookeeper Commands: The Four Letter Words</h3>
  681. <p>Zookeeper responds to a small set of commands. Each command is composed of
  682. four letters. You issue the commands to Zookeeper via telnet or nc, at
  683. the client port.</p>
  684. <dl>
  685. <dt>
  686. <term>dump</term>
  687. </dt>
  688. <dd>
  689. <p>Lists the outstanding sessions and ephemeral nodes. This
  690. only works on the leader.</p>
  691. </dd>
  692. <dt>
  693. <term>kill</term>
  694. </dt>
  695. <dd>
  696. <p>Shuts down the server. This must be issued from the
  697. machine the Zookeeper server is running on.</p>
  698. </dd>
  699. <dt>
  700. <term>ruok</term>
  701. </dt>
  702. <dd>
  703. <p>Tests if server is running in a non-error state. The
  704. server will respond with imok if it is running. Otherwise it
  705. will not respond at all.</p>
  706. </dd>
  707. <dt>
  708. <term>stat</term>
  709. </dt>
  710. <dd>
  711. <p>Lists statistics about performance and connected
  712. clients.</p>
  713. </dd>
  714. </dl>
  715. <p>Here's an example of the <strong>ruok</strong>
  716. command:</p>
  717. <pre class="code">$ echo ruok | nc 127.0.0.1 5111
  718. imok
  719. </pre>
  720. <a name="N1029B"></a><a name="sc_monitoring"></a>
  721. <h3 class="h4">Monitoring</h3>
  722. <p>
  723. <remark>[tbd: Patrick, Ben, et al: I believe the Message Broker
  724. team does perform routine monitoring of Zookeeper. But I might be
  725. wrong. To your knowledge, is there any monitoring of a Zookeeper
  726. deployment that will a Zookeeper sys admin will want to do, outside of
  727. Yahoo?]</remark>
  728. </p>
  729. <a name="N102A6"></a><a name="sc_dataFileManagement"></a>
  730. <h3 class="h4">Data File Management</h3>
  731. <p>ZooKeeper stores its data in a data directory and its transaction
  732. log in a transaction log directory. By default these two directories are
  733. the same. The server can (and should) be configured to store the
  734. transaction log files in a separate directory than the data files.
  735. Throughput increases and latency decreases when transaction logs reside
  736. on a dedicated log devices.</p>
  737. <a name="N102AF"></a><a name="The+Data+Directory"></a>
  738. <h4>The Data Directory</h4>
  739. <p>This directory has two files in it:</p>
  740. <ul>
  741. <li>
  742. <p>
  743. <span class="codefrag filename">myid</span> - contains a single integer in
  744. human readable ASCII text that represents the server id.</p>
  745. </li>
  746. <li>
  747. <p>
  748. <span class="codefrag filename">snapshot.&lt;zxid&gt;</span> - holds the fuzzy
  749. snapshot of a data tree.</p>
  750. </li>
  751. </ul>
  752. <p>Each ZooKeeper server has a unique id. This id is used in two
  753. places: the <span class="codefrag filename">myid</span> file and the configuration file.
  754. The <span class="codefrag filename">myid</span> file identifies the server that
  755. corresponds to the given data directory. The configuration file lists
  756. the contact information for each server identified by its server id.
  757. When a ZooKeeper server instance starts, it reads its id from the
  758. <span class="codefrag filename">myid</span> file and then, using that id, reads from the
  759. configuration file, looking up the port on which it should
  760. listen.</p>
  761. <p>The <span class="codefrag filename">snapshot</span> files stored in the data
  762. directory are fuzzy snapshots in the sense that during the time the
  763. ZooKeeper server is taking the snapshot, updates are occurring to the
  764. data tree. The suffix of the <span class="codefrag filename">snapshot</span> file names
  765. is the <em>zxid</em>, the ZooKeeper transaction id, of the
  766. last committed transaction at the start of the snapshot. Thus, the
  767. snapshot includes a subset of the updates to the data tree that
  768. occurred while the snapshot was in process. The snapshot, then, may
  769. not correspond to any data tree that actually existed, and for this
  770. reason we refer to it as a fuzzy snapshot. Still, ZooKeeper can
  771. recover using this snapshot because it takes advantage of the
  772. idempotent nature of its updates. By replaying the transaction log
  773. against fuzzy snapshots ZooKeeper gets the state of the system at the
  774. end of the log.</p>
  775. <a name="N102EB"></a><a name="The+Log+Directory"></a>
  776. <h4>The Log Directory</h4>
  777. <p>The Log Directory contains the ZooKeeper transaction logs.
  778. Before any update takes place, ZooKeeper ensures that the transaction
  779. that represents the update is written to non-volatile storage. A new
  780. log file is started each time a snapshot is begun. The log file's
  781. suffix is the first zxid written to that log.</p>
  782. <a name="N102F5"></a><a name="File+Management"></a>
  783. <h4>File Management</h4>
  784. <p>The format of snapshot and log files does not change between
  785. standalone ZooKeeper servers and different configurations of
  786. replicated ZooKeeper servers. Therefore, you can pull these files from
  787. a running replicated ZooKeeper server to a development machine with a
  788. stand-alone ZooKeeper server for trouble shooting.</p>
  789. <p>Using older log and snapshot files, you can look at the previous
  790. state of ZooKeeper servers and even restore that state. The
  791. LogFormatter class allows an administrator to look at the transactions
  792. in a log.</p>
  793. <p>The ZooKeeper server creates snapshot and log files, but never
  794. deletes them. The retention policy of the data and log files is
  795. implemented outside of the ZooKeeper server. The server itself only
  796. needs the latest complete fuzzy snapshot and the log files from the
  797. start of that snapshot. The PurgeTxnLog utility implements a simple
  798. retention policy that administrators can use.</p>
  799. <a name="N10306"></a><a name="sc_commonProblems"></a>
  800. <h3 class="h4">Things to Avoid</h3>
  801. <p>Here are some common problems you can avoid by configuring
  802. ZooKeeper correctly:</p>
  803. <dl>
  804. <dt>
  805. <term>inconsistent lists of servers</term>
  806. </dt>
  807. <dd>
  808. <p>The list of Zookeeper servers used by the clients must match
  809. the list of ZooKeeper servers that each ZooKeeper server has.
  810. Things work okay if the client list is a subset of the real list,
  811. but things will really act strange if clients have a list of
  812. ZooKeeper servers that are in different ZooKeeper clusters. Also,
  813. the server lists in each Zookeeper server configuration file
  814. should be consistent with one another. <remark>[tbd: I'm assuming
  815. this last part is true. Is it?]</remark>
  816. </p>
  817. </dd>
  818. <dt>
  819. <term>incorrect placement of transasction log</term>
  820. </dt>
  821. <dd>
  822. <p>The most performance critical part of ZooKeeper is the
  823. transaction log. Zookeeper syncs transactions to media before it
  824. returns a response. A dedicated transaction log device is key to
  825. consistent good performance. Putting the log on a busy device will
  826. adversely effect performance. If you only have one storage device,
  827. put trace files on NFS and increase the snapshotCount; it doesn't
  828. eliminate the problem, but it should mitigate it.</p>
  829. </dd>
  830. <dt>
  831. <term>incorrect Java heap size</term>
  832. </dt>
  833. <dd>
  834. <p>You should take special care to set your Java max heap size
  835. correctly. In particular, you should not create a situation in
  836. which Zookeeper swaps to disk. The disk is death to ZooKeeper.
  837. Everything is ordered, so if processing one request swaps the
  838. disk, all other queued requests will probably do the same. the
  839. disk. DON'T SWAP.</p>
  840. <p>Be conservative in your estimates: if you have 4G of RAM, do
  841. not set the Java max heap size to 6G or even 4G. For example, it
  842. is more likely you would use a 3G heap for a 4G machine, as the
  843. operating system and the cache also need memory. The best and only
  844. recommend practice for estimating the heap size your system needs
  845. is to run load tests, and then make sure you are well below the
  846. usage limit that would cause the system to swap.</p>
  847. </dd>
  848. </dl>
  849. <a name="N1032C"></a><a name="sc_bestPractices"></a>
  850. <h3 class="h4">Best Practices</h3>
  851. <p>For best results, take note of the following list of good
  852. Zookeeper practices. <remark>[tbd: I just threw this section in. Do we
  853. have list that is is different from the "things to avoid"? If not, I can
  854. easily remove this section.]</remark>
  855. </p>
  856. </div>
  857. <p align="right">
  858. <font size="-2"></font>
  859. </p>
  860. </div>
  861. <!--+
  862. |end content
  863. +-->
  864. <div class="clearboth">&nbsp;</div>
  865. </div>
  866. <div id="footer">
  867. <!--+
  868. |start bottomstrip
  869. +-->
  870. <div class="lastmodified">
  871. <script type="text/javascript"><!--
  872. document.write("Last Published: " + document.lastModified);
  873. // --></script>
  874. </div>
  875. <div class="copyright">
  876. Copyright &copy;
  877. 2008 <a href="http://www.apache.org/licenses/">The Apache Software Foundation.</a>
  878. </div>
  879. <!--+
  880. |end bottomstrip
  881. +-->
  882. </div>
  883. </body>
  884. </html>