ZooKeeper Distributed topics and introduction to Dubbo microservices
An overview of the
Zookeeper is actually a framework developed by Yahoo for consistency processing in distributed environments. It started as a byproduct of Hadoop development. Due to the difficulty of consistency processing in distributed system, there is no need for other distributed systems to make wheels repeatedly. Therefore, ZooKeeper has been widely applied in subsequent distributed systems, so that ZooKeeper has become the basic component of various distributed systems, and its position is of great importance. Well-known hadoop, Kafka, and Dubbo are all built on ZooKeeper.
They are installed
** * Download **Copy the code
Stable version: mirror.bit.edu.cn/apache/zook…
-
Extracting tar files
cdThe/opt/tar - ZXF zookeeper - 3.4.12. Tar. GzcdZookeeper - 3.4.12Copy the code
-
Create a data folder to store data files
mkdir data
-
Create a logs folder to store logs
mkdir logs
-
-
Creating a Configuration File
CFG command to create a configuration file and open it, ps (actually there is a default configuration file under the conf directory, but there are too many comments, so it is better to create a new configuration file, copy zoo_sample. CFG and name it zoo.cfg).
-
Enter the command:
Vi/opt/zookeeper 3.4.12 / conf/zoo. The CFG
-
Edit and fill in the following:
TickTime = 2000 dataDir = /opt/zookeeper-3.4.12/data dataLogDir = /opt/zookeeper-3.4.12/logs tickTime = 2000 clientPort = 2181 initLimit = 5 syncLimit = 2Copy the code
-
They are operating
-
Start the service
-
/ opt/zookeeper 3.4.12 / bin/zkServer. Sh start
-
The response
ZooKeeper JMX enabled by default Using config: /opt/zookeeper-3.4.12/bin/.. /conf/zoo.cfg Starting zookeeper ... STARTEDCopy the code
-
-
Connection service
-
/ opt/zookeeper 3.4.12 / bin/zkCli. Sh
-
The response
Connecting to localhost:2181 2017-08-22 16:43:05.954 [myID :] -info [main:Environment@100] -client Environment: the zookeeper. Version = 3.4.12-1757313, Built on 08/23/2016 06:50 GMT 2017-08-22 16:43:05.958 [myID :] -info [main:Environment@100] -client Environment :host.name=node1 2017-08-22 16:43:05.958 [myID :] -info [main:Environment@100] -client Environment :java.version=1.8.0_144 2017-08-22 16:43:05.967 [myID :] -info [main:Environment@100] -client Environment: Java. vendor=Oracle Corporation 2017-08-22 16:43:05.967 [myID :] -info [main:Environment@100] -client Environment :java.home=/usr/lib/ JVM /jre 2017-08-22 16:43:05.967 [myID :] -info [main:Environment@100] -client Environment: Java. Class. Path = / opt/zookeeper - 3.4.12 / bin /.. / build/classes: / opt/zookeeper - 3.4.12 / bin /.. / build/lib / *. The jar: / opt/zookeeper - 3.4.12 / bin /.. / lib/slf4j - log4j12-1.6.1. Jar: / opt/zookeeper - 3.4.12 / bin /.. / lib/slf4j - API - 1.6.1. Jar: / opt/zookeeper - 3.4.12 / bin /.. / lib/netty - 3.10.5. Final. Jar: / opt/zookeeper - 3.4.12 / bin /.. /lib/log4 j - 1.2.16 jar: / opt/zookeeper - 3.4.12 / bin /.. / lib/jline - 0.9.94. Jar: / opt/zookeeper - 3.4.12 / bin /.. / zookeeper - 3.4.12. Jar: / opt/zookeeper - 3.4.12 / bin /.. / SRC/Java/lib / *. The jar: / opt/zookeeper - 3.4.12 / bin /.. / conf: : / lib/JVM/lib/lib/jre/lib/JVM 16:43:05 2017-08-22, 967 [myid:] - INFO [main: Environment @ 100] - the Client Environment: Java. Library. The path = / usr/Java/packages/lib/amd64: / usr/lib64: / lib64: / lib: / usr/lib 16:43:05 2017-08-22, 967 [myid:] - INFO [main: Environment @ 100] - Client Environment: Java. IO. Tmpdir = / TMP 16:43:05 2017-08-22, 967 [myid:] - INFO [main: Environment @ 100] - Client environment:java.com piler = < 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] 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.12 2017-08-22 16:43:05.969 [myID :] -info [main:ZooKeeper@438] - Initiating the virtual state 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, Virtual 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] Copy the code
-
-
Service status
-
/ opt/zookeeper 3.4.12 / bin/zkServer. Sh status
-
The response
ZooKeeper JMX enabled by default Using config: /opt/zookeeper-3.4.12/bin/.. /conf/zoo.cfg Mode: standaloneCopy the code
-
-
Stop the service
-
/ opt/zookeeper 3.4.12 / bin/zkServer. Sh stop
-
The response
Bin/zkserver. sh stop ZooKeeper JMX enabled by default Using config: /opt/zookeeper-3.4.12/bin/.. /conf/zoo.cfg Stopping zookeeper ... STOPPEDCopy the code
-
Zookeeper installation is complete.
Install the ZooKeeper image
The docker mirror installation reference: segmentfault.com/a/119000000…
The ZooKeeper cluster is installed
Zookeeper cluster installation see: segmentfault.com/a/119000001…
Describes the ZooKeeper configuration file
-
tickTime
TickTime is the basic unit of the preceding two timeout configurations. For example, if the value of initLimit is 5, the timeout duration is 2000ms x 5 = 10 seconds.
-
dataDir
The configuration is similar to that in single-machine mode, except that there is a myID file in cluster mode. The myID file contains only one line and can contain only a number between 1 and 255. This number is the ID of the ZK process described above in server.id.
-
dataLogDir
If not provided, dataDir is used. Zookeeper persistence is stored in these two directories. DataLogDir is the sequential log (WAL) for placing. The dataDir contains a snapshot of the in-memory data structure for quick recovery. To maximize performance, it is recommended that dataDir and dataLogDir be placed on different disks to take full advantage of the sequential write feature of disks.
-
initLimit
In ZooKeeper cluster mode, there are multiple ZK processes, one of which is the leader and the other is the follower. When the follower is initially connected to the leader, a large amount of data is transmitted between the two processes. In particular, the data of the follower is much less than that of the leader. InitLimit Configures the maximum time for synchronization between the follower and the leader after a connection is established
-
syncLimit
Set the maximum duration for sending messages, requests, and replies between followers and the leader.
This section describes the main directory of the ZooKeeper folder
-
bin
Into the bin directory will see that zkCleanup. Sh, zkCli. CMD, zkCli. Sh, zkServer. CMD, zkServer. Sh, etc. The main run commands, where the end of CMD is a command to run on Windows and sh is a command to run on Linux /Mac
-
conf
This is where the configuration files are stored. If you go into the conf directory, Configuration. The XSL, log4j. The properties and zoo_sample. CFG file, two of them do not do introduction, here only focus on zoo_sample. CFG, mentioned earlier will zoo_sample. CFG copy and rename as zoo. CFG;
-
contrib
Some additional features
-
dist-maven
MVN compiled directory, POM files, JAR packages, etc
-
docs
A place to store documents,index.html, or index.pdf
-
lib
The jar package you need to depend on
-
recipes
Keep some cases
-
src
A place where source code is stored
ZooKeeper Distributed topics and introduction to Dubbo microservices