Zookeeper
What is Zookeeper?
Official website portal
ZooKeeper is a Distributed, open source distributed application coordination service, an open source implementation of Google’s Chubby, and an important component of Hadoop and Hbase. It is a software that provides consistent services for distributed applications. The functions provided include: configuration maintenance, domain name services, distributed synchronization, group services, etc.
From the perspective of design mode, the distributed service management framework based on the observer mode design stores the data that everyone cares about, and then accepts the observer’s registration. Once the status of these data changes, zookeeper will be responsible for notifying the registered observers to respond.
Zookeeper installation
Mirror link
Zookeeper installation It’s very simple, just download the compressed package and unzip it.
Extracted directory:
p>
There are several important file directories to pay attention to. The zookeeper command operation file is stored in bin, and conf is the configuration.
1 # The number of milliseconds of each tick
2 tickTime=2000 heartbeat time
3 # The number of ticks that the initial
4 # synchronization phase can take
5 initLimit=10 Initial connection time, connection fails 10 times after this time * tickTime
6 # The number of ticks that can pass between
7 # sending a request and getting an acknowledgement
8 syncLimit=5 Data synchronization time 5 * tickTime 9 # the directory where the snapshot is stored.
10 # do not use /tmp for storage, /tmp here is just
11 # example sakes.
12 dataDir=/tmp/zookeeper The data storage directory is usually changed during development13 # the port at which the clients will connect
14 clientPort=2181 Initial default port
15 # the maximum number of client connections.
16 # increase this if you need to handle more clients
17 #maxClientCnxns=60
18 #
19 # Be sure to read the maintenance section of the
20 # administrator guide before turning on autopurge.
< span style="color: #008080">21 #
22 # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
23 #
24 # The number of snapshots to retai n in dataDir
25 #autopurge.snapRetainCount=3
26< /span> # Purge task interval in hours
27 # Set to "0" to disable auto purge feature
28 #autopurge.purgeInterval=1
29 ~
30 ~
< /p>
Modify the zoo_simple.cfg under the conf file to zoo.cfg< /p>
- Then enter zookeeper/ bin/下
Windows uses zkServer.cmd to start the service zkCli.cmd to start the client,
Linux is used./zkService .sh start starts the service./zkCli.sh start starts the service
< /p>
You can also use the four-character command to view
echo ruok | nc localhost 2181
appears imok means it is activated
So we have installed zookeeper
zookeeper data structure
The data structure of zookeeper is very similar to the file system, but there is no directory in zookeeper. the concept of. Each structure in zookeeper becomes a znode (zookeeper node).
< /p>
/app1, etc. is the path PATH
A small amount of data can be stored in each Znode node. The explanation of the official website is (ZooKeeper aims to store coordination data: status information, configuration, location information, etc., so The data stored in each node is usually very small, in the range of bytes to kilobytes.)
By
create /amber hahaha
You can create a PATH Znode node with /amber value hahaha
get /amber
We can see it in the first line by get /amber The value of znode ”hahaha”
The orange part is collectively referred to as the Stat structure, which describes the current znode information
hahaha //value of znode
cZxid = 0x1d //The transaction id of creating znode ctime = Mon Dec 03 23:19:30 CST 2018 / /Created time mZxid = 0x1d //Modify the transaction id of znode mtime = Mon Dec 03 23:19:30 CST 2018 //modification time pZxid = 0x1d cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 6 //length of value numChildren = 0 //Number of child nodes
In addition, you can view zookeeper operation commands through help
1 # The number of milliseconds of each tick
2 span> tickTime=2000 heartbeat time
3 # The number of ticks that the initial
4 # synchronization phase can take
5 initLimit=10 Initial connection time, connection fails 10 times after this time * tickTime
6 # The number of ticks that can pass between
7 # sending a request and getting an acknowledgement
8 syncLimit=5 Data synchronization time 5 * tickTime
9 # the directory where the snapshot is stored.
10 # do not use /tmp for storage, /tmp here is just
11< /span> # examp le sakes.
12 dataDir=/tmp/zookeeper The data storage directory is usually changed during development13 # the port at which the clients will connect
14 clientPort=2181 Initial default port
15 # the maximum number of client connections.
16 # increase this if you need to handle more clients
17 #maxClientCnxns=60
18 #
19 span> # Be sure to read the maintenance section of the
20 # administrator guide before turning on autopurge.
21 #
22 # http: //zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
23 #
24< /span> # The number of snapshots to retain in dataDir
25 #autopurge. snapRetainCount=3
26 # Purge task interval in hours
27 # Set to "0" to disable auto purge feature
28 #autopurge.purgeInterval=129 ~
30 ~
echo ruok | nc localhost 2181
create /amber hahaha
get /amber
hahaha //value of znode
cZxid = 0x1d //The transaction id that created the znode ctime = Mon Dec 03 23:19:30 CST 2018 //Created time mZxid = 0x1d //Modify the transaction id of znode mtime = Mon Dec 03 23:19:30 CST 2018 //Modification time pZxid = 0x1d cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 6 //value length numChildren = 0 //Number of child nodes