zookeeperAdmin.html 35 KB

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