Apache Zookeeper Architecture and Installation
This article was published as a part of the Data Science Blogathon.
Zookeeper in Hadoop can be considered a centralized repository where distributed applications can put data into and retrieve data from. It makes a distributed system work together as a whole using its synchronization, serialization, and coordination goals. For clarity, Zookeeper can be thought of as a file system where we have nodes that store data instead of files or directories that store data. Zookeeper is a Hadoop Admin tool used to manage jobs in a cluster.
Why do we need a Zookeeper in Hadoop?
A deadlock occurs when two or more computers attempt to access the same shared resource simultaneously. More precisely, they try to access each other’s resources, which leads to a deadlock because neither system releases the resource but waits for the other system to release it. Synchronization in Zookeeper helps resolve deadlocks. Another major problem with a distributed application is partial process failure, leading to data inconsistency. Zookeeper handles this with atomicity, meaning either the entire process terminates, or nothing is left after failure. So Zookeeper is an important part of Hadoop that takes care of these small but important matters so that the developer can focus more on the application’s functionality.
How does Zookeeper Architecture work in Hadoop?
Writes in Zookeeper Architecture
Reads in ZookeeperArchitecture
How to use Apache ZooKeeper to build distributed applications?
- Persistent: This is the default node type in every Zookeeper. Persistent nodes are always present and contain important configuration details. When a new node is added to Zookeeper, it goes to the permanent node and gets configuration information.
- Transient: These are session nodes that are created when the application starts and are deleted when the application ends. This is mainly useful for checking client applications in case of failure. When the app crashes, znode dies.
Installing Apache ZooKeeper
- Download and install the JDK from http://www.oracle.com/technetwork/java/javase/downloads/index.html or http://www.guru99.com/install-java.html – if not already installed. The Apache ZooKeeper server runs on the JVM, an important prerequisite.
- Go to http://zookeeper.apache.org/ and download Zookeeper from the release page.
- Select download from mirrors and select the first mirror.
- Go to the stable folder and download zookeeper-3.4.6.tar.gz
- Unzip the tarball with tar –zxvf zookeeper-3.4.6.tar.gz
- Create the directory with mkdir/usr/local/zookeeper/data. You can create this directory as root and change the owner to any user you need.
- Create a zookeeper configuration file using sudo vi / usr/local/zookeeper/conf/zoo.cfg and insert the following code:
tickTime = 2000 sync limit = 5 dataDir = /usr/local/zookeeper/data clientPort t= 2181 server.1 = Master : 2888 : 3888 server.2 = Slave1 : 2888 : 3888 server.3 = Slave2 : 2888 : 3888
- Create a file named myid in the data folder using sudo vi/usr/local/zookeeper/data/myid and write “1” without quotes in this file and save it.
- Do steps 1 to 7 for the other 2 servers, but change the myid data to 2 for servers 2 and 3 for server 3.
- Use the zkServer.sh start command to start Zookeeper on all servers
- To confirm that Zookeeper has started, type jps and check QuorumPeerMain.
- Use the command zkCli.sh -server Slave1:2181 to start the client
The below-listed points explain how to use Zookeeper-
Zookeeper Architecture goes through the master node, so all writes are guaranteed to be sequential. When performing a write operation to Zookeeper, each server connected to this client stores data along with the master server. This keeps all servers updated with the data. However, this also means that concurrent writes cannot be performed.
- Apache Zookeeper might be a data model. Each directory in our example is called a znode in Zookeeper. Stores statistical data such as version details and user data up to 1 Mb in size.
- If the master node fails, another master node is instantly selected and takes over from the previous master node. In addition to masters and slaves, there are also observers in Zookeeper.
- Multiple server nodes are collectively called a ZooKeeper file. A Zookeeper Architecture client uses at least one server at a given time.
The media shown in this article is not owned by Analytics Vidhya and is used at the Author’s discretion.