Zookeeper installation and configuration

ZooKeeper is a distributed open source framework that provides basic services for coordinating distributed applications. It exposes a set of common services to external applications—Distributed Synchronization, Naming Service, and Group Maintenance. etc., simplify the coordination and management of distributed applications, and provide high-performance distributed services. ZooKeeper itself can be installed and run in Standalone mode, but its advantage lies in ensuring the stability and availability of the ZooKeeper cluster based on a certain strategy through a distributed ZooKeeper cluster (one Leader, multiple Followers), so as to achieve the reliability of distributed applications .

There are many introductions to ZooKeeper on the Internet, and you can also refer to some related links that I have compiled at the back of the article.

Next, we briefly explain the configuration of ZooKeeper

ZooKeeper Standalone Mode

Download the ZooKeeper package from the Apache website (zookeeper.apache.org), I chose version 3.3.6 (zookeeper-3.3.6.tar.gz), it's very easy to install on a Linux machine, just unzip it After that, simply configure it to start the ZooKeeper server process.

Use the cp zoo_sample.cfg zoo.cfg command in the zookeeper-3.3.6/conf directory to copy zoo_sample.cfg and rename it to zoo.cfg. The content of the configuration file is as follows:

The meaning of the above configuration parameters is also very simple, and the reference is as follows:

tickTime —— The basic time unit of heartbeat, in milliseconds, basically all the time of ZK is an integer multiple of this time.
dataDir —— The storage address of the in-memory database snapshot. If the transaction log storage address (dataLogDir) is not specified, it is also stored in this path by default. It is recommended that the two addresses be stored separately on different devices. 

 

Let's start the ZooKeeper server process:

The ZooKeeper server process, named QuorumPeerMain, can be viewed through the jps command.

To connect to the ZooKeeper server on the client, execute the following command:



ZooKeeper Distributed模式

ZooKeeper distributed mode installation (ZooKeeper cluster) is also relatively easy, here are the basic points.

The first thing to be clear is that the ZooKeeper cluster is an independent distributed coordination service cluster. The meaning of "independent" means that if you want to use ZooKeeper to realize the coordination and management of distributed applications and simplify coordination and management, any distributed application can Use, thanks to Zookeeper's data model (Data Model) and hierarchical namespace (Hierarchical Namespace) structure, please refer to http://zookeeper.apache.org/doc/trunk/zookeeperOver.html for details. When designing your distributed application coordination service, the first thing to consider is how to organize the hierarchical namespace.

The following describes the installation and configuration of the distributed mode. The process is as follows:

Step 1: Host name to IP address mapping configuration

There are two key roles in the ZooKeeper cluster: Leader and Follower. All nodes in the cluster provide services for distributed applications as a whole, and each node in the cluster is connected to each other. Therefore, when configuring a ZooKeeper cluster, the mapping from host to IP address of each node is To configure the mapping information of other nodes in the cluster.

For example, the configuration of each node in my ZooKeeper cluster, taking CentOS1 as an example, the content of /etc/hosts is as follows:


 

ZooKeeper employs an election algorithm called Leader election. During the operation of the entire cluster, there is only one leader, and the others are followers. If there is a problem with the leader during the operation of the ZooKeeper cluster, the system will use this algorithm to re-select a leader. Therefore, the above mapping must be configured to ensure that each node is connected to each other.

When the ZooKeeper cluster is started, a leader will be elected first. During the leader election process, a node that satisfies the election calculation can become the leader. The architecture of the entire cluster can be found at http://zookeeper.apache.org/doc/trunk/zookeeperOver.html#sc_designGoals.

Step 2: Modify the ZooKeeper configuration file

On one of the machines (CentOS1), unzip zookeeper-3.3.6.tar.gz, and modify the configuration file conf/zoo.cfg as follows:

For the description of the above configuration content, you can refer to http://zookeeper.apache.org/doc/trunk/zookeeperStarted.html#sc_RunningReplicatedZooKeeper.

Step 3: Remotely copy and distribute installation files

ZooKeeper has been configured on a machine CentOS1 above, and now the configured installation file can be remotely copied to the directory corresponding to each node in the cluster:

cd /application/tools/zookeeper-3.3.6  
scp -r /application/tools/zookeeper-3.3.6 root@CentOS2:/application/tools  
scp -r /application/tools/zookeeper-3.3.6 root@CentOS3:/application/tools

Step 4: Set up myid

Under the directory specified by the dataDir we configured, create a myid file, which contains a number to identify the current host. What is the number of X in server.X configured in the conf/zoo.cfg file, then enter the myid file. this number

Step 5: Start the ZooKeeper cluster

On each node of the ZooKeeper cluster, execute the command zkServer.sh start to start ZooKeeper, and check the startup log file zookeeper.out after startup. If no error is reported, the startup is normal.

 

Possible exceptions:

Processing: Turn off the CentOS firewall

 

 

Reference: http://blog.csdn.net/shirdrn/article/details/7183503 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326990002&siteId=291194637