& zookeeper mounted on the basic operation start & linux

First, install java

sudo apt-get update
sudo apt-get install default-jre

 

Second, the installation zookeeper

  download

wget "http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz"

  Decompression

tar -xf zookeeper-3.4.14.tar.gz 

  Create a profile

cd zookeeper-3.4.14/conf/
cp zoo_sample.cfg zoo.cfg

  start up

cd zookeeper-3.4.14/bin/
./zkServer.sh start

 

 

Third, the pseudo-cluster model

  Copy zookeeper

cp zookeeper-3.4.14 zookeeper-1 -r
cp zookeeper-3.4.14 zookeeper-2 -r
cp zookeeper-3.4.14 zookeeper-3 -r

 

  Modify the configuration: to modify their respective zoo.cfg directory conf, will dataDir, dataLogDir and clientPort modified to their different, and increase ip list. As zk1 configuration:

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
dataDir=/mnt/zookeeper-1/data
dataLogDir=/mnt/zookeeper-1/log
# the port at which the clients will connect
clientPort=12181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1

server.1=127.0.0.1:12888:13888
server.2=127.0.0.1:14888:15888
server.2=127.0.0.1:16888:17888

 

  Create data, log files directory and myid

mkdir -p  /mnt/zookeeper-1/data
mkdir -p  /mnt/zookeeper-2/data
mkdir -p  /mnt/zookeeper-3/data
mkdir -p  /mnt/zookeeper-1/log
mkdir -p  /mnt/zookeeper-2/log
mkdir -p  /mnt/zookeeper-3/log
echo 1 > /mnt/zookeeper-1/data/myid
echo 2 > /mnt/zookeeper-2/data/myid
echo 3 > /mnt/zookeeper-3/data/myid

  It was started three zk

./zookeeper-1/bin/zkServer.sh start
./zookeeper-2/bin/zkServer.sh start
./zookeeper-3/bin/zkServer.sh start

  View Status

root@iZwz9hextk0ee6gik32377Z:~/zookeeper# for((idx=1;idx<=3;++idx)); do ./zookeeper-${idx}/bin/zkServer.sh start; done    
ZooKeeper JMX enabled by default
Using config: /root/zookeeper/zookeeper-1/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
ZooKeeper JMX enabled by default
Using config: /root/zookeeper/zookeeper-2/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
ZooKeeper JMX enabled by default
Using config: /root/zookeeper/zookeeper-3/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
root@iZwz9hextk0ee6gik32377Z:~/zookeeper# for((idx=1;idx<=3;++idx)); do ./zookeeper-${idx}/bin/zkServer.sh status; done     
ZooKeeper JMX enabled by default
Using config: /root/zookeeper/zookeeper-1/bin/../conf/zoo.cfg
Mode: follower
ZooKeeper JMX enabled by default
Using config: /root/zookeeper/zookeeper-2/bin/../conf/zoo.cfg
Mode: leader
ZooKeeper JMX enabled by default
Using config: /root/zookeeper/zookeeper-3/bin/../conf/zoo.cfg
Mode: follower

 

Fourth, the cluster model

  And pseudo-cluster model is similar, the difference is deployed in different machines.

 

Fifth, the basic operation

  Connection zk. Execution zkCli.sh bin directory. Since the deployment is not the default ip ip 2181, need to specify the ip port

./zkCli.sh -server 127.0.0.1:12181 
[zk: 127.0.0.1:12181(CONNECTED) 5] ls /    
[zookeeper]
[zk: 127.0.0.1:12181(CONNECTED) 6] create /test test
Created /test
[zk: 127.0.0.1:12181(CONNECTED) 7] ls / 
[zookeeper, test]
[zk: 127.0.0.1:12181(CONNECTED) 8] get /test
test
cZxid = 0x400000006
ctime = Mon Apr 06 22:01:48 CST 2020
mZxid = 0x400000006
mtime = Mon Apr 06 22:01:48 CST 2020
pZxid = 0x400000006
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0
[zk: 127.0.0.1:12181(CONNECTED) 9] delete /test
[zk: 127.0.0.1:12181(CONNECTED) 10] ls /    
[zookeeper]
[zk: 127.0.0.1:12181(CONNECTED) 11] get /test
Node does not exist: /test
[zk: 127.0.0.1:12181(CONNECTED) 12] quit
Quitting...

 

 

  

 

Guess you like

Origin www.cnblogs.com/chinxi/p/12649964.html