zookeeperAdmin.html 58 KB

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