3. Zookeeper installation and configuration
1. What is zookeeper
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. Its functions include: configuration maintenance, domain name service, distributed synchronization, group service, etc.
The goal of zooKeeper is to encapsulate complex and error-prone key services, and provide users with simple and easy-to-use interfaces and systems with high performance and stable functions.
2. Why use zookeeper
In the development of large enterprises, the number of services is very large. If we want to add a service, we need to re-overwrite the file and restart the entire container. The result of this is that the ripple effect is too great and maintenance is very difficult.
At this time, a place that can dynamically register services and obtain service information is needed to manage services uniformly. This place is conveniently called a service configuration center. Zookeeper not only realizes the flexible management and smooth transition function of cusumer and provider , but also has built-in functions such as load balancing and active notification , so that we can sense the status of the service almost in real time. It can help us solve distributed related problems very well, and it is still one of the mainstream distributed service registry technologies on the market.
3. Zookeeper installation and configuration
3.1. Environment preparation
- jvm environment
- JDK must be version 7 or above
- Use xshell to connect remotely
3.2. Download and install
zookeeper official website: Apache ZooKeeper
latest stable version download address: Apache Downloads
First check the jdk environment, input java , if the following parameters jump out, it proves that the JDK environment is correct
java
After downloading, upload the compressed package to the linux environment, and upload it to the /opt/software path on my side
Decompress the compressed package
tar -zxvf apache-zookeeper-3.7.1-bin.tar.gz
After decompression, you can see that the zookeeper file already exists in the software directory
Copy the decompressed file to the zookeeper folder under the opt/module path
cp apache-zookeeper-3.7.1-bin /opt/module/zookeeper -r
At this point, you can see that there are zookeeper files in the corresponding directory
3.3 configuration
Enter the conf directory under the zookeeper directory, and change zoo_sample.cfg in the directory to zoo.cfg
mv zoo_sample.cfg zoo.cfg
Create a new zkData folder in the zookeeper directory
mkdir zkData
Go back to zoo.cfg, modify it, and replace the path of dataDir with the path of zkData we just created
vim zoo.cfg
After modification, esc, wq! Save and exit
3.3. Start the test
Enter the bin directory and start the server
./zkServer.sh start
As shown in the figure below, the startup is successful
jps view process
jps
You can see that 4526 after we start is the zookeeper server
Go back to the zookeeper directory and start the client
bin/zkCli.sh
If the following page appears, the startup is successful
3.4. Exit
quit
./zkServer.sh stop