天天看點

zookeeper 指令_zookeeper叢集部署

zookeeper 指令_zookeeper叢集部署

一、将zookeeper安裝檔案解壓到/opt/local目錄下面:

sudo tar -zxvf zookeeper-3.4.10.tar.gz -C /opt/local
           

二、在zookeeper目錄下面建立data目錄,用于存放zookeeper日志檔案和snapshot檔案:

cd /opt/local/zookeeper-3.4.10sudo mkdir datasudo mkdir data/snapshotsudo mkdir data/logs
           

三、修改zookeeper配置檔案conf/zoo.cfg:

# The number of milliseconds of each ticktickTime=2000# The number of ticks that the initial# synchronization phase can takeinitLimit=10# The number of ticks that can pass between# sending a request and getting an acknowledgementsyncLimit=5# the directory where the snapshot is stored.# do not use /tmp for storage, /tmp here is just# example sakes.dataDir=/opt/local/zookeeper-3.4.10/data/snapshotdataLogDir=/opt/local/zookeeper-3.4.10/data/logs# the port at which the clients will connectclientPort=2181# 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=1server.0=192.168.0.161:2888:3888server.1=192.168.0.162:2888:3888server.2=192.168.0.163:2888:3888
           

檔案中最後三行用于zookeeper叢集配置,這裡使用三台伺服器來搭建zookeeper叢集。3888端口用于上司者選舉,2888端口用于leader向follower和observer同步資料,并且:

  • 192.168.0.161的辨別為0
  • 192.168.0.162的辨別為1
  • 192.168.0.163的辨別為2

是以我們需要分别在各個伺服器中dataDir目錄(也就是/opt/local/zookeeper-3.4.10/data/snapshot)下建立一個myid檔案,檔案内容是該伺服器的辨別。

四、修改/etc/profile檔案,設定zookeeper path:

export ZOOKEEPER_HOME=/opt/local/zookeeper-3.4.10export PATH=$PATH:$ZOOKEEPER_HOME/bin
           

五、常用操作

啟動zookeeper

sudo zkServer.sh start
           

檢視zookeeper狀态

zkServer.sh status
           

現在可以通過下面指令登入zookeeper叢集:

zkCli.sh -server 192.168.0.161:2181,192.168.0.162:2181,192.168.0.163:2181
           

使用四字母指令通路伺服器,nc指令用于發送資訊至指定IP的端口号:

echo stat | nc 192.168.0.161 2181 #查詢zookeeper狀态echo conf | nc 192.168.0.161 2181 #查詢zookeeper配置資訊echo ruok | nc 192.168.0.161 2181 #檢查zookeeper是否運作正常echo envi | nc 192.168.0.161 2181 #查詢zookeeper詳細資訊,比stat指令傳回更多資訊
           

關閉zookeeper

sudo zkServer.sh stop
           

繼續閱讀