Zookeeper cluster construction

Goal: Build a zk cluster (5 nodes)

 

zk download:

wget http://apache.fayea.com/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gz

 

Unzip:

tar -xvf zookeeper-3.4.9.tar.gz

 

Introduction to executable scripts: 

zkCleanup - Cleans up ZooKeeper historical data, including transaction log files and snapshot data files. 

zkCli - A simple client for ZooKeeper. 

zkEnv - Sets ZooK's environment variables. 

zkServer - Start, stop and restart scripts for the ZooKeeper service.

 

add myid file

(The following corresponds to dataDir=/home/q/www/tools/zk/zk1/data/ configured in the zoo.cfg file):

 

sudo mkdir /home/q/www/tools/zk/zk3/data
sudo echo 1>/home/q/www/tools/zk/zk1/data/myid

 

 Change the configuration: copy 5 copies:

#zoo_sample.cfg file renamed to zoo.cfg
sudo cp zoo_sample.cfg zoo.cfg

 sudo cp -r zookeeper-3.4.9 zk1
 sudo cp -R zookeeper-3.4.9 zk1
 sudo cp -R zookeeper-3.4.9 zk2
 sudo cp -R zookeeper-3.4.9 zk3
 sudo cp -R zookeeper-3.4.9 zk4
 sudo cp -R zookeeper-3.4.9 zk5

 

Change setting: 

The configuration of zk1 zoo.cfg is:

################# ZK 1 ############################### ########

tickTime=2000

initLimit = 10

syncLimit=5

dataDir=/home/q/www/tools/zk/zk1/data/

clientPort=2182

maxClientCnxns=60

 

dataLogDir=/home/q/www/tools/zk/zk1/datalog

 

 

server.1=127.0.0.1:2881:3881

server.2=127.0.0.1:2882:3882

server.3=127.0.0.1:2883:3883

server.4=127.0.0.1:2884:3884

server.5=127.0.0.1:2885:3885

################# ZK 2 ############################## ########

tickTime=2000

initLimit = 10

syncLimit=5

dataDir=/home/q/www/tools/zk/zk2/data/

clientPort=2183

maxClientCnxns=60

 

dataLogDir=/home/q/www/tools/zk/zk2/datalog

 

server.1=127.0.0.1:2881:3881

server.2=127.0.0.1:2882:3882

server.3=127.0.0.1:2883:3883

server.4=127.0.0.1:2884:3884

server.5=127.0.0.1:2885:3885

################# ZK 3 ############################### ########

tickTime=2000

initLimit = 10

syncLimit=5

dataDir=/home/q/www/tools/zk/zk3/data/

clientPort=2184

maxClientCnxns=60

 

dataLogDir=/home/q/www/tools/zk/zk3/datalog

 

 

server.1=127.0.0.1:2881:3881

server.2=127.0.0.1:2882:3882

server.3=127.0.0.1:2883:3883

server.4=127.0.0.1:2884:3884

server.5=127.0.0.1:2885:3885

################# ZK 4 ############################### ########

tickTime=2000

initLimit = 10

syncLimit=5

dataDir=/home/q/www/tools/zk/zk4/data/

clientPort=2185

maxClientCnxns=60

 

dataLogDir=/home/q/www/tools/zk/zk4/datalog

 

 

server.1=127.0.0.1:2881:3881

server.2=127.0.0.1:2882:3882

server.3=127.0.0.1:2883:3883

server.4=127.0.0.1:2884:3884

server.5=127.0.0.1:2885:3885

 

################# ZK 5 ############################### ########

tickTime=2000

initLimit = 10

syncLimit=5

dataDir=/home/q/www/tools/zk/zk5/data/

clientPort=2186

maxClientCnxns=60

 

dataLogDir=/home/q/www/tools/zk/zk5/datalog

 

 

server.1=127.0.0.1:2881:3881

server.2=127.0.0.1:2882:3882

