{"id":729,"date":"2016-08-05T10:19:29","date_gmt":"2016-08-05T10:19:29","guid":{"rendered":"https:\/\/blog.ngocha.biz\/?p=729"},"modified":"2016-08-05T10:19:29","modified_gmt":"2016-08-05T10:19:29","slug":"how-to-setup-a-zookeeper-cluster","status":"publish","type":"post","link":"https:\/\/blog.ngocha.biz\/?p=729","title":{"rendered":"How To Setup a Zookeeper Cluster &#8211; Beginners Guide"},"content":{"rendered":"<p>Zookeeper is a distributed coordination tool which can be used for various distributed workloads. In this article, we have explained the necessary steps to install and configure zookeeper cluster with a definite quorum.<\/p>\n<h2 id=\"setup-a-zookeeper-cluster\">Setup a Zookeeper Cluster<\/h2>\n<h4 id=\"prerequisites\">Prerequisites<\/h4>\n<ol>\n<li>Three VM&#8217;s. (Forms a quorum). For high availability cluster, you can go with any odd number above 3. For example, if you set up 5 servers, the cluster can handle two failed nodes and so on.<\/li>\n<li>VM\u2019s with inbound connections on ports 2888, 3888 and 2181. If IPtables is enabled, make sure you enable the specified ports because zookeeper communication happens through these ports.<\/li>\n<\/ol>\n<p>Note: If you are using AWS or any other cloud provider, apart from server level inbound connections, make sure you enable the security groups or endpoints for the zookeeper ports.<\/p>\n<h3 id=\"install-and-configure-zookeeper\">Install and Configure Zookeeper<\/h3>\n<p>You need to perform the following steps in all the three VM&#8217;s.<\/p>\n<ol>\n<li>Update your server.<\/li>\n<\/ol>\n<pre><code>sudo yum -y update<\/code><\/pre>\n<ol start=\"2\">\n<li>Install Java if is not installed.<\/li>\n<\/ol>\n<pre><code>sudo yum  -y install java-1.7.0-openjdk<\/code><\/pre>\n<ol start=\"3\">\n<li>Download zookeeper. b If you wish to choose another version, you can get the download links from here.<\/li>\n<\/ol>\n<pre><code>wget http:\/\/mirror.fibergrid.in\/apache\/zookeeper\/zookeeper-3.5.2-alpha\/zookeeper-3.5.2-alpha.tar.gz<\/code><\/pre>\n<ol start=\"4\">\n<li>Untar the application to \/opt folder<\/li>\n<\/ol>\n<pre><code>sudo tar -xf zookeeper-3.5.2-alpha.tar.gz -C \/opt\/<\/code><\/pre>\n<ol start=\"5\">\n<li>Rename the zookeeper app directory<\/li>\n<\/ol>\n<pre><code>cd \/opt sudo mv zookeeper-* zookeeper<\/code><\/pre>\n<ol start=\"6\">\n<li>Create a zoo.cfg file in \/opt\/zookeeper\/conf directory with the configurations shown below.<\/li>\n<\/ol>\n<pre><code>tickTime=2000\ndataDir=\/var\/lib\/zookeeper\nclientPort=2181\ninitLimit=5\nsyncLimit=2\nserver.1=&lt;ZooKeeper_IP\/hostname&gt;:2888:3888\nserver.2=&lt;ZooKeeper_iP\/hostname&gt;:2888:3888\nserver.3=&lt;ZooKeeper_iP\/hostname&gt;:2888:3888<\/code><\/pre>\n<p>In the above code, server 1, 2 and 3 represent our three zookeeper servers. You need to replace the Zookeeper_IP with relevant IP or resolvable hostnames.<\/p>\n<ol start=\"7\">\n<li>Create a zookeeper directory in the lib folder. Thar will be zookeepers data directory as mentioned in the zoo.cfg file.<\/li>\n<\/ol>\n<pre><code>sudo mkdir \/var\/lib\/zookeeper<\/code><\/pre>\n<ol start=\"8\">\n<li>Create a file name myid in \/var\/lib\/zookeeper\/ directory .<\/li>\n<\/ol>\n<pre><code>sudo touch \/var\/lib\/zookeeper\/myid<\/code><\/pre>\n<ol start=\"9\">\n<li>Each zookeeper server should have a unique number in the myid file. For example, server 1 will have value 1, server 2 will have value 2 and so on.<\/li>\n<\/ol>\n<p><strong>server 1<\/strong><\/p>\n<pre><code>sudo sh -c \"echo '1' &gt; \/var\/lib\/zookeeper\/myid\"<\/code><\/pre>\n<p><strong>server 2<\/strong><\/p>\n<pre><code>sudo sh -c \"echo '2' &gt; \/var\/lib\/zookeeper\/myid\"<\/code><\/pre>\n<p><strong>server 1<\/strong><\/p>\n<pre><code>sudo sh -c \"echo '3' &gt; \/var\/lib\/zookeeper\/myid\"<\/code><\/pre>\n<h3 id=\"configuring-zookeeper-as-a-service\">Configuring Zookeeper as a Service<\/h3>\n<p>Zookeeper can be started and stopped using the scripts. But it is good to run it as a service to manage it in an elegant way.<\/p>\n<ol>\n<li>Open zkServer.zh file for editing.<\/li>\n<\/ol>\n<pre><code>sudo vi \/opt\/zookeeper\/bin\/zkServer.sh<\/code><\/pre>\n<ol start=\"2\">\n<li>Add the following below the shebang \u201c#!\/usr\/bin\/env bash\u201d to add zookeeper to the system start up.<\/li>\n<\/ol>\n<pre><code># description: Zookeeper Start Stop Restart\n# processname: zookeeper\n# chkconfig: 244 30 80<\/code><\/pre>\n<ol start=\"3\">\n<li>Find a line which says \u201c# use POSTIX&nbsp;interface, symlink is followed automatically\u201d. Replace the existing variables after that line with the following.<\/li>\n<\/ol>\n<pre><code>ZOOSH=`readlink $0`\nZOOBIN=`dirname $ZOOSH`\nZOOBINDIR=`cd $ZOOBIN; pwd`\nZOO_LOG_DIR=`echo $ZOOBIN`<\/code><\/pre>\n<ol start=\"4\">\n<li>Now, create a symlink for the zookeeper service.<\/li>\n<\/ol>\n<pre><code>sudo ln -s \/opt\/zookeeper\/bin\/zkServer.sh \/etc\/init.d\/zookeeper<\/code><\/pre>\n<p>5. Add zookeeper to the boot menu.<\/p>\n<pre><code>sudo chkconfig zookeeper on<\/code><\/pre>\n<ol start=\"6\">\n<li>Now, Restart all the servers.<\/li>\n<\/ol>\n<pre><code>sudo  init 6<\/code><\/pre>\n<ol start=\"7\">\n<li>Once restarted, you can manage zookeeper servers using the following commands.<\/li>\n<\/ol>\n<pre><code>sudo service zookeeper status\nsudo service zookeeper stop\nsudo service zookeeper start\nsudo service zookeeper restart<\/code><\/pre>\n<ol start=\"8\">\n<li>When you check the status, it should produce an output like the following.<\/li>\n<\/ol>\n<pre><code>\/bin\/java\nZooKeeper JMX enabled by default\nUsing config: \/opt\/zookeeper\/bin\/..\/conf\/zoo.cfg\nClient port found: 2181. Client address: localhost.\nMode: leader<\/code><\/pre>\n<p>out of three servers, one will be in leader mode and other two will be in follower mode.<\/p>\n<hr>\n<p><strong>Ngu\u1ed3n:<\/strong> <a href=\"https:\/\/devopscube.com\/how-to-setup-a-zookeeper-cluster\/\" target=\"_blank\" rel=\"noopener noreferrer\">How To Setup a Zookeeper Cluster &#8211; Beginners Guide \u2014 DevOpsCube<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/devopscube.com\/how-to-setup-a-zookeeper-cluster\/<\/p>\n","protected":false},"author":1,"featured_media":730,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-729","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/729","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=729"}],"version-history":[{"count":0,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/729\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/media\/730"}],"wp:attachment":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=729"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=729"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=729"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}