Hadoop beginner's Guide (10) -- installing and operating zookeeper Clusters

Source: Internet
Author: User

This article briefly introduces the basic knowledge of zookeeper.


(1) Overview

① What is zookeeper?

Zookeeper is an open-source implementation of Google's chubby and a Distributed Coordination Service of hadoop.

It contains a simple primitive set. distributed applications can implement synchronization services, configuration maintenance, and naming services based on it.

② Role of zookeeper

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/38/5A/wKioL1OzxZahBuIGAAECR45s2BU483.jpg "Title =" image 1.jpg "alt =" wkiol1ozxzahbuigaaecr45s2bu483.jpg "/>

③ Why is zookeeper used?

Most distributed applications require a master, Coordinator, or controller to Manage Sub-processes (such as resources and task allocation) that are physically distributed)

At present, most applications need to develop private coordination programs and lack a general mechanism.

Repeated compilation of the Coordination Program is a waste, and it is difficult to form a common and scalable coordinator.

Zookeeper: provides common Distributed Lock Services to coordinate distributed applications.

④ Features of zookeeper

Zookeeper is simple

Zookeeper is expressive

High Availability of zookeeper

Zookeeper adopts loose coupling interaction mode

Zookeeper is a resource library.


(2) Installation

① Decompress

Command: tar-zvxf zookeeper-3.4.5.tar.gz

② For future convenience, rename the decompressed folder

Command: Music zookeeper-3.4.5 ZK

③ Set Environment Variables

Command: Vim/etc/profile

Add zookeeper_home and modify path

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/38/65/wKioL1OzzC6wNBPxAACFSjhm1qo198.jpg "Title =" zk2.png "alt =" wkiol1ozzc6wnbpxaacfsjhm1qo198.jpg "/>

After the modification is complete, reload the Configuration:

Source/etc/profile

④ Modify the zookeeper configuration file

Modify zoo_sample.cfg in zk/conf to zoo. cfg, and edit the file

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/38/69/wKiom1OzzxfivrA0AAJY5yFzeks033.jpg "Title =" zk3.png "alt =" wkiom1ozzxfivra0aajy5yfzeks033.jpg "/>

Datadir indicates the cluster data, server. the following ID indicates the number of the zookeeper cluster host. hadoop0 is my host name, 2888 and 3888 are ports, 2888 is the port of the zookeeper role, and 3888 is the port on which zookeeper transmits data.


⑤ Create a folder/usr/local/ZK/data and create a myid file in the folder. The content is the zookeeper cluster number corresponding to the current host. For example, the current host is hadoop0, the content of the myid file is as follows:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/38/6E/wKiom1Oz0NDjyIzLAAAt-eX0C1c516.jpg "Title =" zk4.png "alt =" wKiom1Oz0NDjyIzLAAAt-eX0C1c516.jpg "/>

6. You can also use SCP to copy files on other hosts.


7. Start zookeeper

Go to the bin directory and run the following command:

Zkserver. Sh start

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/38/71/wKiom1Oz0zSTy_XeAADfRppAXQA298.jpg "Title =" zk5.png "alt =" wkiom1oz0zsty_xeaadfrppaxqa298.jpg "/>

In this case, the zookeeper cluster of the hadoop0 node is started, and then you can check the zookeeper. Out file. The content is as follows:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/38/71/wKioL1Oz042BC6RtAAfA06RNE3U816.jpg "Title =" zk6.png "alt =" wkiol1oz042bc6rtaafa06rne3u816.jpg "/>

You can see that the cluster has identified the myid file. Because the cluster on other nodes is not started, an error is reported. In this case, you only need to start the cluster on other nodes.


(3) Role of zookeeper

Leader is responsible for initiating voting and making resolutions, and updating the system status.

Learner, including follower and observer. follower is used to accept client requests and want the client to return results.

The observer can accept client connections and forward write requests to the leader. However, the observer only synchronizes the status of the leader without voting. The observer aims to expand the system and increase the reading speed.

Client, the requester


After starting the cluster, you can use zkserver. Sh status to view roles.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/38/75/wKioL1Oz1PaT_tYmAABzdFW_R2E531.jpg "style =" float: none; "Title =" zk7.png "alt =" wkiol1oz1pat_tymaabzdfw_r2e531.jpg "/>

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/38/76/wKiom1Oz1SXwFhvNAABj3NM7qQs943.jpg "style =" float: none; "Title =" zk8.png "alt =" wkiom1oz1sxwfhvnaabj3nm7qqs943.jpg "/>

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/38/75/wKioL1Oz1PaSjX5-AABllK-qZxQ633.jpg "style =" float: none; "Title =" zk9.png "alt =" wKioL1Oz1PaSjX5-AABllK-qZxQ633.jpg "/>



(3) Basic shell operations of zookeeper

Use zkcli. Sh to access the shell operation of zookeeper.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/38/78/wKiom1Oz1_PBoYhzAAScq-8k2kw185.jpg "Title =" zk10.png "alt =" wKiom1Oz1_PBoYhzAAScq-8k2kw185.jpg "/>

Type help to view the supported commands:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/38/78/wKiom1Oz2EvQiobNAAETsSXIovY857.jpg "Title =" zk11.png "alt =" wkiom1oz2evqiobnaaetssxiovy857.jpg "/>

Use ls/to view the directory. You can also see that zookeeper automatically accumulates the number of operation commands:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/38/77/wKioL1Oz2FXwTgvoAABWL050rJQ404.jpg "Title =" zk12.png "alt =" wkiol1oz2fxwtgvoaabwl0501_q404.jpg "/>

Create a node and view it:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/38/78/wKiom1Oz2NiiezFxAAE0AK8rc_4225.jpg "Title =" zk13.png "alt =" wkiom1oz2niiezfxaae0ak8rc_4225.jpg "/>

If you log on to another node, you can see that the data has been synchronized to the cluster.

This article is from the "xlows" blog, please be sure to keep this source http://xlows.blog.51cto.com/5380484/1433662

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.