zookeeperAdmin.html 45 KB

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