zookeeperAdmin.html 36 KB

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