zookeeperAdmin.html 36 KB

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