Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction of zookeeper stand-alone Multi-instance and distributed deployment method

2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "introduction of zookeeper stand-alone multi-instance and distributed deployment method". In daily operation, I believe many people have doubts about the introduction of zookeeper stand-alone multi-instance and distributed deployment method. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "introduction to zookeeper stand-alone multi-instance and distributed deployment method". Next, please follow the editor to study!

1. Preparatory work:

1) linux environment is required, and ubuntu system is recommended. If you learn to install a virtual machine using oracle's virtual box, you can install it by looking for the installation documentation online, while the production environment will generally be installed. Ubuntu download link:

32 bit: http://mirrors.zju.edu.cn/ubuntu-releases//precise/ubuntu-12.04.3-server-i386.iso or 64 bit: http://mirrors.hust.edu.cn/ubuntu-releases//precise/ubuntu-12.04.3-server-amd64.iso

2) JDK:zookeeper needs java running environment. This recommendation is above 1.6. configure JAVA_HOME, CLASSPATH and PATH variables.

Jdk download address: http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

For the configuration of environment variables, you can use .profile under the home directory:

Export JAVA_HOME= "/ usr/lib/jvm/jdk1.7.0_40" export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarexport ZOOKEEPER_HOME= "/ data/apache/zookeeper" export PATH= "$PATH:$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin"

3) zookeeper installation package: http://zookeeper.apache.org/releases.html download stable version, the current version is 3.4.5

two。 All kinds of decompression, not to mention, it is recommended to establish a soft connection zk for the extracted directory (with version number) to facilitate later configuration and upgrade.

After I decompress it, I put it under: / data/apache/zookeeper, and modify the file permissions to run user permissions:

Sudo chown-R zqgame:zqgame zookeeper

Zqgame:zqgame is the user running zookeeper and the group to which the user belongs. View permissions:

Zqgame@develop-test-web:/data/apache$ lltotal 16drwxr-xr-x 4 zqgame zqgame 4096 Jan 17 12:41. / drwxr-xr-x 11 root root 4096 Dec 13 14:49.. / drwxr-xr-x 11 zqgame zqgame 4096 Nov 20 15:50 hadoop-2.2.0/drwxr-xr-x 12 zqgame zqgame 4096 Jan 17 12:56 zookeeper/zqgame@develop-test-web:/data/apache$

3. Port check, the commonly used port 2181 is 288pl 3888, check whether it is occupied, then change the port in the configuration below.

Netstat-ano | grep 2181

4. Configuration and startup of multiple instances on a single machine:

# generate a configuration file with a random name. Here is zoo.cfgcp / data/apache/zookeeper/conf/zoo_sample.cfg / data/apache/zookeeper/conf/zoo.cfgvi / data/apache/zookeeper/conf/zoo.cfg

Configuration file content:

The tickTime=2000initLimit=5syncLimit=5dataDir=/data/apache/zookeeper/data # directory needs to be created manually to store zk data, mainly snapshot clientPort=2181# dataLogDir transaction log storage directory. It is best to configure. The writing speed of the transaction log seriously affects the performance of zookeeper dataLogDir=/data/apache/zookeeper/datalogserver.1=192.168.130.170:2889:3889server.2=192.168.130.170:2890:3890server.3=192.168.130.170:2891:3891.

Copy the configuration file and generate three configuration files: zoo-slave1.cfg: (the other two zoo-slave2.cfg and zoo-slave3.cfg).

Zoo-slave1.cfg needs to set up directories for dataDir and dataLogDir. The changes are as follows:

DataDir=/data/apache/zookeeper/data/slave1dataLogDir=/data/apache/zookeeper/datalog/slave1clientPort=2182

Zoo-slave2.cfg:

DataDir=/data/apache/zookeeper/data/slave2dataLogDir=/data/apache/zookeeper/datalog/slave2clientPort=2183

Zoo-slave3.cfg:

DataDir=/data/apache/zookeeper/data/slave3dataLogDir=/data/apache/zookeeper/datalog/slave3clientPort=2184

As above, the same native IP and different port numbers are configured. Here are three instances.

How to tell the number of instances, there must be an id file, the name must be myid

Echo "1" > / data/apache/zookeeper/data/slave1/myidecho "2" > / data/apache/zookeeper/data/slave1/myidecho "3" > / data/apache/zookeeper/data/slave1/myid

Start quickly under three windows:

Bin/zkServer.sh start zoo-slave1.cfg bin/zkServer.sh start zoo-slave2.cfg bin/zkServer.sh start zoo-slave3.cfg

Check the leader selected by zookeeper, and specify the configuration file through the following script, and then you can see which instance is leader:

Bin/zkServer.sh status zoo-slave1.cfg

You can take a look at the following output:

Zqgame@develop-test-web:/data/apache/zookeeper$ bin/zkServer.sh status zoo-slave2.cfg JMX enabled by defaultUsing config: / data/apache/zookeeper/bin/../conf/zoo-slave2.cfgMode: leader

5. Distributed deployment:

It's similar to multiple instances on a single machine, but instead of three directories, you only need one directory, one configuration file, and three different IP, which are distributed on different IP and are still different myid. Assuming I have three separate machines, the zoo.cfg (only one default configuration file, zoo.cfg) configuration file is as follows:

The tickTime=2000initLimit=5syncLimit=5dataDir=/data/apache/zookeeper/data # directory needs to be created manually to store zk data, mainly snapshot clientPort=2181# dataLogDir transaction log storage directory. It is best to configure. The writing speed of the transaction log seriously affects the performance of zookeeper dataLogDir=/data/apache/zookeeper/datalogserver.1=192.168.130.101:2888:3888server.2=192.168.130.102:2888:3888server.3=192.168.130.103:2888:3888.

Then write different myid on the three machines:

# execute the following echo "1" > / data/apache/zookeeper/data/myid# at 192.168.130.101 / data/apache/zookeeper/data/myid# at 192.168.130.102 / data/apache/zookeeper/data/myid# at 192.168.130.103 execute the following echo "3" > / data/apache/zookeeper/data/myid

In this way, zookeeper is started quickly on each of the three machines. There is no need to specify a configuration file at this time. The default configuration file is zoo.cfg:

Bin/zkServer.sh start

View the status after startup:

Bin/zkServer.sh status

Enter the shell client of zookeeper:

Bin/zkCli.sh # enter the shell of the native zookeeper

Enter the shell client of the specified machine:

Bin/zkCli.sh-server 192.168.130.101

If there is an error in viewing the startup status, check it later, because it takes some time to select the leader after zookeeper starts. The usage of the following articles that are not understood by the above configuration and commands can be explained in detail. Welcome to patting bricks!

At this point, the study on "introduction to zookeeper stand-alone multiple instances and distributed deployment methods" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report