The installation and configuration process ZooKeeper

Use work to do ZooKeeper cluster management tools, the installation and configuration simple ZooKeeper record it.

First, download ZooKeeper, had nothing to say, but his negligence made a stupid mistake, you should download the executable file compression package apache-zookeeper-xxx-bin.tar.gz, I downloaded became a source apache-zookeeper-xxxtar .gz, resulting in an error when you start, do not find the main class.

 

 After the download is complete compression can be configured. Alternatively, you can build a soft link, if there is a change in the future ZooKeeper version, as long as the modifications soft link.

 Use% ZK_HOME% to represent the installation directory of ZooKeeper.

tar xzvf apache-zookeeper Over 3.5 . 6 bin. tar .gz

 

ZooKeeper has two operating modes, one is the cluster model, is a stand-alone mode. They are arranged as follows.

1. Cluster model

Suppose that three machines to build ZooKeeper clusters, IP addresses IP1, IP2, IP3

(1) configuration file zoo.cfg

Initial use ZooKeeper, the file needs to be zoo_sample.cfg% ZOO_HOME% / conf directory rename zoo.cfg, and simple configuration according to the following code:

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/zs/zookeeper/zookeeper1/data
dataLogDir=/home/zs/zookeeper/zookeeper1/log
clientPort=2181
server.1=IP1:2888:3888
server.2=IP2:2888:3888
server.3=IP3:2888:3888

Configuration parameters are interpreted as follows:

a) tickTime:. This parameter MS milliseconds, the minimum length for ZooKeeper configuration unit time, a lot of time running multiple intervals are used to represent the tickTime.

b) initLimit:. To configure this parameter is a positive integer N, the N times of tickTime. Follower Leader for configuring server waits to start and finish time data synchronization. Follower server during the boot process, we will establish a connection with the Leader and complete the synchronization of the data to determine the initial state of their own provide external services. Leader server allows Follower complete the work within initLimit time.

c) syncLimit:. To configure this parameter is a positive integer N, the N times of tickTime. Leader disposed between a server and Follower heartbeat detected maximum delay time. If the server can not get to the Leader heartbeat response Follower in syncLimit time, the Leader will conclude that the Follower is already out and their synchronization.

d) dataDir:. ZooKeeper is used to configure the directory server stores the snapshot file. By default, if not configured parameters dataLogDir, then transaction logs will be stored in this directory. Taking into account the transaction log write performance directly affects the overall ZooKeeper service capabilities, while it is recommended to configure the storage directory transaction logs ZooKeeper by parameters dataLogDir.

e) dataLogDir:. ZooKeeper is used to configure the directory server to store the transaction log files. dataDir and dataLogDir must ensure that read and write permissions.

f) clientPort:. The current server is used to configure external service port, the client will create a connection through the port and ZooKeeper server.

. G) server.id = host: port: port: This parameter is used to configure a machine consisting ZooKeeper cluster list, where id is the ServerID, and each server myid file corresponds to the number. Meanwhile, in this parameter, configures two ports: a first port for the specified port server running Follower Leader with communication and data used for synchronization, the second port is dedicated to the election process for Leader voting communications. When ZooKeeper server startup, which will be determined according to ServerID myid own configuration file which server and use port corresponding to the configuration of the line to start. If the actual use needs to be deployed in multiple instances ZooKeeper constituted on the same server cluster dummy, then these ports need to be configured to be different.

(2) Create a file myid

In the directory configured dataDir, create a file named myid, writing in the first line of the file on a digital, ie ServerID, and the corresponding number on zoo.cfg current machine. For example, server.1 of myid contents of the file is "1." To ensure that the digital myid file for each server in a different, and where their machines and zoo.cfg in server.id = host: port: id value of the port of the same. Id range is 1 to 255.

(3) repeat (1) and (2) step, and the configuration zoo.cfg myid file for all machines.

(4) start ZooKeeper.

bin/zkServer.sh start

 

 Sometimes While executing the start command, display STARTED, but ZooKeeper does not really run, may correspond to the state for testing. In order to start the implementation of the directory will generate Logs directory, logging started, if not start successfully, you can find out the reasons in the Logs directory.

(5) the authentication server

To verify that the server has not started, you can telnet to port ZooKeeper, and then send commands to verify stat

If the following output message appears, the server startup success.

 

 

You may also be used zkServer.sh status command to check the status ZooKeeper server, as shown below, indicating that the server is a follower.

 

 

