zookeeperAdmin.html 70 KB

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