Zookeeper installation and configuration (cluster mode)

1. Download and unzip

  Zookeeper download address: http://www.apache.org/dyn/closer.cgi/zookeeper/

  After the download is complete, unzip to a specific directory

同步时间所有节点的时间,并关闭防火墙
$ ntpdate -u ntp.sjtu.edu.cn
$ service iptables stop

 

2. Zooker configuration

  Zookeeper cluster mode requires at least 3 hosts to build, prepare three hosts Serve1, Server2, and Server3 

  »Create a myid file in the Zookeeper conf directory. The content of server1 is: 1, the content of server2 is: 2, and the content of server3 is: 3
  » Create a configuration file zoo.cfg (marked in red) in the conf directory main):

tickTime=2000
dataDir=/Users/zdandljb/zookeeper/data
dataLogDir=/Users/zdandljb/zookeeper/dataLog
clientPort=2181
initLimit=5
syncLimit=2
server.1=server1:2888:3888
server.2=server2:2888:3888
server.3=server3:2888:3888

    After the configuration is completed, distribute the configuration file to other hosts;

  Parameter explanation:  

    • tickTime: the interval time for sending heartbeats, unit: milliseconds
    • dataDir: the directory where zookeeper saves data.
    • clientPort: The port used by the client to connect to the Zookeeper server. Zookeeper will listen on this port and accept the client's access request.
    • initLimit: This configuration item is used to configure Zookeeper to accept clients (the client mentioned here is not the client of the user connecting to the Zookeeper server.

     It is the maximum number of heartbeat intervals that can be tolerated when initializing the connection in the Zookeeper server cluster connected to the Follower server of the Leader.

     When the length of 5 heartbeats (that is, tickTime) is exceeded, the Zookeeper server has not received the return message from the client, then it indicates that the client connection has failed.

     The total length of time is 5*2000=10 seconds
    • syncLimit: This configuration item identifies the length of the message, request and response time between Leader and Follower. The longest time cannot exceed the length of tickTime.

     The total length of time is 2*2000=4 seconds
    • server.A=B: C: D: Among them

     A is a number, indicating which server is this number;

     B is the ip address of this server;

     C represents the port for this server to exchange information with the Leader server in the cluster;

     D means that in case the Leader server in the cluster goes down, a port is needed to re-elect and select a new leader.

     This port is used to communicate with each other when the election is performed. If it is a pseudo-cluster configuration method, since B is the same,

     Therefore, the communication port numbers of different Zookeeper instances cannot be the same, so different port numbers must be assigned to them.

3. Configure the environment variables of zookeeper

$ vim /root/.bash_profile

#写入

PATH=$PATH:/usr/local/zookeeper-3.4.6/bin

4. Start zookeeper (all nodes must be started)

$ cd /usr/local/zookeeper

$ bin/zkServer.sh start

# 显示:Starting zookeeper ... STARTED 表示启动成功

 

 Follow the official account " Java Senior Architect " and reply to the " Interview Questions" Get: HD 3585 pages of real interview questions from Dachang

 

Guess you like

Origin blog.csdn.net/qq_17010193/article/details/114959941