zookeeperAdmin.html 55 KB

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