zookeeperAdmin.html 58 KB

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