zookeeperAdmin.html 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <meta content="Apache Forrest" name="Generator">
  6. <meta name="Forrest-version" content="0.8">
  7. <meta name="Forrest-skin-name" content="pelt">
  8. <title>ZooKeeper Administrator's Guide</title>
  9. <link type="text/css" href="skin/basic.css" rel="stylesheet">
  10. <link media="screen" type="text/css" href="skin/screen.css" rel="stylesheet">
  11. <link media="print" type="text/css" href="skin/print.css" rel="stylesheet">
  12. <link type="text/css" href="skin/profile.css" rel="stylesheet">
  13. <script src="skin/getBlank.js" language="javascript" type="text/javascript"></script><script src="skin/getMenu.js" language="javascript" type="text/javascript"></script><script src="skin/fontsize.js" language="javascript" type="text/javascript"></script>
  14. <link rel="shortcut icon" href="images/favicon.ico">
  15. </head>
  16. <body onload="init()">
  17. <script type="text/javascript">ndeSetTextSize();</script>
  18. <div id="top">
  19. <!--+
  20. |breadtrail
  21. +-->
  22. <div class="breadtrail">
  23. <a href="http://www.apache.org/">Apache</a> &gt; <a href="http://hadoop.apache.org/">Hadoop</a> &gt; <a href="http://hadoop.apache.org/zookeeper/">ZooKeeper</a><script src="skin/breadcrumbs.js" language="JavaScript" type="text/javascript"></script>
  24. </div>
  25. <!--+
  26. |header
  27. +-->
  28. <div class="header">
  29. <!--+
  30. |start group logo
  31. +-->
  32. <div class="grouplogo">
  33. <a href="http://hadoop.apache.org/"><img class="logoImage" alt="Hadoop" src="images/hadoop-logo.jpg" title="Apache Hadoop"></a>
  34. </div>
  35. <!--+
  36. |end group logo
  37. +-->
  38. <!--+
  39. |start Project Logo
  40. +-->
  41. <div class="projectlogo">
  42. <a href="http://hadoop.apache.org/zookeeper/"><img class="logoImage" alt="ZooKeeper" src="images/zookeeper_small.gif" title="The Hadoop database"></a>
  43. </div>
  44. <!--+
  45. |end Project Logo
  46. +-->
  47. <!--+
  48. |start Search
  49. +-->
  50. <div class="searchbox">
  51. <form action="http://www.google.com/search" method="get" class="roundtopsmall">
  52. <input value="hadoop.apache.org" name="sitesearch" type="hidden"><input onFocus="getBlank (this, 'Search the site with google');" size="25" name="q" id="query" type="text" value="Search the site with google">&nbsp;
  53. <input name="Search" value="Search" type="submit">
  54. </form>
  55. </div>
  56. <!--+
  57. |end search
  58. +-->
  59. <!--+
  60. |start Tabs
  61. +-->
  62. <ul id="tabs">
  63. <li>
  64. <a class="unselected" href="http://hadoop.apache.org/zookeeper/">Project</a>
  65. </li>
  66. <li>
  67. <a class="unselected" href="http://wiki.apache.org/hadoop/ZooKeeper">Wiki</a>
  68. </li>
  69. <li class="current">
  70. <a class="selected" href="index.html">ZooKeeper 3.1 Documentation</a>
  71. </li>
  72. </ul>
  73. <!--+
  74. |end Tabs
  75. +-->
  76. </div>
  77. </div>
  78. <div id="main">
  79. <div id="publishedStrip">
  80. <!--+
  81. |start Subtabs
  82. +-->
  83. <div id="level2tabs"></div>
  84. <!--+
  85. |end Endtabs
  86. +-->
  87. <script type="text/javascript"><!--
  88. document.write("Last Published: " + document.lastModified);
  89. // --></script>
  90. </div>
  91. <!--+
  92. |breadtrail
  93. +-->
  94. <div class="breadtrail">
  95. &nbsp;
  96. </div>
  97. <!--+
  98. |start Menu, mainarea
  99. +-->
  100. <!--+
  101. |start Menu
  102. +-->
  103. <div id="menu">
  104. <div onclick="SwitchMenu('menu_1.1', 'skin/')" id="menu_1.1Title" class="menutitle">Overview</div>
  105. <div id="menu_1.1" class="menuitemgroup">
  106. <div class="menuitem">
  107. <a href="index.html">Welcome</a>
  108. </div>
  109. <div class="menuitem">
  110. <a href="zookeeperOver.html">Overview</a>
  111. </div>
  112. <div class="menuitem">
  113. <a href="zookeeperStarted.html">Getting Started</a>
  114. </div>
  115. <div class="menuitem">
  116. <a href="releasenotes.html">Release Notes</a>
  117. </div>
  118. </div>
  119. <div onclick="SwitchMenu('menu_1.2', 'skin/')" id="menu_1.2Title" class="menutitle">Developer</div>
  120. <div id="menu_1.2" class="menuitemgroup">
  121. <div class="menuitem">
  122. <a href="api/index.html">API Docs</a>
  123. </div>
  124. <div class="menuitem">
  125. <a href="zookeeperProgrammers.html">Programmer's Guide</a>
  126. </div>
  127. <div class="menuitem">
  128. <a href="javaExample.html">Java Example</a>
  129. </div>
  130. <div class="menuitem">
  131. <a href="zookeeperTutorial.html">Barrier and Queue Tutorial</a>
  132. </div>
  133. <div class="menuitem">
  134. <a href="recipes.html">Recipes</a>
  135. </div>
  136. </div>
  137. <div onclick="SwitchMenu('menu_selected_1.3', 'skin/')" id="menu_selected_1.3Title" class="menutitle" style="background-image: url('skin/images/chapter_open.gif');">Admin &amp; Ops</div>
  138. <div id="menu_selected_1.3" class="selectedmenuitemgroup" style="display: block;">
  139. <div class="menupage">
  140. <div class="menupagetitle">Administrator's Guide</div>
  141. </div>
  142. </div>
  143. <div onclick="SwitchMenu('menu_1.4', 'skin/')" id="menu_1.4Title" class="menutitle">Contributor</div>
  144. <div id="menu_1.4" class="menuitemgroup">
  145. <div class="menuitem">
  146. <a href="zookeeperInternals.html">ZooKeeper Internals</a>
  147. </div>
  148. </div>
  149. <div onclick="SwitchMenu('menu_1.5', 'skin/')" id="menu_1.5Title" class="menutitle">Miscellaneous</div>
  150. <div id="menu_1.5" class="menuitemgroup">
  151. <div class="menuitem">
  152. <a href="http://wiki.apache.org/hadoop/ZooKeeper">Wiki</a>
  153. </div>
  154. <div class="menuitem">
  155. <a href="http://wiki.apache.org/hadoop/ZooKeeper/FAQ">FAQ</a>
  156. </div>
  157. <div class="menuitem">
  158. <a href="http://hadoop.apache.org/zookeeper/mailing_lists.html">Mailing Lists</a>
  159. </div>
  160. </div>
  161. <div id="credit"></div>
  162. <div id="roundbottom">
  163. <img style="display: none" class="corner" height="15" width="15" alt="" src="skin/images/rc-b-l-15-1body-2menu-3menu.png"></div>
  164. <!--+
  165. |alternative credits
  166. +-->
  167. <div id="credit2"></div>
  168. </div>
  169. <!--+
  170. |end Menu
  171. +-->
  172. <!--+
  173. |start content
  174. +-->
  175. <div id="content">
  176. <div title="Portable Document Format" class="pdflink">
  177. <a class="dida" href="zookeeperAdmin.pdf"><img alt="PDF -icon" src="skin/images/pdfdoc.gif" class="skin"><br>
  178. PDF</a>
  179. </div>
  180. <h1>ZooKeeper Administrator's Guide</h1>
  181. <h3>A Guide to Deployment and Administration</h3>
  182. <div id="minitoc-area">
  183. <ul class="minitoc">
  184. <li>
  185. <a href="#ch_deployment">Deployment</a>
  186. <ul class="minitoc">
  187. <li>
  188. <a href="#sc_systemReq">System Requirements</a>
  189. </li>
  190. <li>
  191. <a href="#sc_zkMulitServerSetup">Clustered (Multi-Server) Setup</a>
  192. </li>
  193. <li>
  194. <a href="#sc_singleAndDevSetup">Single Server and Developer Setup</a>
  195. </li>
  196. </ul>
  197. </li>
  198. <li>
  199. <a href="#ch_administration">Administration</a>
  200. <ul class="minitoc">
  201. <li>
  202. <a href="#sc_designing">Designing a ZooKeeper Deployment</a>
  203. </li>
  204. <li>
  205. <a href="#sc_provisioning">Provisioning</a>
  206. </li>
  207. <li>
  208. <a href="#sc_strengthsAndLimitations">Things to Consider: ZooKeeper Strengths and Limitations</a>
  209. </li>
  210. <li>
  211. <a href="#sc_administering">Administering</a>
  212. </li>
  213. <li>
  214. <a href="#sc_monitoring">Monitoring</a>
  215. </li>
  216. <li>
  217. <a href="#sc_logging">Logging</a>
  218. </li>
  219. <li>
  220. <a href="#sc_troubleshooting">Troubleshooting</a>
  221. </li>
  222. <li>
  223. <a href="#sc_configuration">Configuration Parameters</a>
  224. <ul class="minitoc">
  225. <li>
  226. <a href="#sc_minimumConfiguration">Minimum Configuration</a>
  227. </li>
  228. <li>
  229. <a href="#sc_advancedConfiguration">Advanced Configuration</a>
  230. </li>
  231. <li>
  232. <a href="#sc_clusterOptions">Cluster Options</a>
  233. </li>
  234. <li>
  235. <a href="#Unsafe+Options">Unsafe Options</a>
  236. </li>
  237. </ul>
  238. </li>
  239. <li>
  240. <a href="#sc_zkCommands">ZooKeeper Commands: The Four Letter Words</a>
  241. </li>
  242. <li>
  243. <a href="#sc_dataFileManagement">Data File Management</a>
  244. <ul class="minitoc">
  245. <li>
  246. <a href="#The+Data+Directory">The Data Directory</a>
  247. </li>
  248. <li>
  249. <a href="#The+Log+Directory">The Log Directory</a>
  250. </li>
  251. <li>
  252. <a href="#File+Management">File Management</a>
  253. </li>
  254. </ul>
  255. </li>
  256. <li>
  257. <a href="#sc_commonProblems">Things to Avoid</a>
  258. </li>
  259. <li>
  260. <a href="#sc_bestPractices">Best Practices</a>
  261. </li>
  262. </ul>
  263. </li>
  264. </ul>
  265. </div>
  266. <a name="N1000B"></a><a name="ch_deployment"></a>
  267. <h2 class="h3">Deployment</h2>
  268. <div class="section">
  269. <p>This section contains information about deploying Zookeeper and
  270. covers these topics:</p>
  271. <ul>
  272. <li>
  273. <p>
  274. <a href="#sc_systemReq">System Requirements</a>
  275. </p>
  276. </li>
  277. <li>
  278. <p>
  279. <a href="#sc_zkMulitServerSetup">Clustered (Multi-Server) Setup</a>
  280. </p>
  281. </li>
  282. <li>
  283. <p>
  284. <a href="#sc_singleAndDevSetup">Single Server and Developer Setup</a>
  285. </p>
  286. </li>
  287. </ul>
  288. <p>The first two sections assume you are interested in installing
  289. ZooKeeper in a production environment such as a datacenter. The final
  290. section covers situations in which you are setting up ZooKeeper on a
  291. limited basis - for evaluation, testing, or development - but not in a
  292. production environment.</p>
  293. <a name="N10032"></a><a name="sc_systemReq"></a>
  294. <h3 class="h4">System Requirements</h3>
  295. <p>ZooKeeper runs in Java, release 1.5 or greater (JDK 5 or greater).
  296. It runs as an <em>ensemble</em> of ZooKeeper servers. Three ZooKeeper
  297. servers is the minimum recommended size for an ensemble, and we also recommend that
  298. they run on separate machines. At Yahoo!, ZooKeeper is usually deployed on
  299. dedicated RHEL boxes, with dual-core processors, 2GB of RAM, and 80GB IDE hard
  300. drives.</p>
  301. <a name="N1003F"></a><a name="sc_zkMulitServerSetup"></a>
  302. <h3 class="h4">Clustered (Multi-Server) Setup</h3>
  303. <p>For reliable ZooKeeper service, you should deploy ZooKeeper in a
  304. cluster known as an <em>ensemble</em>. As long as a majority
  305. of the ensemble are up, the service will be available. Because Zookeeper
  306. requires a majority, it is best to use an
  307. odd number of machines. For example, with four machines ZooKeeper can
  308. only handle the failure of a single machine; if two machines fail, the
  309. remaining two machines do not constitute a majority. However, with five
  310. machines ZooKeeper can handle the failure of two machines. </p>
  311. <p>Here are the steps to setting a server that will be part of an
  312. ensemble. These steps should be performed on every host in the
  313. ensemble:</p>
  314. <ol>
  315. <li>
  316. <p>Install the Java JDK. You can use the native packaging system
  317. for your system, or download the JDK from:</p>
  318. <p>
  319. <a href="http://java.sun.com/javase/downloads/index.jsp">http://java.sun.com/javase/downloads/index.jsp</a>
  320. </p>
  321. </li>
  322. <li>
  323. <p>Set the Java heap size. This is very important to avoid
  324. swapping, which will seriously degrade ZooKeeper performance. To
  325. determine the correct value, use load tests, and make sure you are
  326. well below the usage limit that would cause you to swap. Be
  327. conservative - use a maximum heap size of 3GB for a 4GB
  328. machine.</p>
  329. </li>
  330. <li>
  331. <p>Install the ZooKeeper Server Package. It can be downloaded
  332. from:
  333. </p>
  334. <p>
  335. <a href="http://hadoop.apache.org/zookeeper/releases.html">
  336. http://hadoop.apache.org/zookeeper/releases.html
  337. </a>
  338. </p>
  339. </li>
  340. <li>
  341. <p>Create a configuration file. This file can be called anything.
  342. Use the following settings as a starting point:</p>
  343. <p>
  344. <span class="codefrag computeroutput">
  345. tickTime=2000
  346. dataDir=/var/zookeeper/
  347. clientPort=2181
  348. initLimit=5
  349. syncLimit=2
  350. server.1=zoo1:2888:3888
  351. server.2=zoo2:2888:3888
  352. server.3=zoo3:2888:3888</span>
  353. </p>
  354. <p>You can find the meanings of these and other configuration
  355. settings in the section <a href="#sc_configuration">Configuration Parameters</a>. A word
  356. though about a few here:</p>
  357. <p>Every machine that is part of the ZooKeeper ensemble should know
  358. about every other machine in the ensemble. You accomplish this with
  359. 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
  360. server id to each machine by creating a file named
  361. <span class="codefrag filename">myid</span>, one for each server, which resides in
  362. that server's data directory, as specified by the configuration file
  363. parameter <strong>dataDir</strong>. The myid file
  364. consists of a single line containing only the text of that machine's
  365. id. So <span class="codefrag filename">myid</span> of server 1 would contain the text
  366. "1" and nothing else. The id must be unique within the
  367. ensemble.</p>
  368. </li>
  369. <li>
  370. <p>If your configuration file is set up, you can start
  371. ZooKeeper:</p>
  372. <p>
  373. <span class="codefrag computeroutput">$ java -cp zookeeper.jar:src/java/lib/log4j-1.2.15.jar:conf \
  374. org.apache.zookeeper.server.quorum.QuorumPeerMain zoo.cfg</span>
  375. </p>
  376. </li>
  377. <li>
  378. <p>Test your deployment by connecting to the hosts:</p>
  379. <ul>
  380. <li>
  381. <p>In Java, you can run the following command to execute
  382. simple operations:</p>
  383. <p>
  384. <span class="codefrag computeroutput">$ java -cp zookeeper.jar:src/java/lib/log4j-1.2.15.jar:conf \
  385. org.apache.zookeeper.ZooKeeperMain 127.0.0.1:2181</span>
  386. </p>
  387. </li>
  388. <li>
  389. <p>In C, you can compile either the single threaded client or
  390. the multithreaded client: or n the c subdirectory in the
  391. ZooKeeper sources. This compiles the single threaded
  392. client:</p>
  393. <p>
  394. <span class="codefrag computeroutput">$ make cli_st</span>
  395. </p>
  396. <p>And this compiles the mulithreaded client:</p>
  397. <p>
  398. <span class="codefrag computeroutput">$ make cli_mt</span>
  399. </p>
  400. </li>
  401. </ul>
  402. <p>Running either program gives you a shell in which to execute
  403. simple file-system-like operations. To connect to ZooKeeper with the
  404. multithreaded client, for example, you would run:</p>
  405. <p>
  406. <span class="codefrag computeroutput">$ cli_mt 127.0.0.1:2181</span>
  407. </p>
  408. </li>
  409. </ol>
  410. <a name="N100D3"></a><a name="sc_singleAndDevSetup"></a>
  411. <h3 class="h4">Single Server and Developer Setup</h3>
  412. <p>If you want to setup ZooKeeper for development purposes, you will
  413. probably want to setup a single server instance of ZooKeeper, and then
  414. install either the Java or C client-side libraries and bindings on your
  415. development machine.</p>
  416. <p>The steps to setting up a single server instance are the similar
  417. to the above, except the configuration file is simpler. You can find the
  418. complete instructions in the <a href="zookeeperStarted.html#sc_InstallingSingleMode">Installing and
  419. Running ZooKeeper in Single Server Mode</a> section of the <a href="zookeeperStarted.html">ZooKeeper Getting Started
  420. Guide</a>.</p>
  421. <p>For information on installing the client side libraries, refer to
  422. the <a href="zookeeperProgrammers.html#Bindings">Bindings</a>
  423. section of the <a href="zookeeperProgrammers.html">ZooKeeper
  424. Programmer's Guide</a>.</p>
  425. </div>
  426. <a name="N100F4"></a><a name="ch_administration"></a>
  427. <h2 class="h3">Administration</h2>
  428. <div class="section">
  429. <p>This section contains information about running and maintaining
  430. ZooKeeper and covers these topics: </p>
  431. <ul>
  432. <li>
  433. <p>
  434. <a href="#sc_designing">Designing a ZooKeeper Deployment</a>
  435. </p>
  436. </li>
  437. <li>
  438. <p>
  439. <a href="#sc_provisioning">Provisioning</a>
  440. </p>
  441. </li>
  442. <li>
  443. <p>
  444. <a href="#sc_strengthsAndLimitations">Things to Consider: ZooKeeper Strengths and Limitations</a>
  445. </p>
  446. </li>
  447. <li>
  448. <p>
  449. <a href="#sc_administering">Administering</a>
  450. </p>
  451. </li>
  452. <li>
  453. <p>
  454. <a href="#sc_monitoring">Monitoring</a>
  455. </p>
  456. </li>
  457. <li>
  458. <p>
  459. <a href="#sc_logging">Logging</a>
  460. </p>
  461. </li>
  462. <li>
  463. <p>
  464. <a href="#sc_troubleshooting">Troubleshooting</a>
  465. </p>
  466. </li>
  467. <li>
  468. <p>
  469. <a href="#sc_configuration">Configuration Parameters</a>
  470. </p>
  471. </li>
  472. <li>
  473. <p>
  474. <a href="#sc_zkCommands">ZooKeeper Commands: The Four Letter Words</a>
  475. </p>
  476. </li>
  477. <li>
  478. <p>
  479. <a href="#sc_dataFileManagement">Data File Management</a>
  480. </p>
  481. </li>
  482. <li>
  483. <p>
  484. <a href="#sc_commonProblems">Things to Avoid</a>
  485. </p>
  486. </li>
  487. <li>
  488. <p>
  489. <a href="#sc_bestPractices">Best Practices</a>
  490. </p>
  491. </li>
  492. </ul>
  493. <a name="N10160"></a><a name="sc_designing"></a>
  494. <h3 class="h4">Designing a ZooKeeper Deployment</h3>
  495. <p></p>
  496. <a name="N10169"></a><a name="sc_provisioning"></a>
  497. <h3 class="h4">Provisioning</h3>
  498. <p></p>
  499. <a name="N10172"></a><a name="sc_strengthsAndLimitations"></a>
  500. <h3 class="h4">Things to Consider: ZooKeeper Strengths and Limitations</h3>
  501. <p></p>
  502. <a name="N1017B"></a><a name="sc_administering"></a>
  503. <h3 class="h4">Administering</h3>
  504. <p></p>
  505. <a name="N10184"></a><a name="sc_monitoring"></a>
  506. <h3 class="h4">Monitoring</h3>
  507. <p></p>
  508. <a name="N1018D"></a><a name="sc_logging"></a>
  509. <h3 class="h4">Logging</h3>
  510. <p>ZooKeeper uses <strong>log4j</strong> version 1.2 as
  511. its logging infrastructure. The ZooKeeper default <span class="codefrag filename">log4j.properties</span>
  512. file resides in the <span class="codefrag filename">conf</span> directory. Log4j requires that
  513. <span class="codefrag filename">log4j.properties</span> either be in the working directory
  514. (the directory from which ZooKeeper is run) or be accessible from the classpath.</p>
  515. <p>For more information, see
  516. <a href="http://logging.apache.org/log4j/1.2/manual.html#defaultInit">Log4j Default Initialization Procedure</a>
  517. of the log4j manual.</p>
  518. <a name="N101AD"></a><a name="sc_troubleshooting"></a>
  519. <h3 class="h4">Troubleshooting</h3>
  520. <p></p>
  521. <a name="N101B6"></a><a name="sc_configuration"></a>
  522. <h3 class="h4">Configuration Parameters</h3>
  523. <p>ZooKeeper's behavior is governed by the ZooKeeper configuration
  524. file. This file is designed so that the exact same file can be used by
  525. all the servers that make up a ZooKeeper server assuming the disk
  526. layouts are the same. If servers use different configuration files, care
  527. must be taken to ensure that the list of servers in all of the different
  528. configuration files match.</p>
  529. <a name="N101BF"></a><a name="sc_minimumConfiguration"></a>
  530. <h4>Minimum Configuration</h4>
  531. <p>Here are the minimum configuration keywords that must be defined
  532. in the configuration file:</p>
  533. <dl>
  534. <dt>
  535. <term>clientPort</term>
  536. </dt>
  537. <dd>
  538. <p>the port to listen for client connections; that is, the
  539. port that clients attempt to connect to.</p>
  540. </dd>
  541. <dt>
  542. <term>dataDir</term>
  543. </dt>
  544. <dd>
  545. <p>the location where ZooKeeper will store the in-memory
  546. database snapshots and, unless specified otherwise, the
  547. transaction log of updates to the database.</p>
  548. <div class="note">
  549. <div class="label">Note</div>
  550. <div class="content">
  551. <p>Be careful where you put the transaction log. A
  552. dedicated transaction log device is key to consistent good
  553. performance. Putting the log on a busy device will adversely
  554. effect performance.</p>
  555. </div>
  556. </div>
  557. </dd>
  558. <dt>
  559. <term>tickTime</term>
  560. </dt>
  561. <dd>
  562. <p>the length of a single tick, which is the basic time unit
  563. used by ZooKeeper, as measured in milliseconds. It is used to
  564. regulate heartbeats, and timeouts. For example, the minimum
  565. session timeout will be two ticks.</p>
  566. </dd>
  567. </dl>
  568. <a name="N101E6"></a><a name="sc_advancedConfiguration"></a>
  569. <h4>Advanced Configuration</h4>
  570. <p>The configuration settings in the section are optional. You can
  571. use them to further fine tune the behaviour of your ZooKeeper servers.
  572. Some can also be set using Java system properties, generally of the
  573. form <em>zookeeper.keyword</em>. The exact system
  574. property, when available, is noted below.</p>
  575. <dl>
  576. <dt>
  577. <term>dataLogDir</term>
  578. </dt>
  579. <dd>
  580. <p>(No Java system property)</p>
  581. <p>This option will direct the machine to write the
  582. transaction log to the <strong>dataLogDir</strong> rather than the <strong>dataDir</strong>. This allows a dedicated log
  583. device to be used, and helps avoid competition between logging
  584. and snaphots.</p>
  585. <div class="note">
  586. <div class="label">Note</div>
  587. <div class="content">
  588. <p>Having a dedicated log device has a large impact on
  589. throughput and stable latencies. It is highly recommened to
  590. dedicate a log device and set <strong>dataLogDir</strong> to point to a directory on
  591. that device, and then make sure to point <strong>dataDir</strong> to a directory
  592. <em>not</em> residing on that device.</p>
  593. </div>
  594. </div>
  595. </dd>
  596. <dt>
  597. <term>globalOutstandingLimit</term>
  598. </dt>
  599. <dd>
  600. <p>(Java system property: <strong>zookeeper.globalOutstandingLimit.</strong>)</p>
  601. <p>Clients can submit requests faster than ZooKeeper can
  602. process them, especially if there are a lot of clients. To
  603. prevent ZooKeeper from running out of memory due to queued
  604. requests, ZooKeeper will throttle clients so that there is no
  605. more than globalOutstandingLimit outstanding requests in the
  606. system. The default limit is 1,000.</p>
  607. </dd>
  608. <dt>
  609. <term>preAllocSize</term>
  610. </dt>
  611. <dd>
  612. <p>(Java system property: <strong>zookeeper.preAllocSize</strong>)</p>
  613. <p>To avoid seeks ZooKeeper allocates space in the
  614. transaction log file in blocks of preAllocSize kilobytes. The
  615. default block size is 64M. One reason for changing the size of
  616. the blocks is to reduce the block size if snapshots are taken
  617. more often. (Also, see <strong>snapCount</strong>).</p>
  618. </dd>
  619. <dt>
  620. <term>snapCount</term>
  621. </dt>
  622. <dd>
  623. <p>(Java system property: <strong>zookeeper.snapCount</strong>)</p>
  624. <p>Clients can submit requests faster than ZooKeeper can
  625. process them, especially if there are a lot of clients. To
  626. prevent ZooKeeper from running out of memory due to queued
  627. requests, ZooKeeper will throttle clients so that there is no
  628. more than globalOutstandingLimit outstanding requests in the
  629. system. The default limit is 1,000.ZooKeeper logs transactions
  630. to a transaction log. After snapCount transactions are written
  631. to a log file a snapshot is started and a new transaction log
  632. file is started. The default snapCount is 10,000.</p>
  633. </dd>
  634. <dt>
  635. <term>traceFile</term>
  636. </dt>
  637. <dd>
  638. <p>(Java system property: <strong>requestTraceFile</strong>)</p>
  639. <p>If this option is defined, requests will be will logged to
  640. a trace file named traceFile.year.month.day. Use of this option
  641. provides useful debugging information, but will impact
  642. performance. (Note: The system property has no zookeeper prefix,
  643. and the configuration variable name is different from the system
  644. property. Yes - it's not consistent, and it's annoying.)</p>
  645. </dd>
  646. </dl>
  647. <a name="N10246"></a><a name="sc_clusterOptions"></a>
  648. <h4>Cluster Options</h4>
  649. <p>The options in this section are designed for use with an ensemble
  650. of servers -- that is, when deploying clusters of servers.</p>
  651. <dl>
  652. <dt>
  653. <term>electionAlg</term>
  654. </dt>
  655. <dd>
  656. <p>(No Java system property)</p>
  657. <p>Election implementation to use. A value of "0" corresponds
  658. to the original UDP-based version, "1" corresponds to the
  659. non-authenticated UDP-based version of fast leader election, "2"
  660. corresponds to the authenticated UDP-based version of fast
  661. leader election, and "3" corresponds to TCP-based version of
  662. fast leader election. Currently, only 0 and 3 are supported, 3
  663. being the default</p>
  664. </dd>
  665. <dt>
  666. <term>initLimit</term>
  667. </dt>
  668. <dd>
  669. <p>(No Java system property)</p>
  670. <p>Amount of time, in ticks (see <a href="#id_tickTime">tickTime</a>), to allow followers to
  671. connect and sync to a leader. Increased this value as needed, if
  672. the amount of data managed by ZooKeeper is large.</p>
  673. </dd>
  674. <dt>
  675. <term>leaderServes</term>
  676. </dt>
  677. <dd>
  678. <p>(Java system property: zookeeper.<strong>leaderServes</strong>)</p>
  679. <p>Leader accepts client connections. Default value is "yes".
  680. The leader machine coordinates updates. For higher update
  681. throughput at thes slight expense of read throughput the leader
  682. can be configured to not accept clients and focus on
  683. coordination. The default to this option is yes, which means
  684. that a leader will accept client connections.</p>
  685. <div class="note">
  686. <div class="label">Note</div>
  687. <div class="content">
  688. <p>Turning on leader selection is highly recommended when
  689. you have more than three ZooKeeper servers in an ensemble.</p>
  690. </div>
  691. </div>
  692. </dd>
  693. <dt>
  694. <term>server.x=[hostname]:nnnnn[:nnnnn], etc</term>
  695. </dt>
  696. <dd>
  697. <p>(No Java system property)</p>
  698. <p>servers making up the ZooKeeper ensemble. When the server
  699. starts up, it determines which server it is by looking for the
  700. file <span class="codefrag filename">myid</span> in the data directory. That file
  701. contains the server number, in ASCII, and it should match
  702. <strong>x</strong> in <strong>server.x</strong> in the left hand side of this
  703. setting.</p>
  704. <p>The list of servers that make up ZooKeeper servers that is
  705. used by the clients must match the list of ZooKeeper servers
  706. that each ZooKeeper server has.</p>
  707. <p>There are two port numbers <strong>nnnnn</strong>.
  708. The first followers use to connect to the leader, and the second is for
  709. leader election. The leader election port is only necessary if electionAlg
  710. is 1, 2, or 3 (default). If electionAlg is 0, then the second port is not
  711. necessary. If you want to test multiple servers on a single machine, then
  712. different ports can be used for each server.</p>
  713. </dd>
  714. <dt>
  715. <term>syncLimit</term>
  716. </dt>
  717. <dd>
  718. <p>(No Java system property)</p>
  719. <p>Amount of time, in ticks (see <a href="#id_tickTime">tickTime</a>), to allow followers to sync
  720. with ZooKeeper. If followers fall too far behind a leader, they
  721. will be dropped.</p>
  722. </dd>
  723. </dl>
  724. <p></p>
  725. <a name="N102A3"></a><a name="Unsafe+Options"></a>
  726. <h4>Unsafe Options</h4>
  727. <p>The following options can be useful, but be careful when you use
  728. them. The risk of each is explained along with the explanation of what
  729. the variable does.</p>
  730. <dl>
  731. <dt>
  732. <term>forceSync</term>
  733. </dt>
  734. <dd>
  735. <p>(Java system property: <strong>zookeeper.forceSync</strong>)</p>
  736. <p>Requires updates to be synced to media of the transaction
  737. log before finishing processing the update. If this option is
  738. set to no, ZooKeeper will not require updates to be synced to
  739. the media.</p>
  740. </dd>
  741. <dt>
  742. <term>jute.maxbuffer:</term>
  743. </dt>
  744. <dd>
  745. <p>(Java system property:<strong>
  746. jute.maxbuffer</strong>)</p>
  747. <p>This option can only be set as a Java system property.
  748. There is no zookeeper prefix on it. It specifies the maximum
  749. size of the data that can be stored in a znode. The default is
  750. 0xfffff, or just under 1M. If this option is changed, the system
  751. property must be set on all servers and clients otherwise
  752. problems will arise. This is really a sanity check. ZooKeeper is
  753. designed to store data on the order of kilobytes in size.</p>
  754. </dd>
  755. <dt>
  756. <term>skipACL</term>
  757. </dt>
  758. <dd>
  759. <p>(Java system property: <strong>zookeeper.skipACL</strong>)</p>
  760. <p>Skips ACL checks. This results in a boost in throughput,
  761. but opens up full access to the data tree to everyone.</p>
  762. </dd>
  763. </dl>
  764. <a name="N102D5"></a><a name="sc_zkCommands"></a>
  765. <h3 class="h4">ZooKeeper Commands: The Four Letter Words</h3>
  766. <p>ZooKeeper responds to a small set of commands. Each command is
  767. composed of four letters. You issue the commands to ZooKeeper via telnet
  768. or nc, at the client port.</p>
  769. <dl>
  770. <dt>
  771. <term>dump</term>
  772. </dt>
  773. <dd>
  774. <p>Lists the outstanding sessions and ephemeral nodes. This
  775. only works on the leader.</p>
  776. </dd>
  777. <dt>
  778. <term>envi</term>
  779. </dt>
  780. <dd>
  781. <p>Print details about serving environment</p>
  782. </dd>
  783. <dt>
  784. <term>kill</term>
  785. </dt>
  786. <dd>
  787. <p>Shuts down the server. This must be issued from the machine
  788. the ZooKeeper server is running on.</p>
  789. </dd>
  790. <dt>
  791. <term>reqs</term>
  792. </dt>
  793. <dd>
  794. <p>List outstanding requests</p>
  795. </dd>
  796. <dt>
  797. <term>ruok</term>
  798. </dt>
  799. <dd>
  800. <p>Tests if server is running in a non-error state. The server
  801. will respond with imok if it is running. Otherwise it will not
  802. respond at all.</p>
  803. </dd>
  804. <dt>
  805. <term>stat</term>
  806. </dt>
  807. <dd>
  808. <p>Lists statistics about performance and connected
  809. clients.</p>
  810. </dd>
  811. </dl>
  812. <p>Here's an example of the <strong>ruok</strong>
  813. command:</p>
  814. <pre class="code">$ echo ruok | nc 127.0.0.1 5111
  815. imok
  816. </pre>
  817. <a name="N10315"></a><a name="sc_dataFileManagement"></a>
  818. <h3 class="h4">Data File Management</h3>
  819. <p>ZooKeeper stores its data in a data directory and its transaction
  820. log in a transaction log directory. By default these two directories are
  821. the same. The server can (and should) be configured to store the
  822. transaction log files in a separate directory than the data files.
  823. Throughput increases and latency decreases when transaction logs reside
  824. on a dedicated log devices.</p>
  825. <a name="N1031E"></a><a name="The+Data+Directory"></a>
  826. <h4>The Data Directory</h4>
  827. <p>This directory has two files in it:</p>
  828. <ul>
  829. <li>
  830. <p>
  831. <span class="codefrag filename">myid</span> - contains a single integer in
  832. human readable ASCII text that represents the server id.</p>
  833. </li>
  834. <li>
  835. <p>
  836. <span class="codefrag filename">snapshot.&lt;zxid&gt;</span> - holds the fuzzy
  837. snapshot of a data tree.</p>
  838. </li>
  839. </ul>
  840. <p>Each ZooKeeper server has a unique id. This id is used in two
  841. places: the <span class="codefrag filename">myid</span> file and the configuration file.
  842. The <span class="codefrag filename">myid</span> file identifies the server that
  843. corresponds to the given data directory. The configuration file lists
  844. the contact information for each server identified by its server id.
  845. When a ZooKeeper server instance starts, it reads its id from the
  846. <span class="codefrag filename">myid</span> file and then, using that id, reads from the
  847. configuration file, looking up the port on which it should
  848. listen.</p>
  849. <p>The <span class="codefrag filename">snapshot</span> files stored in the data
  850. directory are fuzzy snapshots in the sense that during the time the
  851. ZooKeeper server is taking the snapshot, updates are occurring to the
  852. data tree. The suffix of the <span class="codefrag filename">snapshot</span> file names
  853. is the <em>zxid</em>, the ZooKeeper transaction id, of the
  854. last committed transaction at the start of the snapshot. Thus, the
  855. snapshot includes a subset of the updates to the data tree that
  856. occurred while the snapshot was in process. The snapshot, then, may
  857. not correspond to any data tree that actually existed, and for this
  858. reason we refer to it as a fuzzy snapshot. Still, ZooKeeper can
  859. recover using this snapshot because it takes advantage of the
  860. idempotent nature of its updates. By replaying the transaction log
  861. against fuzzy snapshots ZooKeeper gets the state of the system at the
  862. end of the log.</p>
  863. <a name="N1035A"></a><a name="The+Log+Directory"></a>
  864. <h4>The Log Directory</h4>
  865. <p>The Log Directory contains the ZooKeeper transaction logs.
  866. Before any update takes place, ZooKeeper ensures that the transaction
  867. that represents the update is written to non-volatile storage. A new
  868. log file is started each time a snapshot is begun. The log file's
  869. suffix is the first zxid written to that log.</p>
  870. <a name="N10364"></a><a name="File+Management"></a>
  871. <h4>File Management</h4>
  872. <p>The format of snapshot and log files does not change between
  873. standalone ZooKeeper servers and different configurations of
  874. replicated ZooKeeper servers. Therefore, you can pull these files from
  875. a running replicated ZooKeeper server to a development machine with a
  876. stand-alone ZooKeeper server for trouble shooting.</p>
  877. <p>Using older log and snapshot files, you can look at the previous
  878. state of ZooKeeper servers and even restore that state. The
  879. LogFormatter class allows an administrator to look at the transactions
  880. in a log.</p>
  881. <p>The ZooKeeper server creates snapshot and log files, but never
  882. deletes them. The retention policy of the data and log files is
  883. implemented outside of the ZooKeeper server. The server itself only
  884. needs the latest complete fuzzy snapshot and the log files from the
  885. start of that snapshot. The PurgeTxnLog utility implements a simple
  886. retention policy that administrators can use.</p>
  887. <a name="N10375"></a><a name="sc_commonProblems"></a>
  888. <h3 class="h4">Things to Avoid</h3>
  889. <p>Here are some common problems you can avoid by configuring
  890. ZooKeeper correctly:</p>
  891. <dl>
  892. <dt>
  893. <term>inconsistent lists of servers</term>
  894. </dt>
  895. <dd>
  896. <p>The list of ZooKeeper servers used by the clients must match
  897. the list of ZooKeeper servers that each ZooKeeper server has.
  898. Things work okay if the client list is a subset of the real list,
  899. but things will really act strange if clients have a list of
  900. ZooKeeper servers that are in different ZooKeeper clusters. Also,
  901. the server lists in each Zookeeper server configuration file
  902. should be consistent with one another.</p>
  903. </dd>
  904. <dt>
  905. <term>incorrect placement of transasction log</term>
  906. </dt>
  907. <dd>
  908. <p>The most performance critical part of ZooKeeper is the
  909. transaction log. ZooKeeper syncs transactions to media before it
  910. returns a response. A dedicated transaction log device is key to
  911. consistent good performance. Putting the log on a busy device will
  912. adversely effect performance. If you only have one storage device,
  913. put trace files on NFS and increase the snapshotCount; it doesn't
  914. eliminate the problem, but it should mitigate it.</p>
  915. </dd>
  916. <dt>
  917. <term>incorrect Java heap size</term>
  918. </dt>
  919. <dd>
  920. <p>You should take special care to set your Java max heap size
  921. correctly. In particular, you should not create a situation in
  922. which ZooKeeper swaps to disk. The disk is death to ZooKeeper.
  923. Everything is ordered, so if processing one request swaps the
  924. disk, all other queued requests will probably do the same. the
  925. disk. DON'T SWAP.</p>
  926. <p>Be conservative in your estimates: if you have 4G of RAM, do
  927. not set the Java max heap size to 6G or even 4G. For example, it
  928. is more likely you would use a 3G heap for a 4G machine, as the
  929. operating system and the cache also need memory. The best and only
  930. recommend practice for estimating the heap size your system needs
  931. is to run load tests, and then make sure you are well below the
  932. usage limit that would cause the system to swap.</p>
  933. </dd>
  934. </dl>
  935. <a name="N10399"></a><a name="sc_bestPractices"></a>
  936. <h3 class="h4">Best Practices</h3>
  937. <p>For best results, take note of the following list of good
  938. Zookeeper practices. <em>[tbd...]</em>
  939. </p>
  940. </div>
  941. <p align="right">
  942. <font size="-2"></font>
  943. </p>
  944. </div>
  945. <!--+
  946. |end content
  947. +-->
  948. <div class="clearboth">&nbsp;</div>
  949. </div>
  950. <div id="footer">
  951. <!--+
  952. |start bottomstrip
  953. +-->
  954. <div class="lastmodified">
  955. <script type="text/javascript"><!--
  956. document.write("Last Published: " + document.lastModified);
  957. // --></script>
  958. </div>
  959. <div class="copyright">
  960. Copyright &copy;
  961. 2008 <a href="http://www.apache.org/licenses/">The Apache Software Foundation.</a>
  962. </div>
  963. <!--+
  964. |end bottomstrip
  965. +-->
  966. </div>
  967. </body>
  968. </html>