zookeeperAdmin.html 33 KB

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