zookeeperAdmin.html 62 KB

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