zookeeperAdmin.html 66 KB

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