zookeeperAdmin.html 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469
  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.2 Documentation</a>
  71. </li>
  72. </ul>
  73. <!--+
  74. |end Tabs
  75. +-->
  76. </div>
  77. </div>
  78. <div id="main">
  79. <div id="publishedStrip">
  80. <!--+
  81. |start Subtabs
  82. +-->
  83. <div id="level2tabs"></div>
  84. <!--+
  85. |end Endtabs
  86. +-->
  87. <script type="text/javascript"><!--
  88. document.write("Last Published: " + document.lastModified);
  89. // --></script>
  90. </div>
  91. <!--+
  92. |breadtrail
  93. +-->
  94. <div class="breadtrail">
  95. &nbsp;
  96. </div>
  97. <!--+
  98. |start Menu, mainarea
  99. +-->
  100. <!--+
  101. |start Menu
  102. +-->
  103. <div id="menu">
  104. <div onclick="SwitchMenu('menu_1.1', 'skin/')" id="menu_1.1Title" class="menutitle">Overview</div>
  105. <div id="menu_1.1" class="menuitemgroup">
  106. <div class="menuitem">
  107. <a href="index.html">Welcome</a>
  108. </div>
  109. <div class="menuitem">
  110. <a href="zookeeperOver.html">Overview</a>
  111. </div>
  112. <div class="menuitem">
  113. <a href="zookeeperStarted.html">Getting Started</a>
  114. </div>
  115. <div class="menuitem">
  116. <a href="releasenotes.html">Release Notes</a>
  117. </div>
  118. </div>
  119. <div onclick="SwitchMenu('menu_1.2', 'skin/')" id="menu_1.2Title" class="menutitle">Developer</div>
  120. <div id="menu_1.2" class="menuitemgroup">
  121. <div class="menuitem">
  122. <a href="api/index.html">API Docs</a>
  123. </div>
  124. <div class="menuitem">
  125. <a href="zookeeperProgrammers.html">Programmer's Guide</a>
  126. </div>
  127. <div class="menuitem">
  128. <a href="javaExample.html">Java Example</a>
  129. </div>
  130. <div class="menuitem">
  131. <a href="zookeeperTutorial.html">Barrier and Queue Tutorial</a>
  132. </div>
  133. <div class="menuitem">
  134. <a href="recipes.html">Recipes</a>
  135. </div>
  136. </div>
  137. <div onclick="SwitchMenu('menu_selected_1.3', 'skin/')" id="menu_selected_1.3Title" class="menutitle" style="background-image: url('skin/images/chapter_open.gif');">Admin &amp; Ops</div>
  138. <div id="menu_selected_1.3" class="selectedmenuitemgroup" style="display: block;">
  139. <div class="menupage">
  140. <div class="menupagetitle">Administrator's Guide</div>
  141. </div>
  142. <div class="menuitem">
  143. <a href="zookeeperQuotas.html">Quota Guide</a>
  144. </div>
  145. <div class="menuitem">
  146. <a href="zookeeperJMX.html">JMX</a>
  147. </div>
  148. </div>
  149. <div onclick="SwitchMenu('menu_1.4', 'skin/')" id="menu_1.4Title" class="menutitle">Contributor</div>
  150. <div id="menu_1.4" class="menuitemgroup">
  151. <div class="menuitem">
  152. <a href="zookeeperInternals.html">ZooKeeper Internals</a>
  153. </div>
  154. </div>
  155. <div onclick="SwitchMenu('menu_1.5', 'skin/')" id="menu_1.5Title" class="menutitle">Miscellaneous</div>
  156. <div id="menu_1.5" class="menuitemgroup">
  157. <div class="menuitem">
  158. <a href="http://wiki.apache.org/hadoop/ZooKeeper">Wiki</a>
  159. </div>
  160. <div class="menuitem">
  161. <a href="http://wiki.apache.org/hadoop/ZooKeeper/FAQ">FAQ</a>
  162. </div>
  163. <div class="menuitem">
  164. <a href="http://hadoop.apache.org/zookeeper/mailing_lists.html">Mailing Lists</a>
  165. </div>
  166. </div>
  167. <div id="credit"></div>
  168. <div id="roundbottom">
  169. <img style="display: none" class="corner" height="15" width="15" alt="" src="skin/images/rc-b-l-15-1body-2menu-3menu.png"></div>
  170. <!--+
  171. |alternative credits
  172. +-->
  173. <div id="credit2"></div>
  174. </div>
  175. <!--+
  176. |end Menu
  177. +-->
  178. <!--+
  179. |start content
  180. +-->
  181. <div id="content">
  182. <div title="Portable Document Format" class="pdflink">
  183. <a class="dida" href="zookeeperAdmin.pdf"><img alt="PDF -icon" src="skin/images/pdfdoc.gif" class="skin"><br>
  184. PDF</a>
  185. </div>
  186. <h1>ZooKeeper Administrator's Guide</h1>
  187. <h3>A Guide to Deployment and Administration</h3>
  188. <div id="minitoc-area">
  189. <ul class="minitoc">
  190. <li>
  191. <a href="#ch_deployment">Deployment</a>
  192. <ul class="minitoc">
  193. <li>
  194. <a href="#sc_systemReq">System Requirements</a>
  195. <ul class="minitoc">
  196. <li>
  197. <a href="#sc_supportedPlatforms">Supported Platforms</a>
  198. </li>
  199. <li>
  200. <a href="#sc_requiredSoftware">Required Software </a>
  201. </li>
  202. </ul>
  203. </li>
  204. <li>
  205. <a href="#sc_zkMulitServerSetup">Clustered (Multi-Server) Setup</a>
  206. </li>
  207. <li>
  208. <a href="#sc_singleAndDevSetup">Single Server and Developer Setup</a>
  209. </li>
  210. </ul>
  211. </li>
  212. <li>
  213. <a href="#ch_administration">Administration</a>
  214. <ul class="minitoc">
  215. <li>
  216. <a href="#sc_designing">Designing a ZooKeeper Deployment</a>
  217. <ul class="minitoc">
  218. <li>
  219. <a href="#sc_CrossMachineRequirements">Cross Machine Requirements</a>
  220. </li>
  221. <li>
  222. <a href="#Single+Machine+Requirements">Single Machine Requirements</a>
  223. </li>
  224. </ul>
  225. </li>
  226. <li>
  227. <a href="#sc_provisioning">Provisioning</a>
  228. </li>
  229. <li>
  230. <a href="#sc_strengthsAndLimitations">Things to Consider: ZooKeeper Strengths and Limitations</a>
  231. </li>
  232. <li>
  233. <a href="#sc_administering">Administering</a>
  234. </li>
  235. <li>
  236. <a href="#sc_maintenance">Maintenance</a>
  237. <ul class="minitoc">
  238. <li>
  239. <a href="#Ongoing+Data+Directory+Cleanup">Ongoing Data Directory Cleanup</a>
  240. </li>
  241. <li>
  242. <a href="#Debug+Log+Cleanup+%28log4j%29">Debug Log Cleanup (log4j)</a>
  243. </li>
  244. </ul>
  245. </li>
  246. <li>
  247. <a href="#sc_monitoring">Monitoring</a>
  248. </li>
  249. <li>
  250. <a href="#sc_logging">Logging</a>
  251. </li>
  252. <li>
  253. <a href="#sc_troubleshooting">Troubleshooting</a>
  254. </li>
  255. <li>
  256. <a href="#sc_configuration">Configuration Parameters</a>
  257. <ul class="minitoc">
  258. <li>
  259. <a href="#sc_minimumConfiguration">Minimum Configuration</a>
  260. </li>
  261. <li>
  262. <a href="#sc_advancedConfiguration">Advanced Configuration</a>
  263. </li>
  264. <li>
  265. <a href="#sc_clusterOptions">Cluster Options</a>
  266. </li>
  267. <li>
  268. <a href="#sc_authOptions">Authentication &amp; Authorization Options</a>
  269. </li>
  270. <li>
  271. <a href="#Unsafe+Options">Unsafe Options</a>
  272. </li>
  273. </ul>
  274. </li>
  275. <li>
  276. <a href="#sc_zkCommands">ZooKeeper Commands: The Four Letter Words</a>
  277. </li>
  278. <li>
  279. <a href="#sc_dataFileManagement">Data File Management</a>
  280. <ul class="minitoc">
  281. <li>
  282. <a href="#The+Data+Directory">The Data Directory</a>
  283. </li>
  284. <li>
  285. <a href="#The+Log+Directory">The Log Directory</a>
  286. </li>
  287. <li>
  288. <a href="#sc_filemanagement">File Management</a>
  289. </li>
  290. </ul>
  291. </li>
  292. <li>
  293. <a href="#sc_commonProblems">Things to Avoid</a>
  294. </li>
  295. <li>
  296. <a href="#sc_bestPractices">Best Practices</a>
  297. </li>
  298. </ul>
  299. </li>
  300. </ul>
  301. </div>
  302. <a name="N1000B"></a><a name="ch_deployment"></a>
  303. <h2 class="h3">Deployment</h2>
  304. <div class="section">
  305. <p>This section contains information about deploying Zookeeper and
  306. covers these topics:</p>
  307. <ul>
  308. <li>
  309. <p>
  310. <a href="#sc_systemReq">System Requirements</a>
  311. </p>
  312. </li>
  313. <li>
  314. <p>
  315. <a href="#sc_zkMulitServerSetup">Clustered (Multi-Server) Setup</a>
  316. </p>
  317. </li>
  318. <li>
  319. <p>
  320. <a href="#sc_singleAndDevSetup">Single Server and Developer Setup</a>
  321. </p>
  322. </li>
  323. </ul>
  324. <p>The first two sections assume you are interested in installing
  325. ZooKeeper in a production environment such as a datacenter. The final
  326. section covers situations in which you are setting up ZooKeeper on a
  327. limited basis - for evaluation, testing, or development - but not in a
  328. production environment.</p>
  329. <a name="N10032"></a><a name="sc_systemReq"></a>
  330. <h3 class="h4">System Requirements</h3>
  331. <a name="N10038"></a><a name="sc_supportedPlatforms"></a>
  332. <h4>Supported Platforms</h4>
  333. <ul>
  334. <li>
  335. <p>GNU/Linux is supported as a development and production
  336. platform for both server and client.</p>
  337. </li>
  338. <li>
  339. <p>Sun Solaris is supported as a development and production
  340. platform for both server and client.</p>
  341. </li>
  342. <li>
  343. <p>FreeBSD is supported as a development and production
  344. platform for clients only. Java NIO selector support in
  345. the FreeBSD JVM is broken.</p>
  346. </li>
  347. <li>
  348. <p>Win32 is supported as a <em>development
  349. platform</em> only for both server and client.</p>
  350. </li>
  351. <li>
  352. <p>MacOSX is supported as a <em>development
  353. platform</em> only for both server and client.</p>
  354. </li>
  355. </ul>
  356. <a name="N10066"></a><a name="sc_requiredSoftware"></a>
  357. <h4>Required Software </h4>
  358. <p>ZooKeeper runs in Java, release 1.6 or greater (JDK 6 or
  359. greater). It runs as an <em>ensemble</em> of
  360. ZooKeeper servers. Three ZooKeeper servers is the minimum
  361. recommended size for an ensemble, and we also recommend that
  362. they run on separate machines. At Yahoo!, ZooKeeper is
  363. usually deployed on dedicated RHEL boxes, with dual-core
  364. processors, 2GB of RAM, and 80GB IDE hard drives.</p>
  365. <a name="N10074"></a><a name="sc_zkMulitServerSetup"></a>
  366. <h3 class="h4">Clustered (Multi-Server) Setup</h3>
  367. <p>For reliable ZooKeeper service, you should deploy ZooKeeper in a
  368. cluster known as an <em>ensemble</em>. As long as a majority
  369. of the ensemble are up, the service will be available. Because Zookeeper
  370. requires a majority, it is best to use an
  371. odd number of machines. For example, with four machines ZooKeeper can
  372. only handle the failure of a single machine; if two machines fail, the
  373. remaining two machines do not constitute a majority. However, with five
  374. machines ZooKeeper can handle the failure of two machines. </p>
  375. <p>Here are the steps to setting a server that will be part of an
  376. ensemble. These steps should be performed on every host in the
  377. ensemble:</p>
  378. <ol>
  379. <li>
  380. <p>Install the Java JDK. You can use the native packaging system
  381. for your system, or download the JDK from:</p>
  382. <p>
  383. <a href="http://java.sun.com/javase/downloads/index.jsp">http://java.sun.com/javase/downloads/index.jsp</a>
  384. </p>
  385. </li>
  386. <li>
  387. <p>Set the Java heap size. This is very important to avoid
  388. swapping, which will seriously degrade ZooKeeper performance. To
  389. determine the correct value, use load tests, and make sure you are
  390. well below the usage limit that would cause you to swap. Be
  391. conservative - use a maximum heap size of 3GB for a 4GB
  392. machine.</p>
  393. </li>
  394. <li>
  395. <p>Install the ZooKeeper Server Package. It can be downloaded
  396. from:
  397. </p>
  398. <p>
  399. <a href="http://hadoop.apache.org/zookeeper/releases.html">
  400. http://hadoop.apache.org/zookeeper/releases.html
  401. </a>
  402. </p>
  403. </li>
  404. <li>
  405. <p>Create a configuration file. This file can be called anything.
  406. Use the following settings as a starting point:</p>
  407. <p>
  408. <span class="codefrag computeroutput">
  409. tickTime=2000
  410. dataDir=/var/zookeeper/
  411. clientPort=2181
  412. initLimit=5
  413. syncLimit=2
  414. server.1=zoo1:2888:3888
  415. server.2=zoo2:2888:3888
  416. server.3=zoo3:2888:3888</span>
  417. </p>
  418. <p>You can find the meanings of these and other configuration
  419. settings in the section <a href="#sc_configuration">Configuration Parameters</a>. A word
  420. though about a few here:</p>
  421. <p>Every machine that is part of the ZooKeeper ensemble should know
  422. about every other machine in the ensemble. You accomplish this with
  423. 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
  424. server id to each machine by creating a file named
  425. <span class="codefrag filename">myid</span>, one for each server, which resides in
  426. that server's data directory, as specified by the configuration file
  427. parameter <strong>dataDir</strong>. The myid file
  428. consists of a single line containing only the text of that machine's
  429. id. So <span class="codefrag filename">myid</span> of server 1 would contain the text
  430. "1" and nothing else. The id must be unique within the
  431. ensemble and should have a value between 1 and 255.</p>
  432. </li>
  433. <li>
  434. <p>If your configuration file is set up, you can start a
  435. ZooKeeper server:</p>
  436. <p>
  437. <span class="codefrag computeroutput">$ java -cp zookeeper.jar:lib/log4j-1.2.15.jar:conf \
  438. org.apache.zookeeper.server.quorum.QuorumPeerMain zoo.cfg
  439. </span>
  440. </p>
  441. <p>QuorumPeerMain starts a ZooKeeper server,
  442. <a href="http://java.sun.com/javase/technologies/core/mntr-mgmt/javamanagement/">JMX</a>
  443. management beans are also registered which allows
  444. management through a JMX management console.
  445. The <a href="zookeeperJMX.html">ZooKeeper JMX
  446. document</a> contains details on managing ZooKeeper with JMX.
  447. </p>
  448. <p>See the script <em>bin/zkServer.sh</em>,
  449. which is included in the release, for an example
  450. of starting server instances.</p>
  451. </li>
  452. <li>
  453. <p>Test your deployment by connecting to the hosts:</p>
  454. <ul>
  455. <li>
  456. <p>In Java, you can run the following command to execute
  457. simple operations:</p>
  458. <p>
  459. <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 \
  460. org.apache.zookeeper.ZooKeeperMain -server 127.0.0.1:2181</span>
  461. </p>
  462. </li>
  463. <li>
  464. <p>In C, you can compile either the single threaded client or
  465. the multithreaded client: or n the c subdirectory in the
  466. ZooKeeper sources. This compiles the single threaded
  467. client:</p>
  468. <p>
  469. <span class="codefrag computeroutput">$ make cli_st</span>
  470. </p>
  471. <p>And this compiles the mulithreaded client:</p>
  472. <p>
  473. <span class="codefrag computeroutput">$ make cli_mt</span>
  474. </p>
  475. </li>
  476. </ul>
  477. <p>Running either program gives you a shell in which to execute
  478. simple file-system-like operations. To connect to ZooKeeper with the
  479. multithreaded client, for example, you would run:</p>
  480. <p>
  481. <span class="codefrag computeroutput">$ cli_mt 127.0.0.1:2181</span>
  482. </p>
  483. </li>
  484. </ol>
  485. <a name="N10119"></a><a name="sc_singleAndDevSetup"></a>
  486. <h3 class="h4">Single Server and Developer Setup</h3>
  487. <p>If you want to setup ZooKeeper for development purposes, you will
  488. probably want to setup a single server instance of ZooKeeper, and then
  489. install either the Java or C client-side libraries and bindings on your
  490. development machine.</p>
  491. <p>The steps to setting up a single server instance are the similar
  492. to the above, except the configuration file is simpler. You can find the
  493. complete instructions in the <a href="zookeeperStarted.html#sc_InstallingSingleMode">Installing and
  494. Running ZooKeeper in Single Server Mode</a> section of the <a href="zookeeperStarted.html">ZooKeeper Getting Started
  495. Guide</a>.</p>
  496. <p>For information on installing the client side libraries, refer to
  497. the <a href="zookeeperProgrammers.html#Bindings">Bindings</a>
  498. section of the <a href="zookeeperProgrammers.html">ZooKeeper
  499. Programmer's Guide</a>.</p>
  500. </div>
  501. <a name="N1013A"></a><a name="ch_administration"></a>
  502. <h2 class="h3">Administration</h2>
  503. <div class="section">
  504. <p>This section contains information about running and maintaining
  505. ZooKeeper and covers these topics: </p>
  506. <ul>
  507. <li>
  508. <p>
  509. <a href="#sc_designing">Designing a ZooKeeper Deployment</a>
  510. </p>
  511. </li>
  512. <li>
  513. <p>
  514. <a href="#sc_provisioning">Provisioning</a>
  515. </p>
  516. </li>
  517. <li>
  518. <p>
  519. <a href="#sc_strengthsAndLimitations">Things to Consider: ZooKeeper Strengths and Limitations</a>
  520. </p>
  521. </li>
  522. <li>
  523. <p>
  524. <a href="#sc_administering">Administering</a>
  525. </p>
  526. </li>
  527. <li>
  528. <p>
  529. <a href="#sc_maintenance">Maintenance</a>
  530. </p>
  531. </li>
  532. <li>
  533. <p>
  534. <a href="#sc_monitoring">Monitoring</a>
  535. </p>
  536. </li>
  537. <li>
  538. <p>
  539. <a href="#sc_logging">Logging</a>
  540. </p>
  541. </li>
  542. <li>
  543. <p>
  544. <a href="#sc_troubleshooting">Troubleshooting</a>
  545. </p>
  546. </li>
  547. <li>
  548. <p>
  549. <a href="#sc_configuration">Configuration Parameters</a>
  550. </p>
  551. </li>
  552. <li>
  553. <p>
  554. <a href="#sc_zkCommands">ZooKeeper Commands: The Four Letter Words</a>
  555. </p>
  556. </li>
  557. <li>
  558. <p>
  559. <a href="#sc_dataFileManagement">Data File Management</a>
  560. </p>
  561. </li>
  562. <li>
  563. <p>
  564. <a href="#sc_commonProblems">Things to Avoid</a>
  565. </p>
  566. </li>
  567. <li>
  568. <p>
  569. <a href="#sc_bestPractices">Best Practices</a>
  570. </p>
  571. </li>
  572. </ul>
  573. <a name="N101AE"></a><a name="sc_designing"></a>
  574. <h3 class="h4">Designing a ZooKeeper Deployment</h3>
  575. <p>The reliablity of ZooKeeper rests on two basic assumptions.</p>
  576. <ol>
  577. <li>
  578. <p> Only a minority of servers in a deployment
  579. will fail. <em>Failure</em> in this context
  580. means a machine crash, or some error in the network that
  581. partitions a server off from the majority.</p>
  582. </li>
  583. <li>
  584. <p> Deployed machines operate correctly. To
  585. operate correctly means to execute code correctly, to have
  586. clocks that work properly, and to have storage and network
  587. components that perform consistently.</p>
  588. </li>
  589. </ol>
  590. <p>The sections below contain considerations for ZooKeeper
  591. administrators to maximize the probability for these assumptions
  592. to hold true. Some of these are cross-machines considerations,
  593. and others are things you should consider for each and every
  594. machine in your deployment.</p>
  595. <a name="N101CA"></a><a name="sc_CrossMachineRequirements"></a>
  596. <h4>Cross Machine Requirements</h4>
  597. <p>For the ZooKeeper service to be active, there must be a
  598. majority of non-failing machines that can communicate with
  599. each other. To create a deployment that can tolerate the
  600. failure of F machines, you should count on deploying 2xF+1
  601. machines. Thus, a deployment that consists of three machines
  602. can handle one failure, and a deployment of five machines can
  603. handle two failures. Note that a deployment of six machines
  604. can only handle two failures since three machines is not a
  605. majority. For this reason, ZooKeeper deployments are usually
  606. made up of an odd number of machines.</p>
  607. <p>To achieve the highest probability of tolerating a failure
  608. you should try to make machine failures independent. For
  609. example, if most of the machines share the same switch,
  610. failure of that switch could cause a correlated failure and
  611. bring down the service. The same holds true of shared power
  612. circuits, cooling systems, etc.</p>
  613. <a name="N101D7"></a><a name="Single+Machine+Requirements"></a>
  614. <h4>Single Machine Requirements</h4>
  615. <p>If ZooKeeper has to contend with other applications for
  616. access to resourses like storage media, CPU, network, or
  617. memory, its performance will suffer markedly. ZooKeeper has
  618. strong durability guarantees, which means it uses storage
  619. media to log changes before the operation responsible for the
  620. change is allowed to complete. You should be aware of this
  621. dependency then, and take great care if you want to ensure
  622. that ZooKeeper operations aren&rsquo;t held up by your media. Here
  623. are some things you can do to minimize that sort of
  624. degradation:
  625. </p>
  626. <ul>
  627. <li>
  628. <p>ZooKeeper's transaction log must be on a dedicated
  629. device. (A dedicated partition is not enough.) ZooKeeper
  630. writes the log sequentially, without seeking Sharing your
  631. log device with other processes can cause seeks and
  632. contention, which in turn can cause multi-second
  633. delays.</p>
  634. </li>
  635. <li>
  636. <p>Do not put ZooKeeper in a situation that can cause a
  637. swap. In order for ZooKeeper to function with any sort of
  638. timeliness, it simply cannot be allowed to swap.
  639. Therefore, make certain that the maximum heap size given
  640. to ZooKeeper is not bigger than the amount of real memory
  641. available to ZooKeeper. For more on this, see
  642. <a href="#sc_commonProblems">Things to Avoid</a>
  643. below. </p>
  644. </li>
  645. </ul>
  646. <a name="N101F5"></a><a name="sc_provisioning"></a>
  647. <h3 class="h4">Provisioning</h3>
  648. <p></p>
  649. <a name="N101FE"></a><a name="sc_strengthsAndLimitations"></a>
  650. <h3 class="h4">Things to Consider: ZooKeeper Strengths and Limitations</h3>
  651. <p></p>
  652. <a name="N10207"></a><a name="sc_administering"></a>
  653. <h3 class="h4">Administering</h3>
  654. <p></p>
  655. <a name="N10210"></a><a name="sc_maintenance"></a>
  656. <h3 class="h4">Maintenance</h3>
  657. <p>Little long term maintenance is required for a ZooKeeper
  658. cluster however you must be aware of the following:</p>
  659. <a name="N10219"></a><a name="Ongoing+Data+Directory+Cleanup"></a>
  660. <h4>Ongoing Data Directory Cleanup</h4>
  661. <p>The ZooKeeper <a href="#var_datadir">Data
  662. Directory</a> contains files which are a persistent copy
  663. of the znodes stored by a particular serving ensemble. These
  664. are the snapshot and transactional log files. As changes are
  665. made to the znodes these changes are appended to a
  666. transaction log, occasionally, when a log grows large, a
  667. snapshot of the current state of all znodes will be written
  668. to the filesystem. This snapshot supercedes all previous
  669. logs.
  670. </p>
  671. <p>A ZooKeeper server <strong>will not remove
  672. old snapshots and log files</strong>, this is the
  673. responsibility of the operator. Every serving environment is
  674. different and therefore the requirements of managing these
  675. files may differ from install to install (backup for example).
  676. </p>
  677. <p>The PurgeTxnLog utility implements a simple retention
  678. policy that administrators can use. The <a href="api/index.html">API docs</a> contains details on
  679. calling conventions (arguments, etc...).
  680. </p>
  681. <p>In the following example the last count snapshots and
  682. their corresponding logs are retained and the others are
  683. deleted. The value of &lt;count&gt; should typically be
  684. greater than 3 (although not required, this provides 3 backups
  685. in the unlikely event a recent log has become corrupted). This
  686. can be run as a cron job on the ZooKeeper server machines to
  687. clean up the logs daily.</p>
  688. <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>
  689. <a name="N1023A"></a><a name="Debug+Log+Cleanup+%28log4j%29"></a>
  690. <h4>Debug Log Cleanup (log4j)</h4>
  691. <p>See the section on <a href="#sc_logging">logging</a> in this document. It is
  692. expected that you will setup a rolling file appender using the
  693. in-built log4j feature. The sample configuration file in the
  694. release tar's conf/log4j.properties provides an example of
  695. this.
  696. </p>
  697. <a name="N10249"></a><a name="sc_monitoring"></a>
  698. <h3 class="h4">Monitoring</h3>
  699. <p></p>
  700. <a name="N10252"></a><a name="sc_logging"></a>
  701. <h3 class="h4">Logging</h3>
  702. <p>ZooKeeper uses <strong>log4j</strong> version 1.2 as
  703. its logging infrastructure. The ZooKeeper default <span class="codefrag filename">log4j.properties</span>
  704. file resides in the <span class="codefrag filename">conf</span> directory. Log4j requires that
  705. <span class="codefrag filename">log4j.properties</span> either be in the working directory
  706. (the directory from which ZooKeeper is run) or be accessible from the classpath.</p>
  707. <p>For more information, see
  708. <a href="http://logging.apache.org/log4j/1.2/manual.html#defaultInit">Log4j Default Initialization Procedure</a>
  709. of the log4j manual.</p>
  710. <a name="N10272"></a><a name="sc_troubleshooting"></a>
  711. <h3 class="h4">Troubleshooting</h3>
  712. <p></p>
  713. <a name="N1027B"></a><a name="sc_configuration"></a>
  714. <h3 class="h4">Configuration Parameters</h3>
  715. <p>ZooKeeper's behavior is governed by the ZooKeeper configuration
  716. file. This file is designed so that the exact same file can be used by
  717. all the servers that make up a ZooKeeper server assuming the disk
  718. layouts are the same. If servers use different configuration files, care
  719. must be taken to ensure that the list of servers in all of the different
  720. configuration files match.</p>
  721. <a name="N10284"></a><a name="sc_minimumConfiguration"></a>
  722. <h4>Minimum Configuration</h4>
  723. <p>Here are the minimum configuration keywords that must be defined
  724. in the configuration file:</p>
  725. <dl>
  726. <dt>
  727. <term>clientPort</term>
  728. </dt>
  729. <dd>
  730. <p>the port to listen for client connections; that is, the
  731. port that clients attempt to connect to.</p>
  732. </dd>
  733. <dt>
  734. <term>dataDir</term>
  735. </dt>
  736. <dd>
  737. <p>the location where ZooKeeper will store the in-memory
  738. database snapshots and, unless specified otherwise, the
  739. transaction log of updates to the database.</p>
  740. <div class="note">
  741. <div class="label">Note</div>
  742. <div class="content">
  743. <p>Be careful where you put the transaction log. A
  744. dedicated transaction log device is key to consistent good
  745. performance. Putting the log on a busy device will adversely
  746. effect performance.</p>
  747. </div>
  748. </div>
  749. </dd>
  750. <dt>
  751. <term>tickTime</term>
  752. </dt>
  753. <dd>
  754. <p>the length of a single tick, which is the basic time unit
  755. used by ZooKeeper, as measured in milliseconds. It is used to
  756. regulate heartbeats, and timeouts. For example, the minimum
  757. session timeout will be two ticks.</p>
  758. </dd>
  759. </dl>
  760. <a name="N102AB"></a><a name="sc_advancedConfiguration"></a>
  761. <h4>Advanced Configuration</h4>
  762. <p>The configuration settings in the section are optional. You can
  763. use them to further fine tune the behaviour of your ZooKeeper servers.
  764. Some can also be set using Java system properties, generally of the
  765. form <em>zookeeper.keyword</em>. The exact system
  766. property, when available, is noted below.</p>
  767. <dl>
  768. <dt>
  769. <term>dataLogDir</term>
  770. </dt>
  771. <dd>
  772. <p>(No Java system property)</p>
  773. <p>This option will direct the machine to write the
  774. transaction log to the <strong>dataLogDir</strong> rather than the <strong>dataDir</strong>. This allows a dedicated log
  775. device to be used, and helps avoid competition between logging
  776. and snaphots.</p>
  777. <div class="note">
  778. <div class="label">Note</div>
  779. <div class="content">
  780. <p>Having a dedicated log device has a large impact on
  781. throughput and stable latencies. It is highly recommened to
  782. dedicate a log device and set <strong>dataLogDir</strong> to point to a directory on
  783. that device, and then make sure to point <strong>dataDir</strong> to a directory
  784. <em>not</em> residing on that device.</p>
  785. </div>
  786. </div>
  787. </dd>
  788. <dt>
  789. <term>globalOutstandingLimit</term>
  790. </dt>
  791. <dd>
  792. <p>(Java system property: <strong>zookeeper.globalOutstandingLimit.</strong>)</p>
  793. <p>Clients can submit requests faster than ZooKeeper can
  794. process them, especially if there are a lot of clients. To
  795. prevent ZooKeeper from running out of memory due to queued
  796. requests, ZooKeeper will throttle clients so that there is no
  797. more than globalOutstandingLimit outstanding requests in the
  798. system. The default limit is 1,000.</p>
  799. </dd>
  800. <dt>
  801. <term>preAllocSize</term>
  802. </dt>
  803. <dd>
  804. <p>(Java system property: <strong>zookeeper.preAllocSize</strong>)</p>
  805. <p>To avoid seeks ZooKeeper allocates space in the
  806. transaction log file in blocks of preAllocSize kilobytes. The
  807. default block size is 64M. One reason for changing the size of
  808. the blocks is to reduce the block size if snapshots are taken
  809. more often. (Also, see <strong>snapCount</strong>).</p>
  810. </dd>
  811. <dt>
  812. <term>snapCount</term>
  813. </dt>
  814. <dd>
  815. <p>(Java system property: <strong>zookeeper.snapCount</strong>)</p>
  816. <p>Clients can submit requests faster than ZooKeeper can
  817. process them, especially if there are a lot of clients. To
  818. prevent ZooKeeper from running out of memory due to queued
  819. requests, ZooKeeper will throttle clients so that there is no
  820. more than globalOutstandingLimit outstanding requests in the
  821. system. The default limit is 1,000.ZooKeeper logs transactions
  822. to a transaction log. After snapCount transactions are written
  823. to a log file a snapshot is started and a new transaction log
  824. file is started. The default snapCount is 10,000.</p>
  825. </dd>
  826. <dt>
  827. <term>traceFile</term>
  828. </dt>
  829. <dd>
  830. <p>(Java system property: <strong>requestTraceFile</strong>)</p>
  831. <p>If this option is defined, requests will be will logged to
  832. a trace file named traceFile.year.month.day. Use of this option
  833. provides useful debugging information, but will impact
  834. performance. (Note: The system property has no zookeeper prefix,
  835. and the configuration variable name is different from the system
  836. property. Yes - it's not consistent, and it's annoying.)</p>
  837. </dd>
  838. <dt>
  839. <term>maxClientCnxns</term>
  840. </dt>
  841. <dd>
  842. <p>(No Java system property)</p>
  843. <p>Limits the number of concurrent connections (at the socket
  844. level) that a single client, identified by IP address, may make
  845. to a single member of the ZooKeeper ensemble. This is used to
  846. prevent certain classes of DoS attacks, including file
  847. descriptor exhaustion. Setting this to 0 or omitting it entirely
  848. removes the limit on concurrent connections.</p>
  849. </dd>
  850. </dl>
  851. <a name="N10314"></a><a name="sc_clusterOptions"></a>
  852. <h4>Cluster Options</h4>
  853. <p>The options in this section are designed for use with an ensemble
  854. of servers -- that is, when deploying clusters of servers.</p>
  855. <dl>
  856. <dt>
  857. <term>electionAlg</term>
  858. </dt>
  859. <dd>
  860. <p>(No Java system property)</p>
  861. <p>Election implementation to use. A value of "0" corresponds
  862. to the original UDP-based version, "1" corresponds to the
  863. non-authenticated UDP-based version of fast leader election, "2"
  864. corresponds to the authenticated UDP-based version of fast
  865. leader election, and "3" corresponds to TCP-based version of
  866. fast leader election. Currently, only 0 and 3 are supported, 3
  867. being the default</p>
  868. </dd>
  869. <dt>
  870. <term>initLimit</term>
  871. </dt>
  872. <dd>
  873. <p>(No Java system property)</p>
  874. <p>Amount of time, in ticks (see <a href="#id_tickTime">tickTime</a>), to allow followers to
  875. connect and sync to a leader. Increased this value as needed, if
  876. the amount of data managed by ZooKeeper is large.</p>
  877. </dd>
  878. <dt>
  879. <term>leaderServes</term>
  880. </dt>
  881. <dd>
  882. <p>(Java system property: zookeeper.<strong>leaderServes</strong>)</p>
  883. <p>Leader accepts client connections. Default value is "yes".
  884. The leader machine coordinates updates. For higher update
  885. throughput at thes slight expense of read throughput the leader
  886. can be configured to not accept clients and focus on
  887. coordination. The default to this option is yes, which means
  888. that a leader will accept client connections.</p>
  889. <div class="note">
  890. <div class="label">Note</div>
  891. <div class="content">
  892. <p>Turning on leader selection is highly recommended when
  893. you have more than three ZooKeeper servers in an ensemble.</p>
  894. </div>
  895. </div>
  896. </dd>
  897. <dt>
  898. <term>server.x=[hostname]:nnnnn[:nnnnn], etc</term>
  899. </dt>
  900. <dd>
  901. <p>(No Java system property)</p>
  902. <p>servers making up the ZooKeeper ensemble. When the server
  903. starts up, it determines which server it is by looking for the
  904. file <span class="codefrag filename">myid</span> in the data directory. That file
  905. contains the server number, in ASCII, and it should match
  906. <strong>x</strong> in <strong>server.x</strong> in the left hand side of this
  907. setting.</p>
  908. <p>The list of servers that make up ZooKeeper servers that is
  909. used by the clients must match the list of ZooKeeper servers
  910. that each ZooKeeper server has.</p>
  911. <p>There are two port numbers <strong>nnnnn</strong>.
  912. The first followers use to connect to the leader, and the second is for
  913. leader election. The leader election port is only necessary if electionAlg
  914. is 1, 2, or 3 (default). If electionAlg is 0, then the second port is not
  915. necessary. If you want to test multiple servers on a single machine, then
  916. different ports can be used for each server.</p>
  917. </dd>
  918. <dt>
  919. <term>syncLimit</term>
  920. </dt>
  921. <dd>
  922. <p>(No Java system property)</p>
  923. <p>Amount of time, in ticks (see <a href="#id_tickTime">tickTime</a>), to allow followers to sync
  924. with ZooKeeper. If followers fall too far behind a leader, they
  925. will be dropped.</p>
  926. </dd>
  927. <dt>
  928. <term>group.x=nnnnn[:nnnnn]</term>
  929. </dt>
  930. <dd>
  931. <p>(No Java system property)</p>
  932. <p>Enables a hierarchical quorum construction."x" is a group identifier
  933. and the numbers following the "=" sign correspond to server identifiers.
  934. The left-hand side of the assignment is a colon-separated list of server
  935. identifiers. Note that groups must be disjoint and the union of all groups
  936. must be the ZooKeeper ensemble. </p>
  937. </dd>
  938. <dt>
  939. <term>weight.x=nnnnn</term>
  940. </dt>
  941. <dd>
  942. <p>(No Java system property)</p>
  943. <p>Used along with "group", it assigns a weight to a server when
  944. forming quorums. Such a value corresponds to the weight of a server
  945. when voting. There are a few parts of ZooKeeper that require voting
  946. such as leader election and the atomic broadcast protocol. By default
  947. the weight of server is 1. If the configuration defines groups, but not
  948. weights, then a value of 1 will be assigned to all servers.
  949. </p>
  950. </dd>
  951. </dl>
  952. <p></p>
  953. <a name="N10383"></a><a name="sc_authOptions"></a>
  954. <h4>Authentication &amp; Authorization Options</h4>
  955. <p>The options in this section allow control over
  956. authentication/authorization performed by the service.</p>
  957. <dl>
  958. <dt>
  959. <term>zookeeper.DigestAuthenticationProvider.superDigest</term>
  960. </dt>
  961. <dd>
  962. <p>(Java system property only: <strong>zookeeper.DigestAuthenticationProvider.superDigest</strong>)</p>
  963. <p>By default this feature is <strong>disabled</strong>
  964. </p>
  965. <p>
  966. <strong>New in 3.2:</strong>
  967. Enables a ZooKeeper ensemble administrator to access the
  968. znode hierarchy as a "super" user. In particular no ACL
  969. checking occurs for a user authenticated as
  970. super.</p>
  971. <p>org.apache.zookeeper.server.auth.DigestAuthenticationProvider
  972. can be used to generate the superDigest, call it with
  973. one parameter of "super:&lt;password&gt;". Provide the
  974. generated "super:&lt;data&gt;" as the system property value
  975. when starting each server of the ensemble.</p>
  976. <p>When authenticating to a ZooKeeper server (from a
  977. ZooKeeper client) pass a scheme of "digest" and authdata
  978. of "super:&lt;password&gt;". Note that digest auth passes
  979. the authdata in plaintext to the server, it would be
  980. prudent to use this authentication method only on
  981. localhost (not over the network) or over an encrypted
  982. connection.</p>
  983. </dd>
  984. </dl>
  985. <a name="N103A6"></a><a name="Unsafe+Options"></a>
  986. <h4>Unsafe Options</h4>
  987. <p>The following options can be useful, but be careful when you use
  988. them. The risk of each is explained along with the explanation of what
  989. the variable does.</p>
  990. <dl>
  991. <dt>
  992. <term>forceSync</term>
  993. </dt>
  994. <dd>
  995. <p>(Java system property: <strong>zookeeper.forceSync</strong>)</p>
  996. <p>Requires updates to be synced to media of the transaction
  997. log before finishing processing the update. If this option is
  998. set to no, ZooKeeper will not require updates to be synced to
  999. the media.</p>
  1000. </dd>
  1001. <dt>
  1002. <term>jute.maxbuffer:</term>
  1003. </dt>
  1004. <dd>
  1005. <p>(Java system property:<strong>
  1006. jute.maxbuffer</strong>)</p>
  1007. <p>This option can only be set as a Java system property.
  1008. There is no zookeeper prefix on it. It specifies the maximum
  1009. size of the data that can be stored in a znode. The default is
  1010. 0xfffff, or just under 1M. If this option is changed, the system
  1011. property must be set on all servers and clients otherwise
  1012. problems will arise. This is really a sanity check. ZooKeeper is
  1013. designed to store data on the order of kilobytes in size.</p>
  1014. </dd>
  1015. <dt>
  1016. <term>skipACL</term>
  1017. </dt>
  1018. <dd>
  1019. <p>(Java system property: <strong>zookeeper.skipACL</strong>)</p>
  1020. <p>Skips ACL checks. This results in a boost in throughput,
  1021. but opens up full access to the data tree to everyone.</p>
  1022. </dd>
  1023. </dl>
  1024. <a name="N103D8"></a><a name="sc_zkCommands"></a>
  1025. <h3 class="h4">ZooKeeper Commands: The Four Letter Words</h3>
  1026. <p>ZooKeeper responds to a small set of commands. Each command is
  1027. composed of four letters. You issue the commands to ZooKeeper via telnet
  1028. or nc, at the client port.</p>
  1029. <dl>
  1030. <dt>
  1031. <term>dump</term>
  1032. </dt>
  1033. <dd>
  1034. <p>Lists the outstanding sessions and ephemeral nodes. This
  1035. only works on the leader.</p>
  1036. </dd>
  1037. <dt>
  1038. <term>envi</term>
  1039. </dt>
  1040. <dd>
  1041. <p>Print details about serving environment</p>
  1042. </dd>
  1043. <dt>
  1044. <term>reqs</term>
  1045. </dt>
  1046. <dd>
  1047. <p>List outstanding requests</p>
  1048. </dd>
  1049. <dt>
  1050. <term>ruok</term>
  1051. </dt>
  1052. <dd>
  1053. <p>Tests if server is running in a non-error state. The server
  1054. will respond with imok if it is running. Otherwise it will not
  1055. respond at all.</p>
  1056. </dd>
  1057. <dt>
  1058. <term>srst</term>
  1059. </dt>
  1060. <dd>
  1061. <p>Reset statistics returned by stat command.</p>
  1062. </dd>
  1063. <dt>
  1064. <term>stat</term>
  1065. </dt>
  1066. <dd>
  1067. <p>Lists statistics about performance and connected
  1068. clients.</p>
  1069. </dd>
  1070. </dl>
  1071. <p>Here's an example of the <strong>ruok</strong>
  1072. command:</p>
  1073. <pre class="code">$ echo ruok | nc 127.0.0.1 5111
  1074. imok
  1075. </pre>
  1076. <a name="N10418"></a><a name="sc_dataFileManagement"></a>
  1077. <h3 class="h4">Data File Management</h3>
  1078. <p>ZooKeeper stores its data in a data directory and its transaction
  1079. log in a transaction log directory. By default these two directories are
  1080. the same. The server can (and should) be configured to store the
  1081. transaction log files in a separate directory than the data files.
  1082. Throughput increases and latency decreases when transaction logs reside
  1083. on a dedicated log devices.</p>
  1084. <a name="N10421"></a><a name="The+Data+Directory"></a>
  1085. <h4>The Data Directory</h4>
  1086. <p>This directory has two files in it:</p>
  1087. <ul>
  1088. <li>
  1089. <p>
  1090. <span class="codefrag filename">myid</span> - contains a single integer in
  1091. human readable ASCII text that represents the server id.</p>
  1092. </li>
  1093. <li>
  1094. <p>
  1095. <span class="codefrag filename">snapshot.&lt;zxid&gt;</span> - holds the fuzzy
  1096. snapshot of a data tree.</p>
  1097. </li>
  1098. </ul>
  1099. <p>Each ZooKeeper server has a unique id. This id is used in two
  1100. places: the <span class="codefrag filename">myid</span> file and the configuration file.
  1101. The <span class="codefrag filename">myid</span> file identifies the server that
  1102. corresponds to the given data directory. The configuration file lists
  1103. the contact information for each server identified by its server id.
  1104. When a ZooKeeper server instance starts, it reads its id from the
  1105. <span class="codefrag filename">myid</span> file and then, using that id, reads from the
  1106. configuration file, looking up the port on which it should
  1107. listen.</p>
  1108. <p>The <span class="codefrag filename">snapshot</span> files stored in the data
  1109. directory are fuzzy snapshots in the sense that during the time the
  1110. ZooKeeper server is taking the snapshot, updates are occurring to the
  1111. data tree. The suffix of the <span class="codefrag filename">snapshot</span> file names
  1112. is the <em>zxid</em>, the ZooKeeper transaction id, of the
  1113. last committed transaction at the start of the snapshot. Thus, the
  1114. snapshot includes a subset of the updates to the data tree that
  1115. occurred while the snapshot was in process. The snapshot, then, may
  1116. not correspond to any data tree that actually existed, and for this
  1117. reason we refer to it as a fuzzy snapshot. Still, ZooKeeper can
  1118. recover using this snapshot because it takes advantage of the
  1119. idempotent nature of its updates. By replaying the transaction log
  1120. against fuzzy snapshots ZooKeeper gets the state of the system at the
  1121. end of the log.</p>
  1122. <a name="N1045D"></a><a name="The+Log+Directory"></a>
  1123. <h4>The Log Directory</h4>
  1124. <p>The Log Directory contains the ZooKeeper transaction logs.
  1125. Before any update takes place, ZooKeeper ensures that the transaction
  1126. that represents the update is written to non-volatile storage. A new
  1127. log file is started each time a snapshot is begun. The log file's
  1128. suffix is the first zxid written to that log.</p>
  1129. <a name="N10467"></a><a name="sc_filemanagement"></a>
  1130. <h4>File Management</h4>
  1131. <p>The format of snapshot and log files does not change between
  1132. standalone ZooKeeper servers and different configurations of
  1133. replicated ZooKeeper servers. Therefore, you can pull these files from
  1134. a running replicated ZooKeeper server to a development machine with a
  1135. stand-alone ZooKeeper server for trouble shooting.</p>
  1136. <p>Using older log and snapshot files, you can look at the previous
  1137. state of ZooKeeper servers and even restore that state. The
  1138. LogFormatter class allows an administrator to look at the transactions
  1139. in a log.</p>
  1140. <p>The ZooKeeper server creates snapshot and log files, but
  1141. never deletes them. The retention policy of the data and log
  1142. files is implemented outside of the ZooKeeper server. The
  1143. server itself only needs the latest complete fuzzy snapshot
  1144. and the log files from the start of that snapshot. See the
  1145. <a href="#sc_maintenance">maintenance</a> section in
  1146. this document for more details on setting a retention policy
  1147. and maintenance of ZooKeeper storage.
  1148. </p>
  1149. <a name="N1047C"></a><a name="sc_commonProblems"></a>
  1150. <h3 class="h4">Things to Avoid</h3>
  1151. <p>Here are some common problems you can avoid by configuring
  1152. ZooKeeper correctly:</p>
  1153. <dl>
  1154. <dt>
  1155. <term>inconsistent lists of servers</term>
  1156. </dt>
  1157. <dd>
  1158. <p>The list of ZooKeeper servers used by the clients must match
  1159. the list of ZooKeeper servers that each ZooKeeper server has.
  1160. Things work okay if the client list is a subset of the real list,
  1161. but things will really act strange if clients have a list of
  1162. ZooKeeper servers that are in different ZooKeeper clusters. Also,
  1163. the server lists in each Zookeeper server configuration file
  1164. should be consistent with one another.</p>
  1165. </dd>
  1166. <dt>
  1167. <term>incorrect placement of transasction log</term>
  1168. </dt>
  1169. <dd>
  1170. <p>The most performance critical part of ZooKeeper is the
  1171. transaction log. ZooKeeper syncs transactions to media before it
  1172. returns a response. A dedicated transaction log device is key to
  1173. consistent good performance. Putting the log on a busy device will
  1174. adversely effect performance. If you only have one storage device,
  1175. put trace files on NFS and increase the snapshotCount; it doesn't
  1176. eliminate the problem, but it should mitigate it.</p>
  1177. </dd>
  1178. <dt>
  1179. <term>incorrect Java heap size</term>
  1180. </dt>
  1181. <dd>
  1182. <p>You should take special care to set your Java max heap size
  1183. correctly. In particular, you should not create a situation in
  1184. which ZooKeeper swaps to disk. The disk is death to ZooKeeper.
  1185. Everything is ordered, so if processing one request swaps the
  1186. disk, all other queued requests will probably do the same. the
  1187. disk. DON'T SWAP.</p>
  1188. <p>Be conservative in your estimates: if you have 4G of RAM, do
  1189. not set the Java max heap size to 6G or even 4G. For example, it
  1190. is more likely you would use a 3G heap for a 4G machine, as the
  1191. operating system and the cache also need memory. The best and only
  1192. recommend practice for estimating the heap size your system needs
  1193. is to run load tests, and then make sure you are well below the
  1194. usage limit that would cause the system to swap.</p>
  1195. </dd>
  1196. </dl>
  1197. <a name="N104A0"></a><a name="sc_bestPractices"></a>
  1198. <h3 class="h4">Best Practices</h3>
  1199. <p>For best results, take note of the following list of good
  1200. Zookeeper practices. <em>[tbd...]</em>
  1201. </p>
  1202. </div>
  1203. <p align="right">
  1204. <font size="-2"></font>
  1205. </p>
  1206. </div>
  1207. <!--+
  1208. |end content
  1209. +-->
  1210. <div class="clearboth">&nbsp;</div>
  1211. </div>
  1212. <div id="footer">
  1213. <!--+
  1214. |start bottomstrip
  1215. +-->
  1216. <div class="lastmodified">
  1217. <script type="text/javascript"><!--
  1218. document.write("Last Published: " + document.lastModified);
  1219. // --></script>
  1220. </div>
  1221. <div class="copyright">
  1222. Copyright &copy;
  1223. 2008 <a href="http://www.apache.org/licenses/">The Apache Software Foundation.</a>
  1224. </div>
  1225. <!--+
  1226. |end bottomstrip
  1227. +-->
  1228. </div>
  1229. </body>
  1230. </html>