Single deployment

1. Download and decompress

2. Configure the conf/zoo. CFG

DataDir =/var/lib/zookeeper dataDir=/var/lib/zookeeper dataDir=/var/lib/zookeeper DataLogDir =/var/lib/log ## dataDir clientPort=2181 ## dataLogDir=/var/lib/log ## InitLimit =5 ##The number of ticks that The initial synchronization phase can take syncLimit=2 ##The number of ticks that can pass between sending a request and getting an acknowledgment#Zookeeper after 3.4.0 version provides the function of automatic cleaning the snapshot and transaction log by configuring autopurge. SnapRetainCount and autopurge purgeInterval these two parameters can achieve regularly cleaned. Both parameters are configured in zoo.cfg: zoo.cfg
#PurgeInterval Specifies the cleaning frequency, in hours. The value must be an integer of 1 or greater. The default value is 0, indicating that self-cleaning is disabled.
#Autopurge. SnapRetainCount the parameters and the collocation of use, this parameter specifies the number of files should be preserved. The default is 3.Autopurge) snapRetainCount = 60 autopurge) purgeInterval = 48 # keep within 48 hours of log, and reserved 60 file (experience certificate shall be valid for the configuration)## Cluster configuration 
#The id is called the Server ID, which identifies the number of the machine in the cluster
#Host indicates the IP address of the machine
#Port1 Specifies the port used by the Follower server to communicate and synchronize data with the Leader server
##port2 Is used for voting communication during the Leader election.
server.1=IP1:2888:3888
server.2=IP2:2888:3888
server.3=IP3:2888:3888
## create a myID file in the dataDir directory of each machine. The file contents are the corresponding Server ID number of the machine
Copy the code

3. Start

./bin/zkServer.sh start

4. Check the status

./bin/zkServer.sh status

5. Test

./bin/zkCli.sh ls / create /zkPro myData get /zkPro set /zkPro myData2 get /zkPro delete /zkPro quit

Remote machine./bin/ zkcli. sh -server IP :port

Cluster deployment

configuration

Server. 1 = 172.17.0.4:2888-3888 for server 2 = 172.17.0.5:2888:3888 server. 3 = 172.17.0.6:2888-3888Copy the code

echo 1 > /tmp/zookeeper/myid [toc]

Zookeeper Transaction log

Java – cp. / lib/zookeeper – 3.4.6. Jar: lib/log4j – 1.2.17. Jar: lib/slf4j – log4j12-1.7.5. Jar: lib/slf4j – API – 1.7.7. Jar org.apache.zookeeper.server.LogFormatter data/zookeeper/version-2/log.1

Java – cp. / lib/zookeeper – 3.4.6. Jar:. / lib/slf4j – API – 1.6.1. Jar org. Apache. The zookeeper. Server SnapshotFormatter snapshot. 17

java -cp . / lib/zookeeper – 3.6.1. Jar: lib/log4j – 1.2.17. Jar: lib/slf4j – log4j12-1.7.25. Jar: lib/slf4j – API – 1.7.25. Jar:. / lib/zookeeper – jut E – 3.6.1. Jar org. Apache. Zookeeper. Server SnapshotFormatter/TMP/zookeeper/version – 2 / snapshot. 200000015

java -cp . / lib/zookeeper – 3.6.1. Jar: lib/log4j – 1.2.17. Jar: lib/slf4j – log4j12-1.7.25. Jar: lib/slf4j – API – 1.7.25. Jar:. / lib/zookeeper – jut E – 3.6.1. Jar org. Apache. Zookeeper. Server LogFormatter/TMP/zookeeper/version – 2 / log. 100000001

