zookeeperAdmin.html 41 KB

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