zookeeperAdmin.html 45 KB

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