ZooKeeper is a distributed, open source distributed application coordination service. It is an open source implementation of Google's Chubby and an important component of Hadoop and Hbase. This article will share with you the simple use of zookeeper in java. Friends who need it can refer to it
1. The basic principles of zookeeper
data model , as follows:
The structure of the ZooKeeper data model is very similar to the Unix file system. It can be regarded as a tree as a whole, and each node is called Make a ZNode. Each ZNode can be uniquely identified by its path. For example, the first ZNode in the third layer in the above figure has a path of /app1/c1. A small amount of data can be stored on each ZNode (the default is 1M, which can be modified through configuration. It is generally not recommended to store large amounts of data on ZNode). This feature is very useful. In addition, each ZNode also stores its Acl information. It should be noted here that although the tree structure of ZNode is very similar to the Unix file system, its Acl is completely different from the Unix file system. The Acl of each ZNode is independent. , the child node will not inherit the parent node.
ZooKeeper features:
##1. Read and write (update) mode
2, WAL and Snapshot
3. FIFO
4. Linearizability
2. Common commands of zookeeper
We can execute zookeeper-client or /opt/cloudera/parcels/CDH-5.0.0 -1.cdh5.0.0.p0.47/lib/zookeeper/bin/zkCli.sh-server localhost, enter the zookeeper command line, as follows:3. Zookeeper’s javaapi operation
Regarding the Javaapi operation of zookeeper, it is relatively simple. The author directly posted the code, as follows:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
Then, when executed, you can see that the console output is as follows:
So, like some We can save the public configuration in zookeeper, and then other services can use it
Summary
The above is the detailed content of Detailed explanation of the use of zookeeper in java. For more information, please follow other related articles on the PHP Chinese website!