download link
https://archive.apache.org/dist/zookeeper/zookeeper-3.5.6/
According to first download zookeeper learning amended, zoo.cfg file but still there org.apache.zookeeper.server.quorum.QuorumPeerMainm, and other modifications do not see Baidu to no avail, and finally found on google to find the original zookeeper 3.5.5 download package after time with bin should download the file, while the average of the previous tar.gz package which is not just a source of direct use
Reference documents:
https://www.jianshu.com/p/ed6ec88b01c3
Installation Environment
system version |
centos7.7 |
zookeeper version |
apache-zookeeper-3.5.6-bin.tar.gz |
jdk version |
openjdk1.8 |
Detailed configuration parameters (mainly% ZOOKEEPER_HOME% / conf / zoo.cfg file)
https://www.cnblogs.com/xiohao/p/5541093.html
Zookeeper directory structure
Bin 1. : place the tools and scripts to run the script, if it is Linux environment there will be a zookeeper 's operation log lines zookeeper.out
Conf 2. : ZooKeeper default configuration directory read, there will be the default configuration file
Contrib 3. : ZooKeeper expansion capabilities
Dist-maven 4. : ZooKeeper the maven package directory
Docs 5. : ZooKeeper related documents
Lib 6. : ZooKeeper core jar
Recipes 7. : ZooKeeper distributed related jar package
The src 8. The : ZooKeeper source
zookeeper single point of installation
First install openjdk
yum install java-1.8.0-openjdk java-1.8.0-openjdk-devel
Download package zookeeper
wget https://archive.apache.org/dist/zookeeper/zookeeper-3.5.6/apache-zookeeper-3.5.6-bin.tar.gz
tar xf apache-zookeeper-3.5.6-bin.tar.gz
mv apache-zookeeper-3.5.6-bin /usr/local/
cd /usr/local/
ln -s /usr/local/apache-zookeeper-3.5.6-bin/ zookeeper
Configuration environment variable
vim /etc/profile
export PATH=$PATH:/usr/local/zookeeper/bin/
source /etc/profile
vim /etc/profile
Configuring the system environment variables jdk
JAVA_HOME=/usr/local/java/jdk1.8
JRE_HOME=/usr/local/java/jdk1.8/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export JAVA_HOME JRE_HOME PATH CLASSPATH
Create a log log directory
mkdir / usr / local / zookeeper / log_snapshot # snapshot log directory
mkdir / usr / local / zookeeper / log_transaction # transaction log directory
Enter the conf directory
cd /usr/local/zookeeper/conf
change name
cp zoo_sample.cfg zoo.cfg
Specific parameters are as follows:
The main need to configure
dataDir=/usr/local/zookeeper/log_snapshot
dataLogDir=/usr/local/zookeeper/log_transaction
Zookeeper start
Service management commands: zkServer.sh start | stop | restart | status
Connection Client
Client connection: zkCli.sh -server $ {ip}: $ {port}
zkCli.sh -server 10.77.20.23:2181
Client Close: quit or press Ctrl + C
zookeeper port is 2181
ZK There are several types of nodes, node type was determined when the node is created and can not be changed
Temporary node (EPHEMERAL): temporary created node session ends automatically deleted, you can also manually delete the temporary node can not have children
Temporal order node (EPHEMERAL_SEQUENTIAL): wherein a node having a temporary, but it will have a serial number, that will be used in a distributed lock type node
Persistent node (PERSISTENT): After creating permanent, unless the initiative to remove.
Persistent order of nodes (PERSISTENT_SEQUENTIAL): After creating a persistent node, with respect to the persistent node which automatically adds a 10-digit serial number to the node name, the parent node of the count for this node only, if the sequence number is greater than 2 ^ 32-1 will overflow.
zookeeper create a node
-s the Create / the Test ZK- 123 # -e argument for the creation of a temporary node, if no parameter is created enduring # node node name for the node's content
View node content
get /zk-test
Delete Node
delete / zk
connect host: port - connect to other ZooKeeper applications.
ls path - a list of resources in the path. In the ZooKeeper client console, not the default list, you must specify the location to the list of resources. Such as: ls /; ls / path like.
create [-e] [-s] path data - create a node, such as:
Create / test 123 to create a / test node , the node 123 carries data information.
create -e / test 123 to create a temporary node / the Test , carry data 123, the temporary node is only valid in the current session life cycle, node session ends automatically deleted.
create -s / test 123 to create a sequence of node / Test , 123 carrying data, created by the order of the nodes of the node is automatically increased ZooKeeper suffix information, such as - / test00000001 like. -e and -s parameter can be used in combination.
get path - to view a specific node . Such as: get / test. The results are as follows:
set path data [version] - position data set corresponding to the node . Such as: set / test 'test data' . If there is data to be set in the space, data defining a range of single quotation marks are used. After each data modification, dataVersion property increment. You can specify the version in the set command, version data must be consistent with the value of the last query is used to ensure that when this revision command, no other sessions modify this data.
delete path [version] - Removes the specified node , this command can not delete the child node. Such as: delete / test. Wherein the parameter version and version of the set command meaning consistent rmr path - delete the specified node includes sub-nodes.
quit - quit the console
Cluster Setup
Node within the cluster as long as no dang cut in half, zookeeper would not be a problem, etc. So, the more nodes, the more security
Add at each node
vim /usr/local/zookeeper/conf/zoo.cfg
server.1=172.26.103.56:2881:3881
server.2=172.26.103.57:2881:3881
server.3=172.26.103.58:2881:3881
service.N=YYY:A:B
N: represents the server ID (i.e., inside myid value)
YYY: Server Address
A: represents a communication port with Flower Leader, the internal communication port referred to as server (default 2888)
B: representation electoral port (default is 3888)
Add myid within the directory dataDir set in the configuration files in each node zookeeper
echo 1 >myid
echo 2 >myid
echo 3 >myid
Start each node
/usr/local/zookeeper/bin/zkServer.sh start
Check the status of each node role
/usr/local/zookeeper/bin/zkServer.sh status
Optimization; add environment variables
export PATH=$PATH:/usr/local/zookeeper/bin/
About zookeeper occupied port 8080
Recent versions zookeeper There is a built-in management console is started by jetty, will take up 8080 port.
By looking zookeeper official documents, we found there are three ways to solve:
(1) Delete the jetty.
(2) modify the port.
Modification method of two ways, one is in the startup script to increase -Dzookeeper.admin.serverPort = your port number. One is the increase in zoo.cfg in admin.serverPort = port number is not occupied
(3) disable this service, increase "-Dzookeeper.admin.enableServer = false" in the startup script