1 ZooKeeper
1.1 Overview
ZooKeeper is a distributed , open source distributed application coordination service, an open source implementation of Google 's Chubby , and an important component of Hadoop and Hbase. It is a software that provides consistent services for distributed applications. The functions provided include: configuration maintenance, domain name services, distributed synchronization, group services, etc.
ZooKeeper's goal is to encapsulate key services that are complex and error-prone, and provide users with simple and easy-to-use interfaces and systems with high performance and stable functions.
ZooKeeper contains a simple set of primitives that provide interfaces between Java and C.
The ZooKeeper code version provides interfaces for distributed exclusive locks, elections, and queues. The code is in $zookeeper_home\src\recipes. Among them, the distributed lock and queue have two versions, Java and C, and the election only has the Java version.
Zookeeper is a low-level distributed coordination tool!
1.2 Basic functions
- Provide customers with the function of writing data, the data is not big, the status information data
- Provide customers with data reading function
- Provide users with monitoring functions when data changes
Summary: ZooKeeper only records some key data or descriptive data, so it does not store a large amount of data. In order to ensure the safety and reliability of the data, ZooKeeper requires the cluster to work together and store the same data together!! (3 or 5 ), 3 machines store three copies of data, and 5 machines store 5 copies of files!!
1.3 Application scenarios
The role of Zookeeper is as follows:
HDFS YARN's mast is made by itself (configure HA)
intended
Election of the master node in a distributed system! For example, the boss in hbase generates Hmaster (HA)
Master-slave node perception in distributed systems!
Synchronization of configuration files in distributed systems!
Dynamic online and offline perception of system servers!!!
The realization of distributed locks in distributed systems ! The same object in distributed
Name service in distributed systems!
Load balancing in distributed systems!
........
2 Installation
2.1 Upload to linux machine and decompress
rz
tar -zxvf ZooKeeper-3.4.6.tar.gz
2.2 Modify the configuration file
cd ZooKeeper-3.4.6/conf
mv zoo_sample.cfg zoo.cfg
vi zoo.cfg
dataDir=/usr/apps/zookeeper-3.4.6/zkData
# Set to "0" to disable auto purge feature
# autopurge.purgeInterval = 1
server.1=linux01:2888:3888
server.2=linux02:2888:3888
server.3=linux03:2888:3888
2.3 Create the zkData directory and write the myid file
mkdir /opt/apps/zookeeper-3.4.6/zkData
echo 1 > /opt/apps/zookeeper-3.4.6/zkData/myid
2.4 Distribution
scp -r zookeeper-3.4.6/ linux02:$PWD
scp -r zookeeper-3.4.6/ linux03:$PWD
2.5 Modify the myid value of linux02 linux03 machine
linux02 echo 2 > /opt/apps/zookeeper-3.4.6/zkData/myid
linux03 echo 3 > /opt/apps/zookeeper-3.4.6/zkData/myid
2.6 Start zk
Each zk node starts
bin/zkServer.sh start
2.7 Writing a one-click startup script
#!/bin/bash
for i in 1 2 3
do
ssh linux0${i} "source /etc/profile;/opt/apps/zookeeper-3.4.6/bin/zkServer.sh $1"
done
sleep 2
if [ $1 == start ]
then
for i in {1..3}
do
ssh doit0${i} "source /etc/profile;/opt/apps/zookeeper-3.4.6/bin/zkServer.sh status "
done
fi
2.8 View the status of the cluster
bin/zkServer.sh status
[root@linux01 apps]# zookeeper-3.4.6/bin/zkServer.sh status
JMX enabled by default
Using config: /opt/apps/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: follower
[root@linux02 apps]# zookeeper-3.4.6/bin/zkServer.sh status
JMX enabled by default
Using config: /opt/apps/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: leader
[root@linux03 apps]# zookeeper-3.4.6/bin/zkServer.sh status
JMX enabled by default
Using config: /opt/apps/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: follower