{"id":6106,"date":"2018-04-01T21:17:16","date_gmt":"2018-04-01T21:17:16","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=6106"},"modified":"2018-04-01T21:17:16","modified_gmt":"2018-04-01T21:17:16","slug":"zookeeper","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/zookeeper\/","title":{"rendered":"ZooKeeper"},"content":{"rendered":"<p><strong>Why do we need ZooKeeper<\/strong><\/p>\n<p>The first question I had to ask myself was, why do we need ZooKeeper? After all I could store\/publish the host\/port etc. to a Redis server, a database or just a plain centrally located web service (which for all I care could store the information to a simple file).<\/p>\n<p>ZooKeeper has been designed specifically for handling configuration and name registry functionality in a distributed and clustered environment, hence comes with more advanced features to ensure consistency of data along with capabilities to handle cluster management of the servers.<\/p>\n<p><strong>ZooKeeper in Docker<\/strong><\/p>\n<p>I&#8217;m using <a href=\"https:\/\/docs.docker.com\/samples\/library\/zookeeper\/\" rel=\"noopener\" target=\"_blank\">ZooKeeper within docker<\/a>.<\/p>\n<p>To run a ZooKeeper instance within a Docker container, simply use<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\ndocker run --name zookeeper1 --restart always -d zookeeper\r\n<\/pre>\n<p>My first instance is named <em>zookeeper1<\/em>. This command will run a server instance of ZooKeeper. <\/p>\n<p>We may also need to attach to the service with a client, we can run the following command<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\ndocker run -it --rm --link zookeeper1:zookeeper zookeeper zkCli.sh -server zookeeper\r\n<\/pre>\n<p><em>Ensure the name of the Docker instance matches the name you assigned to the server.<\/em><\/p>\n<p><strong>Client commands<\/strong><\/p>\n<p><em<This is not meant to be an exhaustive list of ZooKeeper client commands, but concentrates on the core functionality.<\/em><\/p>\n<ul>\n<li><strong>create<\/strong> We can create a path, \/root\/sub format, to our data, for example <em>create \/services &#8220;hello&#8221;<\/em>. Note: it seems that to create child nodes we cannot just type <em>create \/services\/hello-service &#8220;hello&#8221;<\/em>, we need to first create the root node then the child node.<\/li>\n<li><strong>ls<\/strong> We can list nodes by typing <em>ls \/<\/em> or using root and\/child nodes, for example <em>ls \/services\/hello-service<\/em>. If nodes exist below the listed node the output will be [node-name], so for example <em>ls \/services<\/em> will result in [hello-service]. When no child nodes exists we&#8217;ll get [].<\/li>\n<li><strong>get<\/strong> We can get any data stored at the end of a node, so for example <em>get \/services\/hello-service<\/em> will display the data stored in the node along with data such as the date\/time the data was stored, it&#8217;s size etc.<\/li>\n<li><strong>rmr<\/strong> We can recursively remove nodes (i.e. remove a node and all it&#8217;s children) using <em>rmr<\/em>. For example <em>rmr \/services<\/em>.<\/li>\n<li><strong>delete<\/strong> We can delete an end node using <em>delete<\/em> but this will not work on a node which has children (i.e. it works only on empty nodes).<\/li>\n<li><strong>connect<\/strong> We can connect the client to a running instance of a ZooKeeper server using <em>connect<\/em>, i.e. <em>connect 172.17.0.2:2181<\/em><\/li>\n<li><strong>quit<\/strong> Exists the client.<\/em>\n<\/ul>\n<p>There are other client commands, but these are probably the main one&#8217;s from the client run <em>help<\/em> to see a full list of commands.<\/p>\n<p>Some command have a [watch] options, which can be enabled by either supplying 1 or true as the last argument to the relevant commands.<\/p>\n<p><strong>Useful References<\/strong><\/p>\n<p><a href=\"http:\/\/www.palladiumconsulting.com\/2014\/05\/zookeeper-1-ephemeral-nodes\/\" rel=\"noopener\" target=\"_blank\">ZooKeeper Usage 1 &#8211; 5<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Why do we need ZooKeeper The first question I had to ask myself was, why do we need ZooKeeper? After all I could store\/publish the host\/port etc. to a Redis server, a database or just a plain centrally located web service (which for all I care could store the information to a simple file). ZooKeeper [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[211],"tags":[],"class_list":["post-6106","post","type-post","status-publish","format-standard","hentry","category-zookeeper"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/6106","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=6106"}],"version-history":[{"count":8,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/6106\/revisions"}],"predecessor-version":[{"id":6121,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/6106\/revisions\/6121"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=6106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=6106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=6106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}