Zookeeper Introduction Zookeeper Distributed service Framework is used to solve some data management problems commonly encountered in distributed applications, such as: Unified Naming Service, State Synchronization service, cluster management, distributed application configuration item management, etc. This paper mainly introduces the installation, configuration and application of zookeeper from the angle of users.
Stand-alone mode
Zookeeper can be installed in a single machine, this application mode is mainly used in the test or demo case, in the production environment is generally not used.
1. You can first download the latest installation package from Zookeeper's official website http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
2. Unzip the zookeeper to the specified directory, which is assumed to be/opt/zookeeper
3. Enter the Conf directory under the Zookeeper directory, copy Zoo_sample.cfg to Zoo.cfg, and modify the contents as follows
Ticktime=datadir=/opt/zookeeper-3.4. 6/dataclientport=2181
Ticktime:zookeeper the heartbeat interval between the server or between the client and the server.
Datadir:zookeeper the directory where the data is stored, by default Zookeeper log files that write the data are also stored in this directory.
Clientport:zookeeper server listening port, which is used to accept client access requests.
4. After the configuration, you can start the Zookeeper service, enter the Zookeeper/bin directory, run the following command to start the zookeeper service
DefaultUsing config:/opt/zookeeper/bin/. /conf/zoo.cfgstarting Zookeeper ... STARTED
After you start, you can use the following command to view the service status
defaultusing config:/opt/zookeeper/bin/. /conf/zoo.cfgmode:standalone
5. After the zookeeper server is started, you can use the zookeeper client to connect and test.
$./zkcli.sh or $./zkcli.sh-server 127.0.0.1:2181
After the connection can help to see what commands can be used
[ZK:127.0.0.1:2181 (CONNECTED)0] LS/#查看根节点 [ZOOKEEPER][ZK:127.0.0.1:2181 (CONNECTED)1] create/mykey1 myvalue1#创建一个新节点mykey1Created/MYKEY1[ZK:127.0.0.1:2181 (CONNECTED)2] Create/mykey2 myvalue2#创建一个新节点mykey2Created/MYKEY2[ZK:127.0.0.1:2181 (CONNECTED)LS/#查看根节点 [Mykey1, Mykey2, Zookeeper][zk:127.0.0.1:2181 (CONNECTED)23]Get/mykey1#获取mykey1节点myvalue1cZxid =0x6ctime = Sat Sep2021st:00:CST2014mZxid =0x8mtime = Sat Sep2021st:01:CST2014pZxid =0x6cversion =0dataVersion =1aclVersion =0ephemeralOwner =0x0datalength =9numChildren =0[ZK:127.0.0.1:2181 (CONNECTED)23]Get/mykey2#获取mykey2节点myvalue2cZxid =0x6ctime = Sat Sep2021st:00:CST2014mZxid =0x8mtime = Sat Sep2021st:01:CST2014pZxid =0x6cversion =0dataVersion =1aclVersion =0ephemeralOwner =0x0datalength =9numChildren =0[ZK:127.0.0.1:2181 (CONNECTED) 24] set/ Mykey1 myvalue11 #获取mykey1节点 [ZK: 127.0.0< Span class= "number" >.1:2181 (CONNECTED) 25] set/ Mykey2 myvalue22 #获取mykey2节点 [ZK: 127.0.0< Span class= "number" >.1:2181 (CONNECTED) 26] set/ Mykey1 #删除mykey1节点 [ZK: 127.0.0 .1:2181 (CONNECTED) 27] set/ Mykey2 #删除mykey2节点
Zookeeper in combat mode