ZK is a distributed service framework that provides the basic services for coordinating distributed applications, and theZK cluster is primarily to ensure the reliability and stability of the service, introduce the installation and configuration of the cluster, and install the JDK before installation. ,install thejdk Online to find the appropriate method
First, the download of zookeeper
after the download is complete, winscp Tools will be zookeeper-3.4.6.tar.gz upload to centos /usr/local/src directory
Second, Decompression and installation of zookeeper
1. Connect CentOSwith the Putty tool and enter the zookeeper-3.4.6.tar.gz directory
[Email protected] bin]# cd/usr/local/src/
2. Unzip zookeeper, execute the following command, unzip to the previous level directory
[Email protected] src]# TAR-ZXVF zookeeper-3.4.6.tar.gz-c.
3. go to the top level directory
[Email protected] local]# CD.
4. Enter the zookeeper-3.4.6 directory
[Email protected] local]# CD zookeeper-3.4.6/
5. Create the data directory
[Email protected] local]# mkdir data
6. Enter the conf configuration directory
[Email protected] zookeeper-3.4.6]# CD conf/
7. Copy configuration file zoo_sample.cfg file
[email protected] conf]# CP zoo_sample.cfg ZOO.CFG
8. edit zoo.cfg configuration file
[Email protected] conf]# VI zoo.cfg
DataDir The directory created for step 5
Server.1,Server.2and theserver.3to beZookeeperin the cluster3machine, please follow the actualIPThe address is configured in the configuration file above"Server.id=host:port:port"the first one inPortis from the machine (Follower) connected to the main machine (leader) of the port number, and a secondPortis to carry outLeadershipthe election's port number
1, next in datadir myid file, the contents of the file is only one row, corresponding to the host id server.id id 1 myid 1
[Email protected] conf]# cd/usr/local/zookeeper-3.4.6/data/
[Email protected] data]# VI myID
Enter 1, and press : wq! Save
Second, remote replication of zookeeper installation files
[Email protected] data]# scp-r/usr/local/zookeeper-3.4.6/192.168.33.198:/usr/local/
If you are prompted that the SCP cannot find a command, yum installs the Execute command yum install openssh-clients ( performed on three cluster machines, respectively )
When remote replication prompts for the user name and command for the remote server, enter and complete the replication
[Email protected] data]# scp-r/usr/local/zookeeper-3.4.6/192.168.34.27:/usr/local/
Modify the myIDon the corresponding machine after the copy is complete. For example, modify the myid in 192.168.34.27 as follows:
[Email protected] conf]# cd/usr/local/zookeeper-3.4.6/data/
[Email protected] data]# VI myID
Enter 2, and press : wq! Save
Modify the myid in 192.168.33.198 as follows:
[Email protected] conf]# cd/usr/local/zookeeper-3.4.6/data/
[Email protected] data]# VI myID
Enter 3, and press : wq! Save
Third, start zookeeper cluster
on each node of the ZooKeeper cluster, execute The script that starts the ZooKeeper Service, executing the following script:
[[email protected] bin]#/usr/local/zookeeper-3.4.6/bin/zkserver.sh start
[[email protected] bin]#/usr/local/zookeeper-3.4.6/bin/zkserver.sh start
[[email protected] bin]#/usr/local/zookeeper-3.4.6/bin/zkserver.sh start
As shown:
If you start the Zookeeper on all machines in turn, you can view the boot status via Zookeeper 's script, including the roles of each node in the cluster (or Leader , or Follower), as shown below, is the result of the query on each node in the ZooKeeper cluster:
192.168.33.114
192.168.34.27
192.168.33.198
As you can see from above 192.168.34.27 for leader The other two machines as follower, in addition, can be connected to the client script via the ZooKeeper on the cluster. For the client,ZooKeeper is a whole (ensemble), connected to ZooKeeper The cluster actually feels like a whole cluster of services, so you can build a connection to the service cluster on any one node, and the ZK in Windows that connects to CentOS, as shown in:
Four, Stop Zookeeper
[[email protected] data]/usr/local/zookeeper-3.4.6/bin/zkserver.sh stop
At this point, thezookeeper cluster installation is complete
Zookeeper Related precautions:
In the Zookeeper cluster environment, as long as more than half of the machines start normally, then the Zookeeper service will be available. Therefore, deploying Zookeeper on a cluster is best used for odd machines, so if there are 5 machines, as long as 3 units are working properly, the service will be used normally.
Zookeeper distributed cluster installation and configuration (CENTOS6)