zookeeperAdmin.html 40 KB

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