[root@zk01 apache-zookeeper-3.6.1-bin]# Java -cp./lib/*:./lib/zookeeper-3.6.1.jar org.apache.zookeeper.server.SnapshotFormatter /tmp/zookeeper/version-2/snapshot.200000015 ZNode Details (count=8): /---- / cZxid = 0x00000000000000 ctime = Thu Jan 01 08:00:00 CST 1970 mZxid = 0x00000000000000 mtime = Thu Jan 01 08:00:00 CST 1970 pZxid = 0x00000100000005 cversion = 1 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x00000000000000  dataLength = 0 /---- /zookeeper cZxid = 0x00000000000000 ctime = Thu Jan 01 08:00:00 CST 1970 mZxid = 0x00000000000000 mtime = Thu Jan 01 08:00:00 CST 1970 pZxid = 0x00000000000000 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner  = 0x00000000000000 dataLength = 0 /---- /zookeeper/config cZxid = 0x00000000000000 ctime = Thu Jan 01 08:00:00 CST 1970  mZxid = 0x00000000000000 mtime = Sat Jan 16 11:28:05 CST 2021 pZxid = 0x00000000000000 cversion = 0 dataVersion = -1 aclVersion = -1 ephemeralOwner = 0x00000000000000 dataLength = 135 /---- /zookeeper/quota cZxid = 0x00000000000000 ctime  = Thu Jan 01 08:00:00 CST 1970 mZxid = 0x00000000000000 mtime = Thu Jan 01 08:00:00 CST 1970 pZxid = 0x00000000000000 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x00000000000000 dataLength = 0 /---- /test cZxid = 0x00000100000005 ctime = Thu Jan 14 20:39:35 CST 2021 mZxid = 0x00000100000006 mtime = Thu Jan 14 20:45:15 CST 2021 pZxid = 0x00000100000007 cversion = 1 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x00000000000000 dataLength = 4 [root@zk01 apache-zookeeper-3.6.1-bin]# Java -cp./lib/*:./lib/zookeeper-3.6.1.jar org.apache.zookeeper.server.LogFormatter /tmp/zookeeper/version-2/log.900000001 ZooKeeper Transactional Log File with Dbid 0 TXnlog Format Version 2 21-1-16 10:20:24 SEC Session 0x100004D11A80000 CXID 0x0 zxID 0x900000001 createSession 30000 2 12423198993 21-1-16 10:24:47 PM Session 0x100004D11A80003 CXID 0x3 ZXID 0x900000008 Create '/ zk_test, # 6 d795f64617461, v {s {31, s {' world,' something}}}, F, 2, 2150417933Copy the code

Check the zookeeper state

Usage: ./bin/zkServer.sh [–config ] {start|start-foreground|stop|version|restart|status|print-cmd}

command

./bin/zkCli.sh -server host:port -client-configuration properties-file cmd args

get -s /testNode Data Content cZxid = 0x20000000e ctime = Thu Jun 30 20:41:55 HKT 2016 mZxid = 0x20000000e mtime = Thu Jun 30 20:41:55 HKT 2016 pZxid = 0x20000000e cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 4 numChildren = 0Copy the code
  • The version number:

• datspanning dataVersion number, set operation, incremented by 1. •cversion Version of a child node. When the child node changes, increase by 1. •aclVersion Version of an ACL.

If the version specified in the ZK operation is different from the current version, the operation fails.

  • Transaction ID:

Each change produces a unique Transaction ID, zxID (ZooKeeper Transaction ID). Using the zxID, you can determine the sequence of update operations.

  • cZxid

Transaction ID created by Znode.

  • mZxid

The transaction ID of Znode to be modified, that is, the mZxid is updated every time Znode is modified.

Zxid is a 64-bit number with 32 bits higher than the epoch used to identify whether the leader relationship has changed. Each time a leader is elected, it will have a new epoch, identifying the current reign period of the leader.

The lower 32 bits are used to increment the count (the lower 32 bits, starting at 0, indicate the transaction number during the leader’s reign).

[zk: 127.0.0.1:2181(CONNECTED) 2] stat -w/seQ0000000007 cZxid = 0x900000064 cTime = Sat Jan 16 22:56:28 CST 2021 mZxid = 0x900000064 mtime = Sat Jan 16 22:56:28 CST 2021 pZxid = 0x900000064 cversion = 0 dataVersion = 0 aclVersion = 0 EphemeralOwner = 0x0 dataLength = 5 numChildren = 0 [ZK: 127.0.0.1:2181(CONNECTED) 4] delete /seq0000000007 WATCHER:: WatchedEvent state:SyncConnected type:NodeDeleted path:/seq0000000007Copy the code

create -e -s /test_ephemerol_seq