I. Download and Unzip
1. Introduction to Zookeeper
As a distributed service framework, Zookeeper is mainly used to solve the consistency problem of application systems in distributed cluster. It can provide data storage based on directory node tree similar to file system. But Zookeeper is not used to store data exclusively. Its function is mainly to maintain and monitor. The state of the data you store changes. By monitoring the changes of these data states, data-based cluster management can be achieved.
2. Download
Environment version
centos7
zookeeper 3.4.14
[root@localhost mysoft]$ cd /usr/local/mysoft/ [root@localhost mysoft]$ wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz [root@localhost mysoft]# tar -zxvf zookeeper-3.4.14.tar.gz [root@localhost mysoft]# mv zookeeper-3.4.14 zookeeper3.4
II. Modification of configuration files
1. Data and log directories
[root@localhost /]# mkdir -p data/log/zkp1.log [root@localhost /]# mkdir -p data/zkpdata/zkp1
2. Modify configuration
[root@localhost mysoft]# cd zookeeper3.4/conf/ [root@localhost conf]# cp zoo_sample.cfg zoo.cfg [root@localhost conf]# vim zoo.cfg # Modify the following two pieces of content, other defaults dataDir=/data/zkpdata/zkp1 dataLogDir=/data/log/zkp1.log
3. Configuration file description
1)tickTime The time of heart rate examination. 2)initLimit The maximum number of heartbeats (tickTime s) that can be tolerated in the initial connection between the slave server and the primary server in the cluster. 3)syncLimit The maximum tolerable heartbeat number of requests and promises between slave and primary servers in a cluster. 4)dataDir Data storage directory. 5)dataLogDir Log storage directory. 6)clientPort The client connects to the port of the zookeeper server, which is monitored by the server by default of 2181.
3. Start-up operation
1. Start the server
[root@localhost bin]# pwd /usr/local/mysoft/zookeeper3.4/bin [root@localhost bin]# /usr/local/mysoft/zookeeper3.4/bin/zkServer.sh start /usr/local/mysoft/zookeeper3.4/conf/zoo.cfg ZooKeeper JMX enabled by default Using config: /usr/local/mysoft/zookeeper3.4/conf/zoo.cfg Starting zookeeper ... STARTED [root@localhost bin]# ps -aux |grep zookeeper
2. Start the client
[root@localhost /]# cd /usr/local/mysoft/zookeeper3.4/bin/ [root@localhost bin]# ./zkCli.sh Connecting to localhost:2181
Common Operating Commands
## Create Nodes [zk: localhost:2181(CONNECTED) 2] create /cicada cicada-smile1 Created /cicada [zk: localhost:2181(CONNECTED) 8] create /cicada2 cicada-smile2 Created /cicada2 [zk: localhost:2181(CONNECTED) 4] get /cicada cicada-smile1 ## View directories [zk: localhost:2181(CONNECTED) 5] ls / [zookeeper, cicada, cicada2] ## View the specified directory [zk: localhost:2181(CONNECTED) 17] ls / zookeeper [com.ptp.user.service.UserService] ## Delete Nodes [zk: localhost:2181(CONNECTED) 10] delete /cicada ## Delete all directories [zk: localhost:2181(CONNECTED) 18] rmr /cicada2 [zk: localhost:2181(CONNECTED) 19] ls /cicada2 Node does not exist: /cicada2 ## View the remaining nodes [zk: localhost:2181(CONNECTED) 13] ls / [zookeeper]
5. Source code address
GitHub Address: Know a smile https://github.com/cicadasmile Code Yun Address: Know a smile https://gitee.com/cicadasmile