zookeeperAdmin.html 50 KB

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