zookeeper Download: http: //mirror.bit.edu.cn/apache/zookeeper/
Download bin under the source asked not to download the source files sometimes can not find the class
apache-zookeeper-3.6.0-bin.tar.gz
Cluster Planning 1.1
Zookeeper deployed on linux1, linux2 and linux3 three nodes, three nodes have been installed jdk.
Configure ssh key free dense Login
1. First configure the hosts file
vim /etc/hosts
192.168.10.11 linux1 192.168.10.12 linux2 192.168.10.13 linux3
2. Generate ssh rsa
第一台机器
[@linux1 conf]$ ssh-keygen -t rsa
[hadoop@linux1 conf]$ ssh-copy-id linux2
[hadoop@linux1 conf]$ ssh-copy-id linux3
第二台机器
[hadoop@linux2 conf]$ ssh-keygen -t rsa
[hadoop@linux2 conf]$ ssh-copy-id linux1
[hadoop@linux2 conf]$ ssh-copy-id linux3
第三台机器
[hadoop@linux3 conf]$ ssh-keygen -t rsa
[hadoop@linux3 conf]$ ssh-copy-id linux1
[hadoop@linux3 conf]$ ssh-copy-id linux2
1.2 Extracting installation
tar -zxvf apache-zookeeper-3.6.0-bin.tar.gz -C /opt/module/<br>mv /opt/module/apache-zookeeper-3.6.0-bin /opt/module/apache-zookeeper-3.6.0
Data created in this directory /opt/module/apache-zookeeper-3.6.0/
[hadoop@linux1 apache-zookeeper-3.6.0]$ mkdir Data
Modify the file name
mv zoo_sample.cfg zoo.cfg
1.3 configuration file zoo.cfg
Specific configuration, modify dateDir, add a log store directory
ataDir=/opt/module/apache-zookeeper-3.6.0/Data
dataLogDir=/opt/module/apache-zookeeper-3.6.0/Data/logs
In the end increase
server.1=linux1:2888:3888 server.2=linux2:2888:3888 server.3=linux3:2888:3888
1.4 Cluster Configuration
(1) create a file in /opt/module/apache-zookeeper-3.6.0/Data myid directory
[hadoop@linux1 Data]$ touch myid
(2) editing myid file server to add the corresponding number in the file: The 1
[Hadoop @ linux1 Data] $ vi myid
wq save and exit
[hadoop@linux1 module]$ scp -r apache-zookeeper-3.6.0/ hadoop@linux2:/opt/module/ [hadoop@linux1 module]$ scp -r apache-zookeeper-3.6.0/ hadoop@linux3:/opt/module/
They are set linux1 and linux2 of myid file
[hadoop@linux1 module]$ ssh linux2 Last login: Tue Mar 24 11:32:24 2020 from linux1 [hadoop@linux2 ~]$ echo 2 > /opt/module/apache-zookeeper-3.6.0/Data/myid [hadoop@linux2 ~]$ cat /opt/module/apache-zookeeper-3.6.0/Data/myid 2 [hadoop@linux2 ~]$ exit logout Connection to linux2 closed. [hadoop@linux1 module]$
[hadoop@linux1 module]$ ssh linux3 Last login: Mon Mar 23 14:15:50 2020 [hadoop@linux3 ~]$ echo 3 > /opt/module/apache-zookeeper-3.6.0/Data/myid [hadoop@linux3 ~]$ cat /opt/module/apache-zookeeper-3.6.0/Data/myid 3 [hadoop@linux3 ~]$ exit logout Connection to linux3 closed. [hadoop@linux1 module]$
Start Cluster 1.5
[hadoop@linux1 apache-zookeeper-3.6.0]$ ./bin/zkServer.sh start ZooKeeper JMX enabled by default Using config: /opt/module/apache-zookeeper-3.6.0/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [hadoop@linux1 apache-zookeeper-3.6.0]$ ssh linux2 Last login: Tue Mar 24 11:33:58 2020 from linux1 [hadoop@linux2 ~]$ /opt/module/apache-zookeeper-3.6.0/bin/zkServer.sh start ZooKeeper JMX enabled by default Using config: /opt/module/apache-zookeeper-3.6.0/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [hadoop@linux2 ~]$ exit logout Connection to linux2 closed. [hadoop@linux1 apache-zookeeper-3.6.0]$ ssh linux 2 ssh: Could not resolve hostname linux: Name or service not known [hadoop@linux1 apache-zookeeper-3.6.0]$ ssh linux3 Last login: Tue Mar 24 11:35:38 2020 from linux1 [hadoop@linux3 ~]$ /opt/module/apache-zookeeper-3.6.0/bin/zkServer.sh start ZooKeeper JMX enabled by default Using config: /opt/module/apache-zookeeper-3.6.0/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [hadoop@linux3 ~]$ exit logout Connection to linux3 closed. [hadoop@linux1 apache-zookeeper-3.6.0]$
1.6 Configuration Environment Variables
vi /etc/profile
export ZOOKEEPER_HOME=/opt/module/apache-zookeeper-3.6.0 export PATH=$PATH:$ZOOKEEPER_HOME/bin
source /etc/profile
1.7zoo.cfg configuration parameters interpretation
Server.A=B:C:D。
A is a number, it indicates that the server is the first few numbers;
B is the ip address of the server;
C is the port of the server in the cluster Leader servers to exchange information;
D is the case in the cluster Leader server being down, needs a port to re-election to elect a new Leader, and this port is the port used to perform mutual communication server election.
A configuration file myid trunked mode, the file in the directory dataDir, this document there is a data value A, this file is read when the start Zookeeper, get configuration information with the data inside the comparison to determine which zoo.cfg in the end is which server.
1) tickTime = 2000: Communication heartbeats
tickTime: heart rate communication, the Zookeeper server heartbeat time, in milliseconds
Zookeeper basic time use, or the server is maintained between client and server heartbeat time interval, i.e. each time tickTime will send a heartbeat, the time in milliseconds.
It heartbeat mechanism is used, and set the minimum session timeout is twice the heartbeat time. (Minimum session timeout is 2 * tickTime)
2) initLimit = 10: LF initial communication time
Maximum number of heartbeats between cluster server follower follower (F) to the server leader the leader (L) when the initial connection tolerable (number of tickTime), which is defined by the cluster server is connected to Zookeeper Leader of time.
Voting to elect a new leader of the initialization time
Follower during startup, will synchronize all the latest data from the Leader, then they can determine the initial state of the external services.
Leader allows F to complete this work within initLimit time.
3) syncLimit = 5: LF synchronous communication time
Cluster units between the maximum response time Leader and Follower, if the response exceeds syncLimit * tickTime,
Leader believes Follwer dead, Follwer deleted from the server list.
During operation, Leader responsible for communication with the ZK all the machines in the cluster, for example, through a number of heartbeat mechanism to detect the survival of the state of the machine.
After issuing a heartbeat if L package syncLimit, has not received a response from F that, then that is no longer the F line up.
4) dataDir: data file directory path + data persistence
Save in-memory database snapshot information, if not stated otherwise, the update transaction log is also saved to the database.
5) clientPort = 2181: Client port
Port to listen for client connections
II. Client command-line operation
1) Start the client
[hadoop@linux1 opt]$ zkCli.sh