zookeeperAdmin.html 54 KB

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