[4] zookeeper Getting basic components (b) cluster information management, metadata, node information

Second, the role of ZooKeeper

1.1 Configuration Management

In our application in addition to the code, there are some that various configurations. Such as database access. Generally, we all use the configuration file, the introduction of these profiles in your code. When we only have one configuration, only one server, and do not often modified, use the configuration file is a good practice, but if we configure very large, there are many servers need this configuration, then use the configuration file not a good idea. This time is often needed to find a way to centrally manage the configuration, we have modified the configuration in this central place, all interested can obtain changes to this configuration. Zookeeper is this service that uses Zab This consistency protocol to provide consistency. There are many open source projects use Zookeeper to maintain your configuration, such as HBase, the client is connected to a Zookeeper, HBase obtain configuration information necessary for the cluster, then it can be further manipulated. There are open source message queue Kafka is also used to maintain information broker of Zookeeper. In the open source SOA framework Dubbo Alibaba is also widely used Zookeeper some configuration management to implement service governance.

1.2 Name Service

The name of the service very good understanding. For example, in order to access the system via a network, we have to know each other's IP address, but IP addresses of people very unfriendly, this time we need to use the domain name to access. But the computer is not a domain name. How to do it? If we are provided with each machine in a domain name to IP address mapping, this touches can solve part of the problem, but if the domain name corresponding to the IP changes how should we do? So we have this thing DNS. We just need a well-known access point (known), and it will tell you what the domain name corresponding IP Yes. In our application will exist in many of these issues, especially in a particularly large number of our services, if we save the address of the service in the local time will be very inconvenient, but if we only need to access one we are all familiar access point, here to provide a unified entrance, then it will be much more convenient to maintain.

1.3 Distributed Lock

In fact, in the first article it has been introduced Zookeeper is a distributed coordination services. So that we can take advantage of Zookeeper to coordinate activities between multiple distributed processes. For example, in a distributed environment, in order to improve reliability on every server in our cluster are deployed with the same service. However, one thing if the cluster each server were, then we should coordinate with each other, it will be very complicated programming. And if we just let a service operation, and that there is a single point. Another usual practice is to use a distributed lock, at some point just to let a service

Work, when this service go wrong lock release, immediately fail over to another service. This is done in many distributed systems, this design has a name better listen Leader Election (leader election). For example, the HBase Master is using this mechanism. But it should be noted that the distributed lock with a lock with a process or a difference, so when using the same process than the more cautious use of the lock.

1.4 Cluster Management

In a distributed cluster, often due to various reasons, such as hardware failures, software failures, network problems, some nodes will be coming and going. There are new node to join in, but also the old node from the cluster. This time, the other machines in the cluster need to perceive this change and make the corresponding decisions based on this change. For example, we are a distributed storage system, there is a central allocation is responsible for storing the control node, we want to allocate storage node based on the current state of the cluster now when there is a new store coming in. This time we need to dynamically sense the current state of the cluster. Also, such a distributed SOA architecture, the service is provided by a cluster, when consumers visit a service, you need to use some kind of mechanism to find which nodes can now provide the service (which is also known as Service We found, such as open source SOA framework Dubbo Alibaba on the use of the underlying mechanism of service discovery as a Zookeeper). There are open-source Kafka queue on the use of upper and lower Zookeeper as Cosnumer management.

 

Zookeeper use (znode of view, delete, etc.)

Use client Command Operation zookeeper

cd /usr/local/zookeeper/bin

./zkCli

1, use the ls command to view the contents contained in the current ZooKeeper


 

2. Create a new znode, using the create / zkPro myData

3, again using the ls command to view the contents contained in the zookeeper now:

4, we run the following command to get confirmation znode the second step created contains the string we created:

5, let set zk of the string associated with the set command:

6, below we will delete znode just created (rmr also OK)

 

Reference documents:

https://blog.csdn.net/java_66666/article/details/81015302

https://zookeeper.apache.org/doc/r3.4.14/zookeeperOver.html

https://zhuanlan.zhihu.com/p/72902467

Guess you like

Origin www.cnblogs.com/Agnes1994/p/12217954.html