zookeeperAdmin.html 36 KB

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