Zookeeper is actually developed by Yahoo and is used as a framework for consistent processing in distributed applications. It was originally a by-product of the development of Hadoop. Due to the difficulty of consistency processing in distributed systems, other distributed systems do not need to laboriously reinvent the wheels, so zookeeper is widely used in subsequent distributed systems, so that zookeeper has become the basic component of various distributed systems. The importance of status can be imagined. The famous hadoop, kafka, dubbo are all based on zookeeper.
To understand what zookeeper does, you must first understand clearly what is consistency? **
The so-called consistency actually revolves around "seeing". Who can see? Can you see it? When did you see it? For example: Taobao backend sellers put a big promotion item in the backend and submit it to the main database through server A. Assuming that immediately after submission, there are users who go to query the item from the database through application server B, and a Phenomenon, the seller has successfully updated, but the buyer can't see it; and after a period of time, the data in the master database is synchronized to the slave database, and the buyer can check it.
Assuming that the buyer can see the seller’s update immediately after the seller’s update is successful, it is called strong consistency
If the buyer cannot see the content updated by the seller after the seller update is successful, it is called weak consistency**
After the seller is updated successfully, the buyer can finally see the seller's update after a period of time, which is called final consistency
"ZooKeeper Application Scenarios"
"Distributed ZooKeeper Series"
VMware version number: 12.0.0
CentOS version: CentOS 7.3.1611
ZooKeeper version: ZooKeeper-3.4.9.tar.gz
JDK environment: jdk-8u144-linux-x64.tar.gz
JDK 1.8 installation
Specific reference ["CentOs7.3 install JDK1.8"] (https://segmentfault.com/a/1190000010716919)
cd /opt/
wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gz
Or download and upload in the browser to the opt directory
cd /opt/
tar -zxf zookeeper-3.4.9.tar.gz
cd zookeeper-3.4.9
Create a data
folder to store data files
mkdir data logs
Create a logs
folder to store logs
mkdir logs
Use the command vi conf/zoo.cfg
to create a configuration file and open it, ps (in fact, there is a default configuration file under the directory conf
, but there are too many comments, a lot of English, and too messy)
vi /opt/zookeeper-3.4.9/conf/zoo.cfg
The edit content is as follows
tickTime =2000
dataDir =/opt/zookeeper-3.4.9/data
dataLogDir =/opt/zookeeper-3.4.9/logs
tickTime =2000
clientPort =2181
initLimit =5
syncLimit =2
Configuration file description
tickTime
dataDir
dataLogDir
initLimit
syncLimit
/opt/zookeeper-3.4.9/bin/zkServer.sh start
response
ZooKeeper JMX enabled by default
Using config:/opt/zookeeper-3.4.9/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
Connect to ZooKeeper service
/opt/zookeeper-3.4.9/bin/zkCli.sh
response
Connecting to localhost:21812017-08-2216:43:05,954[myid:]- INFO [main:Environment@100]- Client environment:zookeeper.version=3.4.9-1757313, built on 08/23/201606:50 GMT
2017- 08- 2216:43:05,958[ myid:]- INFO [main:Environment@100]- Client environment:host.name=node1
2017- 08- 2216:43:05,958[ myid:]- INFO [main:Environment@100]- Client environment:java.version=1.8.0_144
2017- 08- 2216:43:05,967[ myid:]- INFO [main:Environment@100]- Client environment:java.vendor=Oracle Corporation
2017- 08- 2216:43:05,967[ myid:]- INFO [main:Environment@100]- Client environment:java.home=/usr/lib/jvm/jre
2017- 08- 2216:43:05,967[ myid:]- INFO [main:Environment@100]- Client environment:java.class.path=/opt/zookeeper-3.4.9/bin/../build/classes:/opt/zookeeper-3.4.9/bin/../build/lib/*.jar:/opt/zookeeper-3.4.9/bin/../lib/slf4j-log4j12-1.6.1.jar:/opt/zookeeper-3.4.9/bin/../lib/slf4j-api-1.6.1.jar:/opt/zookeeper-3.4.9/bin/../lib/netty-3.10.5.Final.jar:/opt/zookeeper-3.4.9/bin/../lib/log4j-1.2.16.jar:/opt/zookeeper-3.4.9/bin/../lib/jline-0.9.94.jar:/opt/zookeeper-3.4.9/bin/../zookeeper-3.4.9.jar:/opt/zookeeper-3.4.9/bin/../src/java/lib/*.jar:/opt/zookeeper-3.4.9/bin/../conf:.:/lib/jvm/lib:/lib/jvm/jre/lib
2017- 08- 22 16:43:05,967 [ myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2017- 08- 22 16:43:05,967 [ myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2017- 08- 22 16:43:05,967 [ myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA>
2017- 08- 22 16:43:05,967 [ myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux
2017- 08- 22 16:43:05,967 [ myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64
2017- 08- 22 16:43:05,967 [ myid:] - INFO [main:Environment@100] - Client environment:os.version=3.10.0-514.26.2.el7.x86_64
2017- 08- 22 16:43:05,968 [ myid:] - INFO [main:Environment@100] - Client environment:user.name=root
2017- 08- 22 16:43:05,968 [ myid:] - INFO [main:Environment@100] - Client environment:user.home=/root
2017- 08- 22 16:43:05,968 [ myid:] - INFO [main:Environment@100] - Client environment:user.dir=/opt/zookeeper-3.4.9
2017- 08- 22 16:43:05,969 [ myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@506c589e
Welcome to ZooKeeper!
2017- 08- 22 16:43:06,011 [ myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2017- 08- 22 16:43:06,164 [ myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@876] - Socket connection established to localhost/0:0:0:0:0:0:0:1:2181, initiating session
2017- 08- 22 16:43:06,237 [ myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181, sessionid = 0x15e091bf2020000, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[ zk: localhost:2181(CONNECTED) 0]
/opt/zookeeper-3.4.9/bin/zkServer.sh status
response
ZooKeeper JMX enabled by default
Using config:/opt/zookeeper-3.4.9/bin/../conf/zoo.cfg
Mode: standalone
/opt/zookeeper-3.4.9/bin/zkServer.sh stop
response
bin/zkServer.sh stop
ZooKeeper JMX enabled by default
Using config:/opt/zookeeper-3.4.9/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
CentOs7.3 build ZooKeeper-3.4.9 Cluster cluster service
Recommended Posts