zookeeperAdmin.html 49 KB

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