zookeeperAdmin.html 69 KB

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