zookeeperAdmin.html 60 KB

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