Problems that may occur when the authentication server as follows:

a). If you use the telnet command to verify stat increase, appear "stat is not executed because it is not in the whitelist." error, you can modify the startup script, add the ZooKeeper the instigation of the White List.

Open zkServer.sh script, if [ "x $ SERVER_JVMFLAGS"! = "X"] add above statement a statement, adding ZooKeeper the instigation of the White List.

ZOOMAIN="-Dzookeeper.4lw.commands.whitelist=* ${ZOOMAIN}"

 

 

b). If you use the telnet command to verify stat added, appears "This ZooKeeper instance is not currently serving requests" error, the reason is that the cluster is not elected leader, when a cluster node only the next stage, or less than half, this error message will appear. You can configure other ZooKeeper cluster server starts, or check whether the network between the server is down.

 

 

c). 如果使用zkServer.sh status命令,出现It is probably not running. 有可能是集群中其他服务器没有开启。要整个集群都开启再执行status命令,只开启一台服务器并验证会报错。也有可能是服务器真没启来,看查看一下输出日志。

 

(6) 关闭服务器

bin/zkServer.sh stop

 

 

2. 伪集群模式

ZooKeeper支持在一台服务器上启动多个ZooKeeper的实例,相互组成一个集群。不需要拷贝多个ZooKeeper的目录,就是同一个程序目录下,配置多个zoo.cfg文件即可。

(1) 配置文件

可以在conf目录下,创建三个配置文件,分别命名为zoo1.cfg、zoo2.cfg、zoo3.cfg,内容分别如下。注意,dataDir和dataLogDir配置不同的目录,IP地址均为本机的IP地址,但端口各不相同。

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/zs/zookeeper/zookeeper1/data
dataLogDir=/home/zs/zookeeper/zookeeper1/log
clientPort=2181
server.1=IP1:2887:3887
server.2=IP1:2888:3888
server.3=IP1:2889:3889
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/zs/zookeeper/zookeeper2/data
dataLogDir=/home/zs/zookeeper/zookeeper2/log
clientPort=2181
server.1=IP1:2887:3887
server.2=IP1:2888:3888
server.3=IP1:2889:3889
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/zs/zookeeper/zookeeper3/data
dataLogDir=/home/zs/zookeeper/zookeeper3/log
clientPort=2181
server.1=IP1:2887:3887
server.2=IP1:2888:3888
server.3=IP1:2889:3889

(2) 创建myid文件

在每个dataDir所配置的目录下,创建一个名为myid的文件,在该文件的第一行写上一个数字,即ServerID,和zoo1.cfg、zoo2.cfg、zoo3.cfg中当前机器的编号对应上。

(3) 启动服务器

因为只有一个ZooKeeper程序目录,在启动不同的实例时,要指定各自的配置文件,启动命令如下所示

bin/zkServer.sh start conf/zoo1.cfg
bin/zkServer.sh start conf/zoo2.cfg
bin/zkServer.sh start conf/zoo3.cfg

 

 (4) 验证服务器

bin/zkServer.sh status conf/zoo1.cfg
bin/zkServer.sh status conf/zoo2.cfg
bin/zkServer.sh status conf/zoo3.cfg

 

 (5) 关闭服务器

bin/zkServer.sh stop conf/zoo1.cfg
bin/zkServer.sh stop conf/zoo2.cfg
bin/zkServer.sh stop conf/zoo3.cfg

 

 

3. 单机模式

ZooKeeper也支持单机部署,单机模式可以看做一种特殊的集群模式,整体配置流程与集群部署一致,不同的地方在于,zoo.cfg配置文件中,只需要配置一个server地址,而且不需要在dataDir目录下配置myid文件。

(1) 配置cfg文件

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/zs/zookeeper/zookeeper/data
dataLogDir=/home/zs/zookeeper/zookeeper/log
clientPort=2181
server.1=IP1:2888:3888

(2) 启动服务器

bin/zkServer.sh start 

 

 (3) 验证服务器

可以使用telnet 加stat命令验证,也可以使用zkServer.sh status 命令验证

使用telnet 加stat命令验证,可以看到单机模式下服务器的Mode为standalone,集群模式下是Leader和Follower。

 

 使用zkServer.sh status 命令验证

 

 (4) 关闭服务器

bin/zkServer.sh stop

 

 

以上就是ZooKeeper的安装和配置过程。

Guess you like

Origin www.cnblogs.com/zhaoshizi/p/12105143.html