Linux ZooKeeper Distributed Cluster Installation tutorial
- 2020-06-23 02:31:26
- OfStack
ZooKeeper is a zookeeper. It is used to manage Hadoop (elephants), Hive (bees) and pig (piglets). Apache Hbase, Apache Solr and Dubbo all use ZooKeeper. ZooKeeper is a distributed, open source program coordination service that is a sub-project of the Hadoop project. The main application scenarios of ZooKeeper include cluster management (master-slave management, load balancing, highly available management), centralized management of configuration files, distributed locking, registry, etc. In real projects, ZooKeeper was installed in a distributed cluster to ensure high availability, requiring at least three nodes, as detailed below.
Here Linux chooses CentOS 7.2.
# wget -P /usr/local http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz
# cd /usr/local
# tar -zxvf zookeeper-3.4.10.tar.gz
# cd zookeeper-3.4.10
# mkdir data
# mkdir logs
# vim /etc/rc.d/rc.local // Configuration starts from startup
Append the following configuration:
export JAVA_HOME=/usr/java/jdk
/usr/local/zookeeper-3.4.10/bin/zkServer.sh start
We deployed an ZooKeeper process on three different servers to form an ZooKeeper cluster. The three ZooKeeper processes use the same ES28en.ES29en configuration:
# cd /usr/local/zookeeper-3.4.10/conf
# cp zoo_sample.cfg zoo.cfg // Copy configuration file
# vim zoo.cfg
Modify the configuration as follows:
# Configure the directory where the snapshot files will be stored
dataDir=/usr/local/zookeeper-3.4.10/data
dataLogDir=/usr/local/zookeeper-3.4.10/logs
# zk The service process is listening TCP port
clientPort=2181
# 2888:ZooKeeper Ports on which services communicate ,3888:ZooKeeper Ports to communicate with other applications
# server.1: Indicates which server number this is
server.1=192.168.20.11:2888:3888
server.2=192.168.20.12:2888:3888
server.3=192.168.20.13:2888:3888
Then, under the dataDir directory of 3 servers, create 1 myid file with contents of 1, 2, 3, respectively. We then started the ZooKeeper process on each of the three machines, so we got the ZooKeeper cluster up. As follows:
# cd /usr/local/zookeeper-3.4.10/data
# echo 1 >>myid // create myid File and write 1
# /usr/local/zookeeper-3.4.10/bin/zkServer.sh start // The background to start ZooKeeper
There are a few other commands as follows:
# /usr/local/zookeeper-3.4.10/bin/zkServer.sh stop // Shut down ZooKeeper
# /usr/local/zookeeper-3.4.10/bin/zkServer.sh status // View service status
# /usr/local/zookeeper-3.4.10/bin/zkServer.sh start-foreground // The front desk to start the