server.3=127.0.0.1:2883:3883

server.4=127.0.0.1:2884:3884

server.5=127.0.0.1:2885:3885

################# ZK config end #######################################

 

 

 

Start the cluster:

#start up
sudo /home/q/www/tools/zk/zk1/bin/zkServer.sh start
# restart
sudo /home/q/www/tools/zk/zk1/bin/zkServer.sh restart

 

The client connects to a certain machine:

sudo /home/q/www/tools/zk/zk4/bin/zkCli.sh -server 127.0.0.1:2183

# perform the operation
get /
ls /

 

View command:

#View the current number of client connections, the current Mode mode (follower/leader)
echo stat|nc 127.0.0.1 2183
#This can also view the current mode of zk
sudo /home/q/www/tools/zk/zk5/bin/zkServer.sh   status

#View the current zk configuration
echo conf|nc 127.0.0.1 2183
#View the current state of zk
echo food | nc 127.0.0.1 2183

 

  • 1. You can use the command: echo stat|nc 127.0.0.1 2181 to check which node is selected as follower or leader
  • 2. Use echo ruok|nc 127.0.0.1 2181 to test whether the server has been started. If it replies imok, it means it has been started.
  • 3. echo dump | nc 127.0.0.1 2181 , list unprocessed sessions and temporary nodes.
  • 4. echo kill | nc 127.0.0.1 2181 , turn off the server
  • 5. echo conf | nc 127.0.0.1 2181 , output the detailed information of related service configuration.
  • 6. echo cons | nc 127.0.0.1 2181 , lists the full connection/session details of all clients connected to the server.
  • 7. echo envi |nc 127.0.0.1 2181 , output detailed information about the service environment (different from the conf command).
  • 8. echo reqs | nc 127.0.0.1 2181 , list unhandled requests.
  • 9. echo wchs | nc 127.0.0.1 2181 , list the details of the server watch.
  • 10. echo wchc | nc 127.0.0.1 2181 , lists the details of the server watch through session, and its output is a list of sessions related to watch.
  • 11. echo wchp | nc 127.0.0.1 2181 , list the details of the server watch by path. It outputs a path associated with the session.

 

experiment:

 5 zk, stop two can work normally

sudo /home/q/www/tools/zk/zk1/bin/zkServer.sh stop

sudo /home/q/www/tools/zk/zk4/bin/zkServer.sh stop

 

implement:

sudo /home/q/www/tools/zk/zk4/bin/zkServer.sh   status

 output:

ZooKeeper JMX enabled by default

Using config: /home/q/www/tools/zk/zk4/bin/../conf/zoo.cfg

Error contacting service. It is probably not running.

 

implement:

sudo /home/q/www/tools/zk/zk5/bin/zkServer.sh   status

 

Output: (cluster exists normally)

ZooKeeper JMX enabled by default

Using config: /home/q/www/tools/zk/zk5/bin/../conf/zoo.cfg

Mode: follower

 

Go ahead and kill one:

sudo /home/q/www/tools/zk/zk2/bin/zkServer.sh stop

 

Check: (At this time, the cluster has completely failed, and no more than 1/2 of the machines will die without any impact, otherwise the cluster will hang up)

sudo /home/q/www/tools/zk/zk5/bin/zkServer.sh   status

 output:

ZooKeeper JMX enabled by default

Using config: /home/q/www/tools/zk/zk5/bin/../conf/zoo.cfg

Error contacting service. It is probably not running.

 

Continue to execute: (start zk2)

sudo /home/q/www/tools/zk/zk2/bin/zkServer.sh start

 

 

Check zk5: (At this point the cluster is back to normal)

sudo /home/q/www/tools/zk/zk5/bin/zkServer.sh   status

 

output:

ZooKeeper JMX enabled by default

Using config: /home/q/www/tools/zk/zk5/bin/../conf/zoo.cfg

Mode: leader

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326689082&siteId=291194637