zookeeperAdmin.html 57 KB

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