zookeeperAdmin.html 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231
  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.9">
  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://zookeeper.apache.org/">ZooKeeper</a> &gt; <a href="http://zookeeper.apache.org/">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://zookeeper.apache.org/"><img class="logoImage" alt="ZooKeeper" src="images/zookeeper_small.gif" title="ZooKeeper: distributed coordination"></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="zookeeper.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://zookeeper.apache.org/">Project</a>
  65. </li>
  66. <li>
  67. <a class="unselected" href="https://cwiki.apache.org/confluence/display/ZOOKEEPER/">Wiki</a>
  68. </li>
  69. <li class="current">
  70. <a class="selected" href="index.html">ZooKeeper 3.4 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_1.1', 'skin/')" id="menu_1.1Title" class="menutitle">Overview</div>
  105. <div id="menu_1.1" class="menuitemgroup">
  106. <div class="menuitem">
  107. <a href="index.html">Welcome</a>
  108. </div>
  109. <div class="menuitem">
  110. <a href="zookeeperOver.html">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="releasenotes.html">Release Notes</a>
  117. </div>
  118. </div>
  119. <div onclick="SwitchMenu('menu_1.2', 'skin/')" id="menu_1.2Title" class="menutitle">Developer</div>
  120. <div id="menu_1.2" class="menuitemgroup">
  121. <div class="menuitem">
  122. <a href="api/index.html">API Docs</a>
  123. </div>
  124. <div class="menuitem">
  125. <a href="zookeeperProgrammers.html">Programmer's Guide</a>
  126. </div>
  127. <div class="menuitem">
  128. <a href="javaExample.html">Java Example</a>
  129. </div>
  130. <div class="menuitem">
  131. <a href="zookeeperTutorial.html">Barrier and Queue Tutorial</a>
  132. </div>
  133. <div class="menuitem">
  134. <a href="recipes.html">Recipes</a>
  135. </div>
  136. </div>
  137. <div onclick="SwitchMenu('menu_1.3', 'skin/')" id="menu_1.3Title" class="menutitle">BookKeeper</div>
  138. <div id="menu_1.3" class="menuitemgroup">
  139. <div class="menuitem">
  140. <a href="bookkeeperStarted.html">Getting started</a>
  141. </div>
  142. <div class="menuitem">
  143. <a href="bookkeeperOverview.html">Overview</a>
  144. </div>
  145. <div class="menuitem">
  146. <a href="bookkeeperConfig.html">Setup guide</a>
  147. </div>
  148. <div class="menuitem">
  149. <a href="bookkeeperProgrammer.html">Programmer's guide</a>
  150. </div>
  151. </div>
  152. <div onclick="SwitchMenu('menu_selected_1.4', 'skin/')" id="menu_selected_1.4Title" class="menutitle" style="background-image: url('skin/images/chapter_open.gif');">Admin &amp; Ops</div>
  153. <div id="menu_selected_1.4" class="selectedmenuitemgroup" style="display: block;">
  154. <div class="menupage">
  155. <div class="menupagetitle">Administrator's Guide</div>
  156. </div>
  157. <div class="menuitem">
  158. <a href="zookeeperQuotas.html">Quota Guide</a>
  159. </div>
  160. <div class="menuitem">
  161. <a href="zookeeperJMX.html">JMX</a>
  162. </div>
  163. <div class="menuitem">
  164. <a href="zookeeperObservers.html">Observers Guide</a>
  165. </div>
  166. </div>
  167. <div onclick="SwitchMenu('menu_1.5', 'skin/')" id="menu_1.5Title" class="menutitle">Contributor</div>
  168. <div id="menu_1.5" class="menuitemgroup">
  169. <div class="menuitem">
  170. <a href="zookeeperInternals.html">ZooKeeper Internals</a>
  171. </div>
  172. </div>
  173. <div onclick="SwitchMenu('menu_1.6', 'skin/')" id="menu_1.6Title" class="menutitle">Miscellaneous</div>
  174. <div id="menu_1.6" class="menuitemgroup">
  175. <div class="menuitem">
  176. <a href="https://cwiki.apache.org/confluence/display/ZOOKEEPER">Wiki</a>
  177. </div>
  178. <div class="menuitem">
  179. <a href="https://cwiki.apache.org/confluence/display/ZOOKEEPER/FAQ">FAQ</a>
  180. </div>
  181. <div class="menuitem">
  182. <a href="http://zookeeper.apache.org/mailing_lists.html">Mailing Lists</a>
  183. </div>
  184. </div>
  185. <div id="credit"></div>
  186. <div id="roundbottom">
  187. <img style="display: none" class="corner" height="15" width="15" alt="" src="skin/images/rc-b-l-15-1body-2menu-3menu.png"></div>
  188. <!--+
  189. |alternative credits
  190. +-->
  191. <div id="credit2"></div>
  192. </div>
  193. <!--+
  194. |end Menu
  195. +-->
  196. <!--+
  197. |start content
  198. +-->
  199. <div id="content">
  200. <div title="Portable Document Format" class="pdflink">
  201. <a class="dida" href="zookeeperAdmin.pdf"><img alt="PDF -icon" src="skin/images/pdfdoc.gif" class="skin"><br>
  202. PDF</a>
  203. </div>
  204. <h1>ZooKeeper Administrator's Guide</h1>
  205. <h3>A Guide to Deployment and Administration</h3>
  206. <div id="front-matter">
  207. <div id="minitoc-area">
  208. <ul class="minitoc">
  209. <li>
  210. <a href="#ch_deployment">Deployment</a>
  211. <ul class="minitoc">
  212. <li>
  213. <a href="#sc_systemReq">System Requirements</a>
  214. <ul class="minitoc">
  215. <li>
  216. <a href="#sc_supportedPlatforms">Supported Platforms</a>
  217. </li>
  218. <li>
  219. <a href="#sc_requiredSoftware">Required Software </a>
  220. </li>
  221. </ul>
  222. </li>
  223. <li>
  224. <a href="#sc_zkMulitServerSetup">Clustered (Multi-Server) Setup</a>
  225. </li>
  226. <li>
  227. <a href="#sc_singleAndDevSetup">Single Server and Developer Setup</a>
  228. </li>
  229. </ul>
  230. </li>
  231. <li>
  232. <a href="#ch_administration">Administration</a>
  233. <ul class="minitoc">
  234. <li>
  235. <a href="#sc_designing">Designing a ZooKeeper Deployment</a>
  236. <ul class="minitoc">
  237. <li>
  238. <a href="#sc_CrossMachineRequirements">Cross Machine Requirements</a>
  239. </li>
  240. <li>
  241. <a href="#Single+Machine+Requirements">Single Machine Requirements</a>
  242. </li>
  243. </ul>
  244. </li>
  245. <li>
  246. <a href="#sc_provisioning">Provisioning</a>
  247. </li>
  248. <li>
  249. <a href="#sc_strengthsAndLimitations">Things to Consider: ZooKeeper Strengths and Limitations</a>
  250. </li>
  251. <li>
  252. <a href="#sc_administering">Administering</a>
  253. </li>
  254. <li>
  255. <a href="#sc_maintenance">Maintenance</a>
  256. <ul class="minitoc">
  257. <li>
  258. <a href="#Ongoing+Data+Directory+Cleanup">Ongoing Data Directory Cleanup</a>
  259. </li>
  260. <li>
  261. <a href="#Debug+Log+Cleanup+%28log4j%29">Debug Log Cleanup (log4j)</a>
  262. </li>
  263. </ul>
  264. </li>
  265. <li>
  266. <a href="#sc_supervision">Supervision</a>
  267. </li>
  268. <li>
  269. <a href="#sc_monitoring">Monitoring</a>
  270. </li>
  271. <li>
  272. <a href="#sc_logging">Logging</a>
  273. </li>
  274. <li>
  275. <a href="#sc_troubleshooting">Troubleshooting</a>
  276. </li>
  277. <li>
  278. <a href="#sc_configuration">Configuration Parameters</a>
  279. <ul class="minitoc">
  280. <li>
  281. <a href="#sc_minimumConfiguration">Minimum Configuration</a>
  282. </li>
  283. <li>
  284. <a href="#sc_advancedConfiguration">Advanced Configuration</a>
  285. </li>
  286. <li>
  287. <a href="#sc_clusterOptions">Cluster Options</a>
  288. </li>
  289. <li>
  290. <a href="#sc_authOptions">Authentication &amp; Authorization Options</a>
  291. </li>
  292. <li>
  293. <a href="#Experimental+Options%2FFeatures">Experimental Options/Features</a>
  294. </li>
  295. <li>
  296. <a href="#Unsafe+Options">Unsafe Options</a>
  297. </li>
  298. <li>
  299. <a href="#Communication+using+the+Netty+framework">Communication using the Netty framework</a>
  300. </li>
  301. </ul>
  302. </li>
  303. <li>
  304. <a href="#sc_zkCommands">ZooKeeper Commands: The Four Letter Words</a>
  305. </li>
  306. <li>
  307. <a href="#sc_dataFileManagement">Data File Management</a>
  308. <ul class="minitoc">
  309. <li>
  310. <a href="#The+Data+Directory">The Data Directory</a>
  311. </li>
  312. <li>
  313. <a href="#The+Log+Directory">The Log Directory</a>
  314. </li>
  315. <li>
  316. <a href="#sc_filemanagement">File Management</a>
  317. </li>
  318. <li>
  319. <a href="#Recovery+-+TxnLogToolkit">Recovery - TxnLogToolkit</a>
  320. </li>
  321. </ul>
  322. </li>
  323. <li>
  324. <a href="#sc_commonProblems">Things to Avoid</a>
  325. </li>
  326. <li>
  327. <a href="#sc_bestPractices">Best Practices</a>
  328. </li>
  329. </ul>
  330. </li>
  331. </ul>
  332. </div>
  333. </div>
  334. <a name="ch_deployment"></a>
  335. <h2 class="h3">Deployment</h2>
  336. <div class="section">
  337. <p>This section contains information about deploying Zookeeper and
  338. covers these topics:</p>
  339. <ul>
  340. <li>
  341. <p>
  342. <a href="#sc_systemReq">System Requirements</a>
  343. </p>
  344. </li>
  345. <li>
  346. <p>
  347. <a href="#sc_zkMulitServerSetup">Clustered (Multi-Server) Setup</a>
  348. </p>
  349. </li>
  350. <li>
  351. <p>
  352. <a href="#sc_singleAndDevSetup">Single Server and Developer Setup</a>
  353. </p>
  354. </li>
  355. </ul>
  356. <p>The first two sections assume you are interested in installing
  357. ZooKeeper in a production environment such as a datacenter. The final
  358. section covers situations in which you are setting up ZooKeeper on a
  359. limited basis - for evaluation, testing, or development - but not in a
  360. production environment.</p>
  361. <a name="sc_systemReq"></a>
  362. <h3 class="h4">System Requirements</h3>
  363. <a name="sc_supportedPlatforms"></a>
  364. <h4>Supported Platforms</h4>
  365. <p>ZooKeeper consists of multiple components. Some components are
  366. supported broadly, and other components are supported only on a smaller
  367. set of platforms.</p>
  368. <ul>
  369. <li>
  370. <p>
  371. <strong>Client</strong> is the Java client
  372. library, used by applications to connect to a ZooKeeper ensemble.
  373. </p>
  374. </li>
  375. <li>
  376. <p>
  377. <strong>Server</strong> is the Java server
  378. that runs on the ZooKeeper ensemble nodes.</p>
  379. </li>
  380. <li>
  381. <p>
  382. <strong>Native Client</strong> is a client
  383. implemented in C, similar to the Java client, used by applications
  384. to connect to a ZooKeeper ensemble.</p>
  385. </li>
  386. <li>
  387. <p>
  388. <strong>Contrib</strong> refers to multiple
  389. optional add-on components.</p>
  390. </li>
  391. </ul>
  392. <p>The following matrix describes the level of support committed for
  393. running each component on different operating system platforms.</p>
  394. <table class="ForrestTable" cellspacing="1" cellpadding="4">
  395. <caption>Support Matrix</caption>
  396. <title>Support Matrix</title>
  397. <tr>
  398. <th>Operating System</th>
  399. <th>Client</th>
  400. <th>Server</th>
  401. <th>Native Client</th>
  402. <th>Contrib</th>
  403. </tr>
  404. <tr>
  405. <td>GNU/Linux</td>
  406. <td>Development and Production</td>
  407. <td>Development and Production</td>
  408. <td>Development and Production</td>
  409. <td>Development and Production</td>
  410. </tr>
  411. <tr>
  412. <td>Solaris</td>
  413. <td>Development and Production</td>
  414. <td>Development and Production</td>
  415. <td>Not Supported</td>
  416. <td>Not Supported</td>
  417. </tr>
  418. <tr>
  419. <td>FreeBSD</td>
  420. <td>Development and Production</td>
  421. <td>Development and Production</td>
  422. <td>Not Supported</td>
  423. <td>Not Supported</td>
  424. </tr>
  425. <tr>
  426. <td>Windows</td>
  427. <td>Development and Production</td>
  428. <td>Development and Production</td>
  429. <td>Not Supported</td>
  430. <td>Not Supported</td>
  431. </tr>
  432. <tr>
  433. <td>Mac OS X</td>
  434. <td>Development Only</td>
  435. <td>Development Only</td>
  436. <td>Not Supported</td>
  437. <td>Not Supported</td>
  438. </tr>
  439. </table>
  440. <p>For any operating system not explicitly mentioned as supported in
  441. the matrix, components may or may not work. The ZooKeeper community
  442. will fix obvious bugs that are reported for other platforms, but there
  443. is no full support.</p>
  444. <a name="sc_requiredSoftware"></a>
  445. <h4>Required Software </h4>
  446. <p>ZooKeeper runs in Java, release 1.6 or greater (JDK 6 or
  447. greater). It runs as an <em>ensemble</em> of
  448. ZooKeeper servers. Three ZooKeeper servers is the minimum
  449. recommended size for an ensemble, and we also recommend that
  450. they run on separate machines. At Yahoo!, ZooKeeper is
  451. usually deployed on dedicated RHEL boxes, with dual-core
  452. processors, 2GB of RAM, and 80GB IDE hard drives.</p>
  453. <a name="sc_zkMulitServerSetup"></a>
  454. <h3 class="h4">Clustered (Multi-Server) Setup</h3>
  455. <p>For reliable ZooKeeper service, you should deploy ZooKeeper in a
  456. cluster known as an <em>ensemble</em>. As long as a majority
  457. of the ensemble are up, the service will be available. Because Zookeeper
  458. requires a majority, it is best to use an
  459. odd number of machines. For example, with four machines ZooKeeper can
  460. only handle the failure of a single machine; if two machines fail, the
  461. remaining two machines do not constitute a majority. However, with five
  462. machines ZooKeeper can handle the failure of two machines. </p>
  463. <div class="note">
  464. <div class="label">Note</div>
  465. <div class="content">
  466. <p>
  467. As mentioned in the
  468. <a href="zookeeperStarted.html">ZooKeeper Getting Started Guide</a>
  469. , a minimum of three servers are required for a fault tolerant
  470. clustered setup, and it is strongly recommended that you have an
  471. odd number of servers.
  472. </p>
  473. <p>Usually three servers is more than enough for a production
  474. install, but for maximum reliability during maintenance, you may
  475. wish to install five servers. With three servers, if you perform
  476. maintenance on one of them, you are vulnerable to a failure on one
  477. of the other two servers during that maintenance. If you have five
  478. of them running, you can take one down for maintenance, and know
  479. that you're still OK if one of the other four suddenly fails.
  480. </p>
  481. <p>Your redundancy considerations should include all aspects of
  482. your environment. If you have three ZooKeeper servers, but their
  483. network cables are all plugged into the same network switch, then
  484. the failure of that switch will take down your entire ensemble.
  485. </p>
  486. </div>
  487. </div>
  488. <p>Here are the steps to setting a server that will be part of an
  489. ensemble. These steps should be performed on every host in the
  490. ensemble:</p>
  491. <ol>
  492. <li>
  493. <p>Install the Java JDK. You can use the native packaging system
  494. for your system, or download the JDK from:</p>
  495. <p>
  496. <a href="http://java.sun.com/javase/downloads/index.jsp">http://java.sun.com/javase/downloads/index.jsp</a>
  497. </p>
  498. </li>
  499. <li>
  500. <p>Set the Java heap size. This is very important to avoid
  501. swapping, which will seriously degrade ZooKeeper performance. To
  502. determine the correct value, use load tests, and make sure you are
  503. well below the usage limit that would cause you to swap. Be
  504. conservative - use a maximum heap size of 3GB for a 4GB
  505. machine.</p>
  506. </li>
  507. <li>
  508. <p>Install the ZooKeeper Server Package. It can be downloaded
  509. from:
  510. </p>
  511. <p>
  512. <a href="http://zookeeper.apache.org/releases.html">
  513. http://zookeeper.apache.org/releases.html
  514. </a>
  515. </p>
  516. </li>
  517. <li>
  518. <p>Create a configuration file. This file can be called anything.
  519. Use the following settings as a starting point:</p>
  520. <pre class="code">
  521. tickTime=2000
  522. dataDir=/var/lib/zookeeper/
  523. clientPort=2181
  524. initLimit=5
  525. syncLimit=2
  526. server.1=zoo1:2888:3888
  527. server.2=zoo2:2888:3888
  528. server.3=zoo3:2888:3888</pre>
  529. <p>You can find the meanings of these and other configuration
  530. settings in the section <a href="#sc_configuration">Configuration Parameters</a>. A word
  531. though about a few here:</p>
  532. <p>Every machine that is part of the ZooKeeper ensemble should know
  533. about every other machine in the ensemble. You accomplish this with
  534. the series of lines of the form <strong>server.id=host:port:port</strong>. The parameters <strong>host</strong> and <strong>port</strong> are straightforward. You attribute the
  535. server id to each machine by creating a file named
  536. <span class="codefrag filename">myid</span>, one for each server, which resides in
  537. that server's data directory, as specified by the configuration file
  538. parameter <strong>dataDir</strong>.</p>
  539. </li>
  540. <li>
  541. <p>The myid file
  542. consists of a single line containing only the text of that machine's
  543. id. So <span class="codefrag filename">myid</span> of server 1 would contain the text
  544. "1" and nothing else. The id must be unique within the
  545. ensemble and should have a value between 1 and 255.</p>
  546. </li>
  547. <li>
  548. <p>If your configuration file is set up, you can start a
  549. ZooKeeper server:</p>
  550. <p>
  551. <span class="codefrag computeroutput">$ java -cp zookeeper.jar:lib/slf4j-api-1.6.1.jar:lib/slf4j-log4j12-1.6.1.jar:lib/log4j-1.2.15.jar:conf \
  552. org.apache.zookeeper.server.quorum.QuorumPeerMain zoo.cfg
  553. </span>
  554. </p>
  555. <p>QuorumPeerMain starts a ZooKeeper server,
  556. <a href="http://java.sun.com/javase/technologies/core/mntr-mgmt/javamanagement/">JMX</a>
  557. management beans are also registered which allows
  558. management through a JMX management console.
  559. The <a href="zookeeperJMX.html">ZooKeeper JMX
  560. document</a> contains details on managing ZooKeeper with JMX.
  561. </p>
  562. <p>See the script <em>bin/zkServer.sh</em>,
  563. which is included in the release, for an example
  564. of starting server instances.</p>
  565. </li>
  566. <li>
  567. <p>Test your deployment by connecting to the hosts:</p>
  568. <p>In Java, you can run the following command to execute
  569. simple operations:</p>
  570. <p>
  571. <span class="codefrag computeroutput">$ bin/zkCli.sh -server 127.0.0.1:2181</span>
  572. </p>
  573. </li>
  574. </ol>
  575. <a name="sc_singleAndDevSetup"></a>
  576. <h3 class="h4">Single Server and Developer Setup</h3>
  577. <p>If you want to setup ZooKeeper for development purposes, you will
  578. probably want to setup a single server instance of ZooKeeper, and then
  579. install either the Java or C client-side libraries and bindings on your
  580. development machine.</p>
  581. <p>The steps to setting up a single server instance are the similar
  582. to the above, except the configuration file is simpler. You can find the
  583. complete instructions in the <a href="zookeeperStarted.html#sc_InstallingSingleMode">Installing and
  584. Running ZooKeeper in Single Server Mode</a> section of the <a href="zookeeperStarted.html">ZooKeeper Getting Started
  585. Guide</a>.</p>
  586. <p>For information on installing the client side libraries, refer to
  587. the <a href="zookeeperProgrammers.html#Bindings">Bindings</a>
  588. section of the <a href="zookeeperProgrammers.html">ZooKeeper
  589. Programmer's Guide</a>.</p>
  590. </div>
  591. <a name="ch_administration"></a>
  592. <h2 class="h3">Administration</h2>
  593. <div class="section">
  594. <p>This section contains information about running and maintaining
  595. ZooKeeper and covers these topics: </p>
  596. <ul>
  597. <li>
  598. <p>
  599. <a href="#sc_designing">Designing a ZooKeeper Deployment</a>
  600. </p>
  601. </li>
  602. <li>
  603. <p>
  604. <a href="#sc_provisioning">Provisioning</a>
  605. </p>
  606. </li>
  607. <li>
  608. <p>
  609. <a href="#sc_strengthsAndLimitations">Things to Consider: ZooKeeper Strengths and Limitations</a>
  610. </p>
  611. </li>
  612. <li>
  613. <p>
  614. <a href="#sc_administering">Administering</a>
  615. </p>
  616. </li>
  617. <li>
  618. <p>
  619. <a href="#sc_maintenance">Maintenance</a>
  620. </p>
  621. </li>
  622. <li>
  623. <p>
  624. <a href="#sc_supervision">Supervision</a>
  625. </p>
  626. </li>
  627. <li>
  628. <p>
  629. <a href="#sc_monitoring">Monitoring</a>
  630. </p>
  631. </li>
  632. <li>
  633. <p>
  634. <a href="#sc_logging">Logging</a>
  635. </p>
  636. </li>
  637. <li>
  638. <p>
  639. <a href="#sc_troubleshooting">Troubleshooting</a>
  640. </p>
  641. </li>
  642. <li>
  643. <p>
  644. <a href="#sc_configuration">Configuration Parameters</a>
  645. </p>
  646. </li>
  647. <li>
  648. <p>
  649. <a href="#sc_zkCommands">ZooKeeper Commands: The Four Letter Words</a>
  650. </p>
  651. </li>
  652. <li>
  653. <p>
  654. <a href="#sc_dataFileManagement">Data File Management</a>
  655. </p>
  656. </li>
  657. <li>
  658. <p>
  659. <a href="#sc_commonProblems">Things to Avoid</a>
  660. </p>
  661. </li>
  662. <li>
  663. <p>
  664. <a href="#sc_bestPractices">Best Practices</a>
  665. </p>
  666. </li>
  667. </ul>
  668. <a name="sc_designing"></a>
  669. <h3 class="h4">Designing a ZooKeeper Deployment</h3>
  670. <p>The reliablity of ZooKeeper rests on two basic assumptions.</p>
  671. <ol>
  672. <li>
  673. <p> Only a minority of servers in a deployment
  674. will fail. <em>Failure</em> in this context
  675. means a machine crash, or some error in the network that
  676. partitions a server off from the majority.</p>
  677. </li>
  678. <li>
  679. <p> Deployed machines operate correctly. To
  680. operate correctly means to execute code correctly, to have
  681. clocks that work properly, and to have storage and network
  682. components that perform consistently.</p>
  683. </li>
  684. </ol>
  685. <p>The sections below contain considerations for ZooKeeper
  686. administrators to maximize the probability for these assumptions
  687. to hold true. Some of these are cross-machines considerations,
  688. and others are things you should consider for each and every
  689. machine in your deployment.</p>
  690. <a name="sc_CrossMachineRequirements"></a>
  691. <h4>Cross Machine Requirements</h4>
  692. <p>For the ZooKeeper service to be active, there must be a
  693. majority of non-failing machines that can communicate with
  694. each other. To create a deployment that can tolerate the
  695. failure of F machines, you should count on deploying 2xF+1
  696. machines. Thus, a deployment that consists of three machines
  697. can handle one failure, and a deployment of five machines can
  698. handle two failures. Note that a deployment of six machines
  699. can only handle two failures since three machines is not a
  700. majority. For this reason, ZooKeeper deployments are usually
  701. made up of an odd number of machines.</p>
  702. <p>To achieve the highest probability of tolerating a failure
  703. you should try to make machine failures independent. For
  704. example, if most of the machines share the same switch,
  705. failure of that switch could cause a correlated failure and
  706. bring down the service. The same holds true of shared power
  707. circuits, cooling systems, etc.</p>
  708. <a name="Single+Machine+Requirements"></a>
  709. <h4>Single Machine Requirements</h4>
  710. <p>If ZooKeeper has to contend with other applications for
  711. access to resourses like storage media, CPU, network, or
  712. memory, its performance will suffer markedly. ZooKeeper has
  713. strong durability guarantees, which means it uses storage
  714. media to log changes before the operation responsible for the
  715. change is allowed to complete. You should be aware of this
  716. dependency then, and take great care if you want to ensure
  717. that ZooKeeper operations aren&rsquo;t held up by your media. Here
  718. are some things you can do to minimize that sort of
  719. degradation:
  720. </p>
  721. <ul>
  722. <li>
  723. <p>ZooKeeper's transaction log must be on a dedicated
  724. device. (A dedicated partition is not enough.) ZooKeeper
  725. writes the log sequentially, without seeking Sharing your
  726. log device with other processes can cause seeks and
  727. contention, which in turn can cause multi-second
  728. delays.</p>
  729. </li>
  730. <li>
  731. <p>Do not put ZooKeeper in a situation that can cause a
  732. swap. In order for ZooKeeper to function with any sort of
  733. timeliness, it simply cannot be allowed to swap.
  734. Therefore, make certain that the maximum heap size given
  735. to ZooKeeper is not bigger than the amount of real memory
  736. available to ZooKeeper. For more on this, see
  737. <a href="#sc_commonProblems">Things to Avoid</a>
  738. below. </p>
  739. </li>
  740. </ul>
  741. <a name="sc_provisioning"></a>
  742. <h3 class="h4">Provisioning</h3>
  743. <p></p>
  744. <a name="sc_strengthsAndLimitations"></a>
  745. <h3 class="h4">Things to Consider: ZooKeeper Strengths and Limitations</h3>
  746. <p></p>
  747. <a name="sc_administering"></a>
  748. <h3 class="h4">Administering</h3>
  749. <p></p>
  750. <a name="sc_maintenance"></a>
  751. <h3 class="h4">Maintenance</h3>
  752. <p>Little long term maintenance is required for a ZooKeeper
  753. cluster however you must be aware of the following:</p>
  754. <a name="Ongoing+Data+Directory+Cleanup"></a>
  755. <h4>Ongoing Data Directory Cleanup</h4>
  756. <p>The ZooKeeper <a href="#var_datadir">Data
  757. Directory</a> contains files which are a persistent copy
  758. of the znodes stored by a particular serving ensemble. These
  759. are the snapshot and transactional log files. As changes are
  760. made to the znodes these changes are appended to a
  761. transaction log. Occasionally, when a log grows large, a
  762. snapshot of the current state of all znodes will be written
  763. to the filesystem and a new transaction log file is created
  764. for future transactions. During snapshotting, ZooKeeper may
  765. continue appending incoming transactions to the old log file.
  766. Therefore, some transactions which are newer than a snapshot
  767. may be found in the last transaction log preceding the
  768. snapshot.
  769. </p>
  770. <p>A ZooKeeper server <strong>will not remove
  771. old snapshots and log files</strong> when using the default
  772. configuration (see autopurge below), this is the
  773. responsibility of the operator. Every serving environment is
  774. different and therefore the requirements of managing these
  775. files may differ from install to install (backup for example).
  776. </p>
  777. <p>The PurgeTxnLog utility implements a simple retention
  778. policy that administrators can use. The <a href="api/index.html">API docs</a> contains details on
  779. calling conventions (arguments, etc...).
  780. </p>
  781. <p>In the following example the last count snapshots and
  782. their corresponding logs are retained and the others are
  783. deleted. The value of &lt;count&gt; should typically be
  784. greater than 3 (although not required, this provides 3 backups
  785. in the unlikely event a recent log has become corrupted). This
  786. can be run as a cron job on the ZooKeeper server machines to
  787. clean up the logs daily.</p>
  788. <pre class="code"> java -cp zookeeper.jar:lib/slf4j-api-1.6.1.jar:lib/slf4j-log4j12-1.6.1.jar:lib/log4j-1.2.15.jar:conf org.apache.zookeeper.server.PurgeTxnLog &lt;dataDir&gt; &lt;snapDir&gt; -n &lt;count&gt;</pre>
  789. <p>Automatic purging of the snapshots and corresponding
  790. transaction logs was introduced in version 3.4.0 and can be
  791. enabled via the following configuration parameters <strong>autopurge.snapRetainCount</strong> and <strong>autopurge.purgeInterval</strong>. For more on
  792. this, see <a href="#sc_advancedConfiguration">Advanced Configuration</a>
  793. below.</p>
  794. <a name="Debug+Log+Cleanup+%28log4j%29"></a>
  795. <h4>Debug Log Cleanup (log4j)</h4>
  796. <p>See the section on <a href="#sc_logging">logging</a> in this document. It is
  797. expected that you will setup a rolling file appender using the
  798. in-built log4j feature. The sample configuration file in the
  799. release tar's conf/log4j.properties provides an example of
  800. this.
  801. </p>
  802. <a name="sc_supervision"></a>
  803. <h3 class="h4">Supervision</h3>
  804. <p>You will want to have a supervisory process that manages
  805. each of your ZooKeeper server processes (JVM). The ZK server is
  806. designed to be "fail fast" meaning that it will shutdown
  807. (process exit) if an error occurs that it cannot recover
  808. from. As a ZooKeeper serving cluster is highly reliable, this
  809. means that while the server may go down the cluster as a whole
  810. is still active and serving requests. Additionally, as the
  811. cluster is "self healing" the failed server once restarted will
  812. automatically rejoin the ensemble w/o any manual
  813. interaction.</p>
  814. <p>Having a supervisory process such as <a href="http://cr.yp.to/daemontools.html">daemontools</a> or
  815. <a href="http://en.wikipedia.org/wiki/Service_Management_Facility">SMF</a>
  816. (other options for supervisory process are also available, it's
  817. up to you which one you would like to use, these are just two
  818. examples) managing your ZooKeeper server ensures that if the
  819. process does exit abnormally it will automatically be restarted
  820. and will quickly rejoin the cluster.</p>
  821. <a name="sc_monitoring"></a>
  822. <h3 class="h4">Monitoring</h3>
  823. <p>The ZooKeeper service can be monitored in one of two
  824. primary ways; 1) the command port through the use of <a href="#sc_zkCommands">4 letter words</a> and 2) <a href="zookeeperJMX.html">JMX</a>. See the appropriate section for
  825. your environment/requirements.</p>
  826. <a name="sc_logging"></a>
  827. <h3 class="h4">Logging</h3>
  828. <p>ZooKeeper uses <strong>log4j</strong> version 1.2 as
  829. its logging infrastructure. The ZooKeeper default <span class="codefrag filename">log4j.properties</span>
  830. file resides in the <span class="codefrag filename">conf</span> directory. Log4j requires that
  831. <span class="codefrag filename">log4j.properties</span> either be in the working directory
  832. (the directory from which ZooKeeper is run) or be accessible from the classpath.</p>
  833. <p>For more information, see
  834. <a href="http://logging.apache.org/log4j/1.2/manual.html#defaultInit">Log4j Default Initialization Procedure</a>
  835. of the log4j manual.</p>
  836. <a name="sc_troubleshooting"></a>
  837. <h3 class="h4">Troubleshooting</h3>
  838. <dl>
  839. <dt>
  840. <term> Server not coming up because of file corruption</term>
  841. </dt>
  842. <dd>
  843. <p>A server might not be able to read its database and fail to come up because of
  844. some file corruption in the transaction logs of the ZooKeeper server. You will
  845. see some IOException on loading ZooKeeper database. In such a case,
  846. make sure all the other servers in your ensemble are up and working. Use "stat"
  847. command on the command port to see if they are in good health. After you have verified that
  848. all the other servers of the ensemble are up, you can go ahead and clean the database
  849. of the corrupt server. Delete all the files in datadir/version-2 and datalogdir/version-2/.
  850. Restart the server.
  851. </p>
  852. </dd>
  853. </dl>
  854. <a name="sc_configuration"></a>
  855. <h3 class="h4">Configuration Parameters</h3>
  856. <p>ZooKeeper's behavior is governed by the ZooKeeper configuration
  857. file. This file is designed so that the exact same file can be used by
  858. all the servers that make up a ZooKeeper server assuming the disk
  859. layouts are the same. If servers use different configuration files, care
  860. must be taken to ensure that the list of servers in all of the different
  861. configuration files match.</p>
  862. <a name="sc_minimumConfiguration"></a>
  863. <h4>Minimum Configuration</h4>
  864. <p>Here are the minimum configuration keywords that must be defined
  865. in the configuration file:</p>
  866. <dl>
  867. <dt>
  868. <term>clientPort</term>
  869. </dt>
  870. <dd>
  871. <p>the port to listen for client connections; that is, the
  872. port that clients attempt to connect to.</p>
  873. </dd>
  874. <dt>
  875. <term>dataDir</term>
  876. </dt>
  877. <dd>
  878. <p>the location where ZooKeeper will store the in-memory
  879. database snapshots and, unless specified otherwise, the
  880. transaction log of updates to the database.</p>
  881. <div class="note">
  882. <div class="label">Note</div>
  883. <div class="content">
  884. <p>Be careful where you put the transaction log. A
  885. dedicated transaction log device is key to consistent good
  886. performance. Putting the log on a busy device will adversely
  887. effect performance.</p>
  888. </div>
  889. </div>
  890. </dd>
  891. <dt>
  892. <term>tickTime</term>
  893. </dt>
  894. <dd>
  895. <p>the length of a single tick, which is the basic time unit
  896. used by ZooKeeper, as measured in milliseconds. It is used to
  897. regulate heartbeats, and timeouts. For example, the minimum
  898. session timeout will be two ticks.</p>
  899. </dd>
  900. </dl>
  901. <a name="sc_advancedConfiguration"></a>
  902. <h4>Advanced Configuration</h4>
  903. <p>The configuration settings in the section are optional. You can
  904. use them to further fine tune the behaviour of your ZooKeeper servers.
  905. Some can also be set using Java system properties, generally of the
  906. form <em>zookeeper.keyword</em>. The exact system
  907. property, when available, is noted below.</p>
  908. <dl>
  909. <dt>
  910. <term>dataLogDir</term>
  911. </dt>
  912. <dd>
  913. <p>(No Java system property)</p>
  914. <p>This option will direct the machine to write the
  915. transaction log to the <strong>dataLogDir</strong> rather than the <strong>dataDir</strong>. This allows a dedicated log
  916. device to be used, and helps avoid competition between logging
  917. and snaphots.</p>
  918. <div class="note">
  919. <div class="label">Note</div>
  920. <div class="content">
  921. <p>Having a dedicated log device has a large impact on
  922. throughput and stable latencies. It is highly recommened to
  923. dedicate a log device and set <strong>dataLogDir</strong> to point to a directory on
  924. that device, and then make sure to point <strong>dataDir</strong> to a directory
  925. <em>not</em> residing on that device.</p>
  926. </div>
  927. </div>
  928. </dd>
  929. <dt>
  930. <term>globalOutstandingLimit</term>
  931. </dt>
  932. <dd>
  933. <p>(Java system property: <strong>zookeeper.globalOutstandingLimit.</strong>)</p>
  934. <p>Clients can submit requests faster than ZooKeeper can
  935. process them, especially if there are a lot of clients. To
  936. prevent ZooKeeper from running out of memory due to queued
  937. requests, ZooKeeper will throttle clients so that there is no
  938. more than globalOutstandingLimit outstanding requests in the
  939. system. The default limit is 1,000.</p>
  940. </dd>
  941. <dt>
  942. <term>preAllocSize</term>
  943. </dt>
  944. <dd>
  945. <p>(Java system property: <strong>zookeeper.preAllocSize</strong>)</p>
  946. <p>To avoid seeks ZooKeeper allocates space in the
  947. transaction log file in blocks of preAllocSize kilobytes. The
  948. default block size is 64M. One reason for changing the size of
  949. the blocks is to reduce the block size if snapshots are taken
  950. more often. (Also, see <strong>snapCount</strong>).</p>
  951. </dd>
  952. <dt>
  953. <term>snapCount</term>
  954. </dt>
  955. <dd>
  956. <p>(Java system property: <strong>zookeeper.snapCount</strong>)</p>
  957. <p>ZooKeeper records its transactions using snapshots and
  958. a transaction log (think write-ahead log).The number of
  959. transactions recorded in the transaction log before a snapshot
  960. can be taken (and the transaction log rolled) is determined
  961. by snapCount. In order to prevent all of the machines in the quorum
  962. from taking a snapshot at the same time, each ZooKeeper server
  963. will take a snapshot when the number of transactions in the transaction log
  964. reaches a runtime generated random value in the [snapCount/2+1, snapCount]
  965. range.The default snapCount is 100,000.</p>
  966. </dd>
  967. <dt>
  968. <term>maxClientCnxns</term>
  969. </dt>
  970. <dd>
  971. <p>(No Java system property)</p>
  972. <p>Limits the number of concurrent connections (at the socket
  973. level) that a single client, identified by IP address, may make
  974. to a single member of the ZooKeeper ensemble. This is used to
  975. prevent certain classes of DoS attacks, including file
  976. descriptor exhaustion. The default is 60. Setting this to 0
  977. entirely removes the limit on concurrent connections.</p>
  978. </dd>
  979. <dt>
  980. <term>clientPortAddress</term>
  981. </dt>
  982. <dd>
  983. <p>
  984. <strong>New in 3.3.0:</strong> the
  985. address (ipv4, ipv6 or hostname) to listen for client
  986. connections; that is, the address that clients attempt
  987. to connect to. This is optional, by default we bind in
  988. such a way that any connection to the <strong>clientPort</strong> for any
  989. address/interface/nic on the server will be
  990. accepted.</p>
  991. </dd>
  992. <dt>
  993. <term>minSessionTimeout</term>
  994. </dt>
  995. <dd>
  996. <p>(No Java system property)</p>
  997. <p>
  998. <strong>New in 3.3.0:</strong> the
  999. minimum session timeout in milliseconds that the server
  1000. will allow the client to negotiate. Defaults to 2 times
  1001. the <strong>tickTime</strong>.</p>
  1002. </dd>
  1003. <dt>
  1004. <term>maxSessionTimeout</term>
  1005. </dt>
  1006. <dd>
  1007. <p>(No Java system property)</p>
  1008. <p>
  1009. <strong>New in 3.3.0:</strong> the
  1010. maximum session timeout in milliseconds that the server
  1011. will allow the client to negotiate. Defaults to 20 times
  1012. the <strong>tickTime</strong>.</p>
  1013. </dd>
  1014. <dt>
  1015. <term>fsync.warningthresholdms</term>
  1016. </dt>
  1017. <dd>
  1018. <p>(Java system property: <strong>zookeeper.fsync.warningthresholdms</strong>)</p>
  1019. <p>
  1020. <strong>New in 3.3.4:</strong> A
  1021. warning message will be output to the log whenever an
  1022. fsync in the Transactional Log (WAL) takes longer than
  1023. this value. The values is specified in milliseconds and
  1024. defaults to 1000. This value can only be set as a
  1025. system property.</p>
  1026. </dd>
  1027. <dt>
  1028. <term>autopurge.snapRetainCount</term>
  1029. </dt>
  1030. <dd>
  1031. <p>(No Java system property)</p>
  1032. <p>
  1033. <strong>New in 3.4.0:</strong>
  1034. When enabled, ZooKeeper auto purge feature retains
  1035. the <strong>autopurge.snapRetainCount</strong> most
  1036. recent snapshots and the corresponding transaction logs in the
  1037. <strong>dataDir</strong> and <strong>dataLogDir</strong> respectively and deletes the rest.
  1038. Defaults to 3. Minimum value is 3.</p>
  1039. </dd>
  1040. <dt>
  1041. <term>autopurge.purgeInterval</term>
  1042. </dt>
  1043. <dd>
  1044. <p>(No Java system property)</p>
  1045. <p>
  1046. <strong>New in 3.4.0:</strong> The
  1047. time interval in hours for which the purge task has to
  1048. be triggered. Set to a positive integer (1 and above)
  1049. to enable the auto purging. Defaults to 0.</p>
  1050. </dd>
  1051. <dt>
  1052. <term>syncEnabled</term>
  1053. </dt>
  1054. <dd>
  1055. <p>(Java system property: <strong>zookeeper.observer.syncEnabled</strong>)</p>
  1056. <p>
  1057. <strong>New in 3.4.6, 3.5.0:</strong>
  1058. The observers now log transaction and write snapshot to disk
  1059. by default like the participants. This reduces the recovery time
  1060. of the observers on restart. Set to "false" to disable this
  1061. feature. Default is "true"</p>
  1062. </dd>
  1063. </dl>
  1064. <a name="sc_clusterOptions"></a>
  1065. <h4>Cluster Options</h4>
  1066. <p>The options in this section are designed for use with an ensemble
  1067. of servers -- that is, when deploying clusters of servers.</p>
  1068. <dl>
  1069. <dt>
  1070. <term>electionAlg</term>
  1071. </dt>
  1072. <dd>
  1073. <p>(No Java system property)</p>
  1074. <p>Election implementation to use. A value of "0" corresponds
  1075. to the original UDP-based version, "1" corresponds to the
  1076. non-authenticated UDP-based version of fast leader election, "2"
  1077. corresponds to the authenticated UDP-based version of fast
  1078. leader election, and "3" corresponds to TCP-based version of
  1079. fast leader election. Currently, algorithm 3 is the default</p>
  1080. <div class="note">
  1081. <div class="label">Note</div>
  1082. <div class="content">
  1083. <p> The implementations of leader election 0, 1, and 2 are now
  1084. <strong> deprecated </strong>. We have the intention
  1085. of removing them in the next release, at which point only the
  1086. FastLeaderElection will be available.
  1087. </p>
  1088. </div>
  1089. </div>
  1090. </dd>
  1091. <dt>
  1092. <term>initLimit</term>
  1093. </dt>
  1094. <dd>
  1095. <p>(No Java system property)</p>
  1096. <p>Amount of time, in ticks (see <a href="#id_tickTime">tickTime</a>), to allow followers to
  1097. connect and sync to a leader. Increased this value as needed, if
  1098. the amount of data managed by ZooKeeper is large.</p>
  1099. </dd>
  1100. <dt>
  1101. <term>leaderServes</term>
  1102. </dt>
  1103. <dd>
  1104. <p>(Java system property: zookeeper.<strong>leaderServes</strong>)</p>
  1105. <p>Leader accepts client connections. Default value is "yes".
  1106. The leader machine coordinates updates. For higher update
  1107. throughput at thes slight expense of read throughput the leader
  1108. can be configured to not accept clients and focus on
  1109. coordination. The default to this option is yes, which means
  1110. that a leader will accept client connections.</p>
  1111. <div class="note">
  1112. <div class="label">Note</div>
  1113. <div class="content">
  1114. <p>Turning on leader selection is highly recommended when
  1115. you have more than three ZooKeeper servers in an ensemble.</p>
  1116. </div>
  1117. </div>
  1118. </dd>
  1119. <dt>
  1120. <term>server.x=[hostname]:nnnnn[:nnnnn], etc</term>
  1121. </dt>
  1122. <dd>
  1123. <p>(No Java system property)</p>
  1124. <p>servers making up the ZooKeeper ensemble. When the server
  1125. starts up, it determines which server it is by looking for the
  1126. file <span class="codefrag filename">myid</span> in the data directory. That file
  1127. contains the server number, in ASCII, and it should match
  1128. <strong>x</strong> in <strong>server.x</strong> in the left hand side of this
  1129. setting.</p>
  1130. <p>The list of servers that make up ZooKeeper servers that is
  1131. used by the clients must match the list of ZooKeeper servers
  1132. that each ZooKeeper server has.</p>
  1133. <p>There are two port numbers <strong>nnnnn</strong>.
  1134. The first followers use to connect to the leader, and the second is for
  1135. leader election. The leader election port is only necessary if electionAlg
  1136. is 1, 2, or 3 (default). If electionAlg is 0, then the second port is not
  1137. necessary. If you want to test multiple servers on a single machine, then
  1138. different ports can be used for each server.</p>
  1139. </dd>
  1140. <dt>
  1141. <term>syncLimit</term>
  1142. </dt>
  1143. <dd>
  1144. <p>(No Java system property)</p>
  1145. <p>Amount of time, in ticks (see <a href="#id_tickTime">tickTime</a>), to allow followers to sync
  1146. with ZooKeeper. If followers fall too far behind a leader, they
  1147. will be dropped.</p>
  1148. </dd>
  1149. <dt>
  1150. <term>group.x=nnnnn[:nnnnn]</term>
  1151. </dt>
  1152. <dd>
  1153. <p>(No Java system property)</p>
  1154. <p>Enables a hierarchical quorum construction."x" is a group identifier
  1155. and the numbers following the "=" sign correspond to server identifiers.
  1156. The left-hand side of the assignment is a colon-separated list of server
  1157. identifiers. Note that groups must be disjoint and the union of all groups
  1158. must be the ZooKeeper ensemble. </p>
  1159. <p> You will find an example <a href="zookeeperHierarchicalQuorums.html">here</a>
  1160. </p>
  1161. </dd>
  1162. <dt>
  1163. <term>weight.x=nnnnn</term>
  1164. </dt>
  1165. <dd>
  1166. <p>(No Java system property)</p>
  1167. <p>Used along with "group", it assigns a weight to a server when
  1168. forming quorums. Such a value corresponds to the weight of a server
  1169. when voting. There are a few parts of ZooKeeper that require voting
  1170. such as leader election and the atomic broadcast protocol. By default
  1171. the weight of server is 1. If the configuration defines groups, but not
  1172. weights, then a value of 1 will be assigned to all servers.
  1173. </p>
  1174. <p> You will find an example <a href="zookeeperHierarchicalQuorums.html">here</a>
  1175. </p>
  1176. </dd>
  1177. <dt>
  1178. <term>cnxTimeout</term>
  1179. </dt>
  1180. <dd>
  1181. <p>(Java system property: zookeeper.<strong>cnxTimeout</strong>)</p>
  1182. <p>Sets the timeout value for opening connections for leader election notifications.
  1183. Only applicable if you are using electionAlg 3.
  1184. </p>
  1185. <div class="note">
  1186. <div class="label">Note</div>
  1187. <div class="content">
  1188. <p>Default value is 5 seconds.</p>
  1189. </div>
  1190. </div>
  1191. </dd>
  1192. <dt>
  1193. <term>4lw.commands.whitelist</term>
  1194. </dt>
  1195. <dd>
  1196. <p>(Java system property: <strong>zookeeper.4lw.commands.whitelist</strong>)</p>
  1197. <p>
  1198. <strong>New in 3.4.10:</strong>
  1199. This property contains a list of comma separated
  1200. <a href="#sc_zkCommands">Four Letter Words</a> commands. It is introduced
  1201. to provide fine grained control over the set of commands ZooKeeper can execute,
  1202. so users can turn off certain commands if necessary.
  1203. By default it contains all supported four letter word commands except "wchp" and "wchc",
  1204. if the property is not specified. If the property is specified, then only commands listed
  1205. in the whitelist are enabled.
  1206. </p>
  1207. <p>Here's an example of the configuration that enables stat, ruok, conf, and isro
  1208. command while disabling the rest of Four Letter Words command:</p>
  1209. <pre class="code">
  1210. 4lw.commands.whitelist=stat, ruok, conf, isro
  1211. </pre>
  1212. <p>Users can also use asterisk option so they don't have to include every command one by one in the list.
  1213. As an example, this will enable all four letter word commands:
  1214. </p>
  1215. <pre class="code">
  1216. 4lw.commands.whitelist=*
  1217. </pre>
  1218. </dd>
  1219. <dt>
  1220. <term>ipReachableTimeout</term>
  1221. </dt>
  1222. <dd>
  1223. <p>(Java system property: <strong>zookeeper.ipReachableTimeout</strong>)</p>
  1224. <p>
  1225. <strong>New in 3.4.11:</strong>
  1226. Set this timeout value for IP addresses reachable checking when hostname is resolved, as mesured in
  1227. milliseconds.
  1228. By default, ZooKeeper will use the first IP address of the hostname(without any reachable checking).
  1229. When zookeeper.ipReachableTimeout is set(larger than 0), ZooKeeper will will try to pick up the first
  1230. IP address which is reachable. This is done by calling Java API InetAddress.isReachable(long timeout)
  1231. function, in which this timeout value is used. If none of such reachable IP address can be found, the
  1232. first IP address of the hostname will be used anyway.
  1233. </p>
  1234. </dd>
  1235. <dt>
  1236. <term>tcpKeepAlive</term>
  1237. </dt>
  1238. <dd>
  1239. <p>(Java system property: <strong>zookeeper.tcpKeepAlive</strong>)</p>
  1240. <p>
  1241. <strong>New in 3.4.11:</strong>
  1242. Setting this to true sets the TCP keepAlive flag on the
  1243. sockets used by quorum members to perform elections.
  1244. This will allow for connections between quorum members to
  1245. remain up when there is network infrastructure that may
  1246. otherwise break them. Some NATs and firewalls may terminate
  1247. or lose state for long running or idle connections.</p>
  1248. <p> Enabling this option relies on OS level settings to work
  1249. properly, check your operating system's options regarding TCP
  1250. keepalive for more information. Defaults to
  1251. <strong>false</strong>.
  1252. </p>
  1253. </dd>
  1254. </dl>
  1255. <p></p>
  1256. <a name="sc_authOptions"></a>
  1257. <h4>Authentication &amp; Authorization Options</h4>
  1258. <p>The options in this section allow control over
  1259. authentication/authorization performed by the service.</p>
  1260. <dl>
  1261. <dt>
  1262. <term>zookeeper.DigestAuthenticationProvider.superDigest</term>
  1263. </dt>
  1264. <dd>
  1265. <p>(Java system property only: <strong>zookeeper.DigestAuthenticationProvider.superDigest</strong>)</p>
  1266. <p>By default this feature is <strong>disabled</strong>
  1267. </p>
  1268. <p>
  1269. <strong>New in 3.2:</strong>
  1270. Enables a ZooKeeper ensemble administrator to access the
  1271. znode hierarchy as a "super" user. In particular no ACL
  1272. checking occurs for a user authenticated as
  1273. super.</p>
  1274. <p>org.apache.zookeeper.server.auth.DigestAuthenticationProvider
  1275. can be used to generate the superDigest, call it with
  1276. one parameter of "super:&lt;password&gt;". Provide the
  1277. generated "super:&lt;data&gt;" as the system property value
  1278. when starting each server of the ensemble.</p>
  1279. <p>When authenticating to a ZooKeeper server (from a
  1280. ZooKeeper client) pass a scheme of "digest" and authdata
  1281. of "super:&lt;password&gt;". Note that digest auth passes
  1282. the authdata in plaintext to the server, it would be
  1283. prudent to use this authentication method only on
  1284. localhost (not over the network) or over an encrypted
  1285. connection.</p>
  1286. </dd>
  1287. <dt>
  1288. <term>isro</term>
  1289. </dt>
  1290. <dd>
  1291. <p>
  1292. <strong>New in 3.4.0:</strong> Tests if
  1293. server is running in read-only mode. The server will respond with
  1294. "ro" if in read-only mode or "rw" if not in read-only mode.</p>
  1295. </dd>
  1296. <dt>
  1297. <term>gtmk</term>
  1298. </dt>
  1299. <dd>
  1300. <p>Gets the current trace mask as a 64-bit signed long value in
  1301. decimal format. See <span class="codefrag command">stmk</span> for an explanation of
  1302. the possible values.</p>
  1303. </dd>
  1304. <dt>
  1305. <term>stmk</term>
  1306. </dt>
  1307. <dd>
  1308. <p>Sets the current trace mask. The trace mask is 64 bits,
  1309. where each bit enables or disables a specific category of trace
  1310. logging on the server. Log4J must be configured to enable
  1311. <span class="codefrag command">TRACE</span> level first in order to see trace logging
  1312. messages. The bits of the trace mask correspond to the following
  1313. trace logging categories.</p>
  1314. <table class="ForrestTable" cellspacing="1" cellpadding="4">
  1315. <caption>Trace Mask Bit Values</caption>
  1316. <title>Trace Mask Bit Values</title>
  1317. <tr>
  1318. <td>0b0000000000</td>
  1319. <td>Unused, reserved for future use.</td>
  1320. </tr>
  1321. <tr>
  1322. <td>0b0000000010</td>
  1323. <td>Logs client requests, excluding ping
  1324. requests.</td>
  1325. </tr>
  1326. <tr>
  1327. <td>0b0000000100</td>
  1328. <td>Unused, reserved for future use.</td>
  1329. </tr>
  1330. <tr>
  1331. <td>0b0000001000</td>
  1332. <td>Logs client ping requests.</td>
  1333. </tr>
  1334. <tr>
  1335. <td>0b0000010000</td>
  1336. <td>Logs packets received from the quorum peer that is
  1337. the current leader, excluding ping requests.</td>
  1338. </tr>
  1339. <tr>
  1340. <td>0b0000100000</td>
  1341. <td>Logs addition, removal and validation of client
  1342. sessions.</td>
  1343. </tr>
  1344. <tr>
  1345. <td>0b0001000000</td>
  1346. <td>Logs delivery of watch events to client
  1347. sessions.</td>
  1348. </tr>
  1349. <tr>
  1350. <td>0b0010000000</td>
  1351. <td>Logs ping packets received from the quorum peer
  1352. that is the current leader.</td>
  1353. </tr>
  1354. <tr>
  1355. <td>0b0100000000</td>
  1356. <td>Unused, reserved for future use.</td>
  1357. </tr>
  1358. <tr>
  1359. <td>0b1000000000</td>
  1360. <td>Unused, reserved for future use.</td>
  1361. </tr>
  1362. </table>
  1363. <p>All remaining bits in the 64-bit value are unused and
  1364. reserved for future use. Multiple trace logging categories are
  1365. specified by calculating the bitwise OR of the documented values.
  1366. The default trace mask is 0b0100110010. Thus, by default, trace
  1367. logging includes client requests, packets received from the
  1368. leader and sessions.</p>
  1369. <p>To set a different trace mask, send a request containing the
  1370. <span class="codefrag command">stmk</span> four-letter word followed by the trace
  1371. mask represented as a 64-bit signed long value. This example uses
  1372. the Perl <span class="codefrag command">pack</span> function to construct a trace
  1373. mask that enables all trace logging categories described above and
  1374. convert it to a 64-bit signed long value with big-endian byte
  1375. order. The result is appended to <span class="codefrag command">stmk</span> and sent
  1376. to the server using netcat. The server responds with the new
  1377. trace mask in decimal format.</p>
  1378. <pre class="code">$ perl -e "print 'stmk', pack('q&gt;', 0b0011111010)" | nc localhost 2181
  1379. 250
  1380. </pre>
  1381. </dd>
  1382. </dl>
  1383. <a name="Experimental+Options%2FFeatures"></a>
  1384. <h4>Experimental Options/Features</h4>
  1385. <p>New features that are currently considered experimental.</p>
  1386. <dl>
  1387. <dt>
  1388. <term>Read Only Mode Server</term>
  1389. </dt>
  1390. <dd>
  1391. <p>(Java system property: <strong>readonlymode.enabled</strong>)</p>
  1392. <p>
  1393. <strong>New in 3.4.0:</strong>
  1394. Setting this value to true enables Read Only Mode server
  1395. support (disabled by default). ROM allows clients
  1396. sessions which requested ROM support to connect to the
  1397. server even when the server might be partitioned from
  1398. the quorum. In this mode ROM clients can still read
  1399. values from the ZK service, but will be unable to write
  1400. values and see changes from other clients. See
  1401. ZOOKEEPER-784 for more details.
  1402. </p>
  1403. </dd>
  1404. </dl>
  1405. <a name="Unsafe+Options"></a>
  1406. <h4>Unsafe Options</h4>
  1407. <p>The following options can be useful, but be careful when you use
  1408. them. The risk of each is explained along with the explanation of what
  1409. the variable does.</p>
  1410. <dl>
  1411. <dt>
  1412. <term>forceSync</term>
  1413. </dt>
  1414. <dd>
  1415. <p>(Java system property: <strong>zookeeper.forceSync</strong>)</p>
  1416. <p>Requires updates to be synced to media of the transaction
  1417. log before finishing processing the update. If this option is
  1418. set to no, ZooKeeper will not require updates to be synced to
  1419. the media.</p>
  1420. </dd>
  1421. <dt>
  1422. <term>jute.maxbuffer:</term>
  1423. </dt>
  1424. <dd>
  1425. <p>(Java system property:<strong>
  1426. jute.maxbuffer</strong>)</p>
  1427. <p>This option can only be set as a Java system property.
  1428. There is no zookeeper prefix on it. It specifies the maximum
  1429. size of the data that can be stored in a znode. The default is
  1430. 0xfffff, or just under 1M. If this option is changed, the system
  1431. property must be set on all servers and clients otherwise
  1432. problems will arise. This is really a sanity check. ZooKeeper is
  1433. designed to store data on the order of kilobytes in size.</p>
  1434. </dd>
  1435. <dt>
  1436. <term>skipACL</term>
  1437. </dt>
  1438. <dd>
  1439. <p>(Java system property: <strong>zookeeper.skipACL</strong>)</p>
  1440. <p>Skips ACL checks. This results in a boost in throughput,
  1441. but opens up full access to the data tree to everyone.</p>
  1442. </dd>
  1443. <dt>
  1444. <term>quorumListenOnAllIPs</term>
  1445. </dt>
  1446. <dd>
  1447. <p>When set to true the ZooKeeper server will listen
  1448. for connections from its peers on all available IP addresses,
  1449. and not only the address configured in the server list of the
  1450. configuration file. It affects the connections handling the
  1451. ZAB protocol and the Fast Leader Election protocol. Default
  1452. value is <strong>false</strong>.</p>
  1453. </dd>
  1454. </dl>
  1455. <a name="Communication+using+the+Netty+framework"></a>
  1456. <h4>Communication using the Netty framework</h4>
  1457. <p>
  1458. <strong>New in
  1459. 3.4:</strong> <a href="http://jboss.org/netty">Netty</a>
  1460. is an NIO based client/server communication framework, it
  1461. simplifies (over NIO being used directly) many of the
  1462. complexities of network level communication for java
  1463. applications. Additionally the Netty framework has built
  1464. in support for encryption (SSL) and authentication
  1465. (certificates). These are optional features and can be
  1466. turned on or off individually.
  1467. </p>
  1468. <p>Prior to version 3.4 ZooKeeper has always used NIO
  1469. directly, however in versions 3.4 and later Netty is
  1470. supported as an option to NIO (replaces). NIO continues to
  1471. be the default, however Netty based communication can be
  1472. used in place of NIO by setting the environment variable
  1473. "zookeeper.serverCnxnFactory" to
  1474. "org.apache.zookeeper.server.NettyServerCnxnFactory". You
  1475. have the option of setting this on either the client(s) or
  1476. server(s), typically you would want to set this on both,
  1477. however that is at your discretion.
  1478. </p>
  1479. <p>
  1480. TBD - tuning options for netty - currently there are none that are netty specific but we should add some. Esp around max bound on the number of reader worker threads netty creates.
  1481. </p>
  1482. <p>
  1483. TBD - how to manage encryption
  1484. </p>
  1485. <p>
  1486. TBD - how to manage certificates
  1487. </p>
  1488. <a name="sc_zkCommands"></a>
  1489. <h3 class="h4">ZooKeeper Commands: The Four Letter Words</h3>
  1490. <p>ZooKeeper responds to a small set of commands. Each command is
  1491. composed of four letters. You issue the commands to ZooKeeper via telnet
  1492. or nc, at the client port.</p>
  1493. <p>Three of the more interesting commands: "stat" gives some
  1494. general information about the server and connected clients,
  1495. while "srvr" and "cons" give extended details on server and
  1496. connections respectively.</p>
  1497. <dl>
  1498. <dt>
  1499. <term>conf</term>
  1500. </dt>
  1501. <dd>
  1502. <p>
  1503. <strong>New in 3.3.0:</strong> Print
  1504. details about serving configuration.</p>
  1505. </dd>
  1506. <dt>
  1507. <term>cons</term>
  1508. </dt>
  1509. <dd>
  1510. <p>
  1511. <strong>New in 3.3.0:</strong> List
  1512. full connection/session details for all clients connected
  1513. to this server. Includes information on numbers of packets
  1514. received/sent, session id, operation latencies, last
  1515. operation performed, etc...</p>
  1516. </dd>
  1517. <dt>
  1518. <term>crst</term>
  1519. </dt>
  1520. <dd>
  1521. <p>
  1522. <strong>New in 3.3.0:</strong> Reset
  1523. connection/session statistics for all connections.</p>
  1524. </dd>
  1525. <dt>
  1526. <term>dump</term>
  1527. </dt>
  1528. <dd>
  1529. <p>Lists the outstanding sessions and ephemeral nodes. This
  1530. only works on the leader.</p>
  1531. </dd>
  1532. <dt>
  1533. <term>envi</term>
  1534. </dt>
  1535. <dd>
  1536. <p>Print details about serving environment</p>
  1537. </dd>
  1538. <dt>
  1539. <term>ruok</term>
  1540. </dt>
  1541. <dd>
  1542. <p>Tests if server is running in a non-error state. The server
  1543. will respond with imok if it is running. Otherwise it will not
  1544. respond at all.</p>
  1545. <p>A response of "imok" does not necessarily indicate that the
  1546. server has joined the quorum, just that the server process is active
  1547. and bound to the specified client port. Use "stat" for details on
  1548. state wrt quorum and client connection information.</p>
  1549. </dd>
  1550. <dt>
  1551. <term>srst</term>
  1552. </dt>
  1553. <dd>
  1554. <p>Reset server statistics.</p>
  1555. </dd>
  1556. <dt>
  1557. <term>srvr</term>
  1558. </dt>
  1559. <dd>
  1560. <p>
  1561. <strong>New in 3.3.0:</strong> Lists
  1562. full details for the server.</p>
  1563. </dd>
  1564. <dt>
  1565. <term>stat</term>
  1566. </dt>
  1567. <dd>
  1568. <p>Lists brief details for the server and connected
  1569. clients.</p>
  1570. </dd>
  1571. <dt>
  1572. <term>wchs</term>
  1573. </dt>
  1574. <dd>
  1575. <p>
  1576. <strong>New in 3.3.0:</strong> Lists
  1577. brief information on watches for the server.</p>
  1578. </dd>
  1579. <dt>
  1580. <term>wchc</term>
  1581. </dt>
  1582. <dd>
  1583. <p>
  1584. <strong>New in 3.3.0:</strong> Lists
  1585. detailed information on watches for the server, by
  1586. session. This outputs a list of sessions(connections)
  1587. with associated watches (paths). Note, depending on the
  1588. number of watches this operation may be expensive (ie
  1589. impact server performance), use it carefully.</p>
  1590. </dd>
  1591. <dt>
  1592. <term>wchp</term>
  1593. </dt>
  1594. <dd>
  1595. <p>
  1596. <strong>New in 3.3.0:</strong> Lists
  1597. detailed information on watches for the server, by path.
  1598. This outputs a list of paths (znodes) with associated
  1599. sessions. Note, depending on the number of watches this
  1600. operation may be expensive (ie impact server performance),
  1601. use it carefully.</p>
  1602. </dd>
  1603. <dt>
  1604. <term>mntr</term>
  1605. </dt>
  1606. <dd>
  1607. <p>
  1608. <strong>New in 3.4.0:</strong> Outputs a list
  1609. of variables that could be used for monitoring the health of the cluster.</p>
  1610. <pre class="code">$ echo mntr | nc localhost 2185
  1611. zk_version 3.4.0
  1612. zk_avg_latency 0
  1613. zk_max_latency 0
  1614. zk_min_latency 0
  1615. zk_packets_received 70
  1616. zk_packets_sent 69
  1617. zk_outstanding_requests 0
  1618. zk_server_state leader
  1619. zk_znode_count 4
  1620. zk_watch_count 0
  1621. zk_ephemerals_count 0
  1622. zk_approximate_data_size 27
  1623. zk_followers 4 - only exposed by the Leader
  1624. zk_synced_followers 4 - only exposed by the Leader
  1625. zk_pending_syncs 0 - only exposed by the Leader
  1626. zk_open_file_descriptor_count 23 - only available on Unix platforms
  1627. zk_max_file_descriptor_count 1024 - only available on Unix platforms
  1628. zk_fsync_threshold_exceed_count 0
  1629. </pre>
  1630. <p>The output is compatible with java properties format and the content
  1631. may change over time (new keys added). Your scripts should expect changes.</p>
  1632. <p>ATTENTION: Some of the keys are platform specific and some of the keys are only exported by the Leader. </p>
  1633. <p>The output contains multiple lines with the following format:</p>
  1634. <pre class="code">key \t value</pre>
  1635. </dd>
  1636. </dl>
  1637. <p>Here's an example of the <strong>ruok</strong>
  1638. command:</p>
  1639. <pre class="code">$ echo ruok | nc 127.0.0.1 5111
  1640. imok
  1641. </pre>
  1642. <a name="sc_dataFileManagement"></a>
  1643. <h3 class="h4">Data File Management</h3>
  1644. <p>ZooKeeper stores its data in a data directory and its transaction
  1645. log in a transaction log directory. By default these two directories are
  1646. the same. The server can (and should) be configured to store the
  1647. transaction log files in a separate directory than the data files.
  1648. Throughput increases and latency decreases when transaction logs reside
  1649. on a dedicated log devices.</p>
  1650. <a name="The+Data+Directory"></a>
  1651. <h4>The Data Directory</h4>
  1652. <p>This directory has two files in it:</p>
  1653. <ul>
  1654. <li>
  1655. <p>
  1656. <span class="codefrag filename">myid</span> - contains a single integer in
  1657. human readable ASCII text that represents the server id.</p>
  1658. </li>
  1659. <li>
  1660. <p>
  1661. <span class="codefrag filename">snapshot.&lt;zxid&gt;</span> - holds the fuzzy
  1662. snapshot of a data tree.</p>
  1663. </li>
  1664. </ul>
  1665. <p>Each ZooKeeper server has a unique id. This id is used in two
  1666. places: the <span class="codefrag filename">myid</span> file and the configuration file.
  1667. The <span class="codefrag filename">myid</span> file identifies the server that
  1668. corresponds to the given data directory. The configuration file lists
  1669. the contact information for each server identified by its server id.
  1670. When a ZooKeeper server instance starts, it reads its id from the
  1671. <span class="codefrag filename">myid</span> file and then, using that id, reads from the
  1672. configuration file, looking up the port on which it should
  1673. listen.</p>
  1674. <p>The <span class="codefrag filename">snapshot</span> files stored in the data
  1675. directory are fuzzy snapshots in the sense that during the time the
  1676. ZooKeeper server is taking the snapshot, updates are occurring to the
  1677. data tree. The suffix of the <span class="codefrag filename">snapshot</span> file names
  1678. is the <em>zxid</em>, the ZooKeeper transaction id, of the
  1679. last committed transaction at the start of the snapshot. Thus, the
  1680. snapshot includes a subset of the updates to the data tree that
  1681. occurred while the snapshot was in process. The snapshot, then, may
  1682. not correspond to any data tree that actually existed, and for this
  1683. reason we refer to it as a fuzzy snapshot. Still, ZooKeeper can
  1684. recover using this snapshot because it takes advantage of the
  1685. idempotent nature of its updates. By replaying the transaction log
  1686. against fuzzy snapshots ZooKeeper gets the state of the system at the
  1687. end of the log.</p>
  1688. <a name="The+Log+Directory"></a>
  1689. <h4>The Log Directory</h4>
  1690. <p>The Log Directory contains the ZooKeeper transaction logs.
  1691. Before any update takes place, ZooKeeper ensures that the transaction
  1692. that represents the update is written to non-volatile storage. A new
  1693. log file is started when the number of transactions written to the
  1694. current log file reaches a (variable) threshold. The threshold is
  1695. computed using the same parameter which influences the frequency of
  1696. snapshotting (see snapCount above). The log file's suffix is the first
  1697. zxid written to that log.</p>
  1698. <a name="sc_filemanagement"></a>
  1699. <h4>File Management</h4>
  1700. <p>The format of snapshot and log files does not change between
  1701. standalone ZooKeeper servers and different configurations of
  1702. replicated ZooKeeper servers. Therefore, you can pull these files from
  1703. a running replicated ZooKeeper server to a development machine with a
  1704. stand-alone ZooKeeper server for trouble shooting.</p>
  1705. <p>Using older log and snapshot files, you can look at the previous
  1706. state of ZooKeeper servers and even restore that state. The
  1707. LogFormatter class allows an administrator to look at the transactions
  1708. in a log.</p>
  1709. <p>The ZooKeeper server creates snapshot and log files, but
  1710. never deletes them. The retention policy of the data and log
  1711. files is implemented outside of the ZooKeeper server. The
  1712. server itself only needs the latest complete fuzzy snapshot, all log
  1713. files following it, and the last log file preceding it. The latter
  1714. requirement is necessary to include updates which happened after this
  1715. snapshot was started but went into the existing log file at that time.
  1716. This is possible because snapshotting and rolling over of logs
  1717. proceed somewhat independently in ZooKeeper. See the
  1718. <a href="#sc_maintenance">maintenance</a> section in
  1719. this document for more details on setting a retention policy
  1720. and maintenance of ZooKeeper storage.
  1721. </p>
  1722. <div class="note">
  1723. <div class="label">Note</div>
  1724. <div class="content">
  1725. <p>The data stored in these files is not encrypted. In the case of
  1726. storing sensitive data in ZooKeeper, necessary measures need to be
  1727. taken to prevent unauthorized access. Such measures are external to
  1728. ZooKeeper (e.g., control access to the files) and depend on the
  1729. individual settings in which it is being deployed. </p>
  1730. </div>
  1731. </div>
  1732. <a name="Recovery+-+TxnLogToolkit"></a>
  1733. <h4>Recovery - TxnLogToolkit</h4>
  1734. <p>TxnLogToolkit is a command line tool shipped with ZooKeeper which
  1735. is capable of recovering transaction log entries with broken CRC.</p>
  1736. <p>Running it without any command line parameters or with the "-h,--help"
  1737. argument, it outputs the following help page:</p>
  1738. <pre class="code">
  1739. $ bin/zkTxnLogToolkit.sh
  1740. usage: TxnLogToolkit [-dhrv] txn_log_file_name
  1741. -d,--dump Dump mode. Dump all entries of the log file. (this is the default)
  1742. -h,--help Print help message
  1743. -r,--recover Recovery mode. Re-calculate CRC for broken entries.
  1744. -v,--verbose Be verbose in recovery mode: print all entries, not just fixed ones.
  1745. -y,--yes Non-interactive mode: repair all CRC errors without asking
  1746. </pre>
  1747. <p>The default behaviour is safe: it dumps the entries of the given
  1748. transaction log file to the screen: (same as using '-d,--dump' parameter)</p>
  1749. <pre class="code">
  1750. $ bin/zkTxnLogToolkit.sh log.100000001
  1751. ZooKeeper Transactional Log File with dbid 0 txnlog format version 2
  1752. 4/5/18 2:15:58 PM CEST session 0x16295bafcc40000 cxid 0x0 zxid 0x100000001 createSession 30000
  1753. <strong>CRC ERROR - 4/5/18 2:16:05 PM CEST session 0x16295bafcc40000 cxid 0x1 zxid 0x100000002 closeSession null</strong>
  1754. 4/5/18 2:16:05 PM CEST session 0x16295bafcc40000 cxid 0x1 zxid 0x100000002 closeSession null
  1755. 4/5/18 2:16:12 PM CEST session 0x26295bafcc90000 cxid 0x0 zxid 0x100000003 createSession 30000
  1756. 4/5/18 2:17:34 PM CEST session 0x26295bafcc90000 cxid 0x0 zxid 0x200000001 closeSession null
  1757. 4/5/18 2:17:34 PM CEST session 0x16295bd23720000 cxid 0x0 zxid 0x200000002 createSession 30000
  1758. 4/5/18 2:18:02 PM CEST session 0x16295bd23720000 cxid 0x2 zxid 0x200000003 create '/andor,#626262,v{s{31,s{'world,'anyone}}},F,1
  1759. EOF reached after 6 txns.
  1760. </pre>
  1761. <p>There's a CRC error in the 2nd entry of the above transaction log file. In <strong>dump</strong>
  1762. mode, the toolkit only prints this information to the screen without touching the original file. In
  1763. <strong>recovery</strong> mode (-r,--recover flag) the original file still remains
  1764. untouched and all transactions will be copied over to a new txn log file with ".fixed" suffix. It recalculates
  1765. CRC values and copies the calculated value, if it doesn't match the original txn entry.
  1766. By default, the tool works interactively: it asks for confirmation whenever CRC error encountered.</p>
  1767. <pre class="code">
  1768. $ bin/zkTxnLogToolkit.sh -r log.100000001
  1769. ZooKeeper Transactional Log File with dbid 0 txnlog format version 2
  1770. CRC ERROR - 4/5/18 2:16:05 PM CEST session 0x16295bafcc40000 cxid 0x1 zxid 0x100000002 closeSession null
  1771. Would you like to fix it (Yes/No/Abort) ?
  1772. </pre>
  1773. <p>Answering <strong>Yes</strong> means the newly calculated CRC value will be outputted
  1774. to the new file. <strong>No</strong> means that the original CRC value will be copied over.
  1775. <strong>Abort</strong> will abort the entire operation and exits.
  1776. (In this case the ".fixed" will not be deleted and left in a half-complete state: contains only entries which
  1777. have already been processed or only the header if the operation was aborted at the first entry.)</p>
  1778. <pre class="code">
  1779. $ bin/zkTxnLogToolkit.sh -r log.100000001
  1780. ZooKeeper Transactional Log File with dbid 0 txnlog format version 2
  1781. CRC ERROR - 4/5/18 2:16:05 PM CEST session 0x16295bafcc40000 cxid 0x1 zxid 0x100000002 closeSession null
  1782. Would you like to fix it (Yes/No/Abort) ? y
  1783. EOF reached after 6 txns.
  1784. Recovery file log.100000001.fixed has been written with 1 fixed CRC error(s)
  1785. </pre>
  1786. <p>The default behaviour of recovery is to be silent: only entries with CRC error get printed to the screen.
  1787. One can turn on verbose mode with the -v,--verbose parameter to see all records.
  1788. Interactive mode can be turned off with the -y,--yes parameter. In this case all CRC errors will be fixed
  1789. in the new transaction file.</p>
  1790. <a name="sc_commonProblems"></a>
  1791. <h3 class="h4">Things to Avoid</h3>
  1792. <p>Here are some common problems you can avoid by configuring
  1793. ZooKeeper correctly:</p>
  1794. <dl>
  1795. <dt>
  1796. <term>inconsistent lists of servers</term>
  1797. </dt>
  1798. <dd>
  1799. <p>The list of ZooKeeper servers used by the clients must match
  1800. the list of ZooKeeper servers that each ZooKeeper server has.
  1801. Things work okay if the client list is a subset of the real list,
  1802. but things will really act strange if clients have a list of
  1803. ZooKeeper servers that are in different ZooKeeper clusters. Also,
  1804. the server lists in each Zookeeper server configuration file
  1805. should be consistent with one another.</p>
  1806. </dd>
  1807. <dt>
  1808. <term>incorrect placement of transaction log</term>
  1809. </dt>
  1810. <dd>
  1811. <p>The most performance critical part of ZooKeeper is the
  1812. transaction log. ZooKeeper syncs transactions to media before it
  1813. returns a response. A dedicated transaction log device is key to
  1814. consistent good performance. Putting the log on a busy device will
  1815. adversely effect performance. If you only have one storage device,
  1816. put trace files on NFS and increase the snapshotCount; it doesn't
  1817. eliminate the problem, but it should mitigate it.</p>
  1818. </dd>
  1819. <dt>
  1820. <term>incorrect Java heap size</term>
  1821. </dt>
  1822. <dd>
  1823. <p>You should take special care to set your Java max heap size
  1824. correctly. In particular, you should not create a situation in
  1825. which ZooKeeper swaps to disk. The disk is death to ZooKeeper.
  1826. Everything is ordered, so if processing one request swaps the
  1827. disk, all other queued requests will probably do the same. the
  1828. disk. DON'T SWAP.</p>
  1829. <p>Be conservative in your estimates: if you have 4G of RAM, do
  1830. not set the Java max heap size to 6G or even 4G. For example, it
  1831. is more likely you would use a 3G heap for a 4G machine, as the
  1832. operating system and the cache also need memory. The best and only
  1833. recommend practice for estimating the heap size your system needs
  1834. is to run load tests, and then make sure you are well below the
  1835. usage limit that would cause the system to swap.</p>
  1836. </dd>
  1837. <dt>
  1838. <term>Publicly accessible deployment</term>
  1839. </dt>
  1840. <dd>
  1841. <p>
  1842. A ZooKeeper ensemble is expected to operate in a trusted computing environment.
  1843. It is thus recommended to deploy ZooKeeper behind a firewall.
  1844. </p>
  1845. </dd>
  1846. </dl>
  1847. <a name="sc_bestPractices"></a>
  1848. <h3 class="h4">Best Practices</h3>
  1849. <p>For best results, take note of the following list of good
  1850. Zookeeper practices:</p>
  1851. <p>For multi-tennant installations see the <a href="zookeeperProgrammers.html#ch_zkSessions">section</a>
  1852. detailing ZooKeeper "chroot" support, this can be very useful
  1853. when deploying many applications/services interfacing to a
  1854. single ZooKeeper cluster.</p>
  1855. </div>
  1856. <p align="right">
  1857. <font size="-2"></font>
  1858. </p>
  1859. </div>
  1860. <!--+
  1861. |end content
  1862. +-->
  1863. <div class="clearboth">&nbsp;</div>
  1864. </div>
  1865. <div id="footer">
  1866. <!--+
  1867. |start bottomstrip
  1868. +-->
  1869. <div class="lastmodified">
  1870. <script type="text/javascript"><!--
  1871. document.write("Last Published: " + document.lastModified);
  1872. // --></script>
  1873. </div>
  1874. <div class="copyright">
  1875. Copyright &copy;
  1876. <a href="http://www.apache.org/licenses/">The Apache Software Foundation.</a>
  1877. </div>
  1878. <!--+
  1879. |end bottomstrip
  1880. +-->
  1881. </div>
  1882. </body>
  1883. </html>