Ubuntu部署zookeeper

2.1 创建文件夹

/home/xdq/xinPrj/zookeeper

mkdir zookeeper cd zookeeper 

2.2 解压文件

  • 解压到当前文件夹
tar -zxvf zookeeper-3.5.1-alpha.tar.gz -C . 
  • 文件目录
├── zookeeper │ ├── zookeeper-3.5.1-alpha │ │ ├── bin │ │ ├── build.xml │ │ ├── CHANGES.txt │ │ ├── conf │ │ ├── contrib │ │ ├── dist-maven │ │ ├── docs │ │ ├── ivysettings.xml │ │ ├── ivy.xml │ │ ├── lib │ │ ├── LICENSE.txt │ │ ├── NOTICE.txt │ │ ├── README_packaging.txt │ │ ├── README.txt │ │ ├── recipes │ │ ├── src │ │ ├── zookeeper-3.5.1-alpha.jar │ │ ├── zookeeper-3.5.1-alpha.jar.asc │ │ ├── zookeeper-3.5.1-alpha.jar.md5 │ │ └── zookeeper-3.5.1-alpha.jar.sha1 │ └── zookeeper-3.5.1-alpha.tar.gz 

2.3 配置文件

  • 创建文件conf/zoo.cfg
    内容拷贝conf/zoo_sample.cfg即可,修改dataDir.
# ZooKeeper时间单位,用于心跳和最小任务超时为tickTime的两倍 tickTime=2000 # 存储数据 dataDir=/home/xdq/xinPrj/zookeeper/datas # 客户端连接监听端口 clientPort=2181 

2.4 Usage

bin/zkServer.sh start 
  • cmd
jps 
  • Result
    启动成功
30372 Jps 30329 QuorumPeerMain 
sudo vim /.bashrc 
export ZOOKEEPER_HOME=/home/xdq/xinPrj/zookeeper/zookeeper-3.5.1-alpha export PATH=$PATH:$ZOOKEEPER_HOME/bin 
source /.bashrc 
  • cmd
bin/zkCli.sh -server 127.0.0.1:2181 
  • Result
2019-07-29 20:32:00,458 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@980] - Socket connection established, initiating session, client: /127.0.0.1:52706, server: 127.0.0.1/127.0.0.1:2181 [zk: 127.0.0.1:2181(CONNECTING) 0] 2019-07-29 20:32:00,659 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1400] - Session establishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x10002ab71280000, negotiated timeout = 30000 WATCHER:: WatchedEvent state:SyncConnected type:None path:null 
  • cmd
bin/zkServer.sh stop 
  • Result
ZooKeeper JMX enabled by default Using config: /home/xdq/xinPrj/zookeeper/zookeeper-3.5.1-alpha/bin/../conf/zoo.cfg Stopping zookeeper ... STOPPED 

3.1 配置hosts

sudo vim /etc/hosts 
127.0.0.1 localhost 

3.2 zoo.cfg文件

假设伪集群数目:3个,则需要配置三份zoo.cfg,路径:/path/zookeeper/conf/zoo.cfg分别如下

  • zoo1.cfg
tickTime=2000 initLimit=10 syncLimit=5 dataDir=/tmp/zk1/data dataLogDir=/tmp/zk1/log clientPort=2181 server.1=localhost:2877:3877 server.2=localhost:2888:3888 server.3=localhost:2899:3899 
  • zoo2.cfg
tickTime=2000 initLimit=10 syncLimit=5 dataDir=/tmp/zk2/data dataLogDir=/tmp/zk2/log clientPort=2182 server.1=localhost:2877:3877 server.2=localhost:2888:3888 server.3=localhost:2899:3899 
  • zoo3.cfg
tickTime=2000 initLimit=10 syncLimit=5 dataDir=/tmp/zk3/data dataLogDir=/tmp/zk3/log clientPort=2183 server.1=localhost:2877:3877 server.2=localhost:2888:3888 server.3=localhost:2899:3899 

3.3 配置zookeeper服务id

dataDir所在的路径下建立myid文件,两种方式:

  • echo写入
echo 1>/tmp/zk1/data/myid echo 1>/tmp/zk2/data/myid echo 1>/tmp/zk3/data/myid 
  • vim 写入
sudo vim /tmp/zk1/data/myid sudo vim /tmp/zk2/data/myid sudo vim /tmp/zk3/data/myid 

3.4 Usage

  • cmd
bin/zkServer.sh start conf/zoo1.cfg 
ZooKeeper JMX enabled by default Using config: conf/zoo1.cfg Starting zookeeper ... STARTED 
  • cmd
bin/zkServer.sh start conf/zoo2.cfg 
ZooKeeper JMX enabled by default Using config: conf/zoo2.cfg Starting zookeeper ... STARTED 
  • cmd
bin/zkServer.sh start conf/zoo3.cfg 
ZooKeeper JMX enabled by default Using config: conf/zoo3.cfg Starting zookeeper ... STARTED 
  • cmd
bin/zkServer.sh status conf/zoo1.cfg 
ZooKeeper JMX enabled by default Using config: conf/zoo1.cfg Client port found: 2181. Client address: localhost. Mode: follower 
  • cmd
bin/zkServer.sh status conf/zoo2.cfg 
ZooKeeper JMX enabled by default Using config: conf/zoo2.cfg Client port found: 2182. Client address: localhost. Mode: leader 
  • cmd
bin/zkServer.sh status conf/zoo3.cfg 
ZooKeeper JMX enabled by default Using config: conf/zoo3.cfg Client port found: 2183. Client address: localhost. Mode: follower 
  • cmd
jps 
27233 Jps 26853 QuorumPeerMain 26919 QuorumPeerMain 26619 QuorumPeerMain 
  • cmd
bin/zkServer.sh stop conf/zoo1.cfg 
  • Result
ZooKeeper JMX enabled by default Using config: /home/xdq/xinPrj/zookeeper/zookeeper-3.5.1-alpha/bin/../conf/zoo.cfg Stopping zookeeper ... STOPPED 

4.1 第一台服务

  • zoo.cfg
tickTime=2000 initLimit=10 syncLimit=5 dataDir=/tmp/zk3/data dataLogDir=/tmp/zk3/log clientPort=2181 server.1=kafka1:2888:3888 server.2=kafka2:2888:3888 server.3=kafka3:2888:3888 

4.2 第二台服务

  • zoo.cfg
tickTime=2000 initLimit=10 syncLimit=5 dataDir=/tmp/zk3/data dataLogDir=/tmp/zk3/log clientPort=2181 server.1=kafka1:2888:3888 server.2=kafka2:2888:3888 server.3=kafka3:2888:3888 

4.3 第三台服务

  • zoo.cfg
tickTime=2000 initLimit=10 syncLimit=5 dataDir=/tmp/zk3/data dataLogDir=/tmp/zk3/log clientPort=2181 server.1=kafka1:2888:3888 server.2=kafka2:2888:3888 server.3=kafka3:2888:3888 

4.4 建立id

在dataDir路径下建立myid文件,并写入server.x对应的x,如1,2,3。

  • echo写入
echo 1>/tmp/zk1/data/myid echo 1>/tmp/zk2/data/myid echo 1>/tmp/zk3/data/myid 
  • vim 写入
sudo vim /tmp/zk1/data/myid sudo vim /tmp/zk2/data/myid sudo vim /tmp/zk3/data/myid 

4.5 Usage

bin/zkServer.sh start 
bin/zkServer.sh status 
bin/zkServer.sh restart 
bin/zkServer.sh stop 

原文链接:https://blog.csdn.net/Xin_101/article/details/97673249

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享