zookeeper服務集羣安裝+測試+命令

zookeeper的安裝測試

1.下載zookeeper。//選擇一個版本下載

2.搭建多臺linux虛擬機(各個虛擬機對應的hosts爲m1,s1,s2)。

3.把下載的zookeeper.tar.gz包拷貝到自己的目錄下。執行tar –zvxf zookeeper.tar.gz

4.修改環境變量

vim/vi  /etc/profile

 在最後面添加:

  1. export ZOOKEEPER_HOME=/usr/local/program/zookeeper  
  2.   
  3. export PATH=$ZOOKEEPER_HOME/bin:$PATH  
注:修改完後profile記得執行source /etc/profile

5.在解壓後的zookeeper的目錄下進入conf目錄修改配置文件

更名操作:mv zoo_sample.cfg zoo.cfg

6.編輯zoo.cfg (vi zoo.cfg)

修改dataDir=/home/hadoop/zookeeper/data/自己指定zookeeper的數據目錄(這個目錄必須存在且必須有myid文件,

myid的值對應的是server.0=m1:2888:3888中的server.0中的0.不同的server上的myid的值不同

新增server.0=m1:2888:3888//m1位liunx虛擬機的映射名稱;2888爲leader的對外接口;3888爲flower的對外接口

         server.1=s1:2888:3888

         server.2=s2:2888:3888

下面是zoo.cfg的配置文件詳解:

zoo.cfg配置信息詳解

# The number of milliseconds of each tick
tickTime=2000 ##ZooKeeper的最小時間單元,單位毫秒(ms),默認值爲3000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10 ##Leader服務器等待Follower啓動並完成數據同步的時間,默認值10,表示tickTime的10倍
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5 ##Leader服務器和Follower之間進行心跳檢測的最大延時時間,默認值5,表示tickTime的5倍
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
dataDir=/tmp/zookeeper ##ZooKeeper服務器存儲快照文件的目錄,必須配值,建議放置在var目錄下
# the port at which the clients will connect
clientPort=2181 ## 服務器對外服務端口,默認值爲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=1
7.到此爲止 m1上的配置就已經完成;接下來配置s1s2.
把m1上的zookeeper的文件拷貝到s1,s2上(scp m1上的zookeeper目錄s1/s2上的zookeeper目錄)
8.分別設置s1,s2上的/etc/profile的環境變量
9.s1中zookeeper的basedir相應的myid中的值改爲1s2zookeeper的basedir相應的myid中的值改爲2
10.啓動,在三個節點上分別執行命令zkServer.sh  start
11.三個節點的zookeeper都啓動後。檢驗,在三個節點上分別執行命令zkServer.sh  status


zookeeper的命令詳解

zookeeper四字命令的使用

需要在linux系統中安裝nc服務。yum install -y nc

操作命令的形式:[root@rocket zookeeper-server1]# echostat|nc 127.0.0.1 2181

zookeeper

四字命令

功能描述

conf

輸出相關服務配置的詳細信息。

cons

列出所有連接到服務器的客戶端的完全的連接 /會話的詳細信息。包括“接受 / 發送”的包數量、會話 id 、操作延遲、最後的操作執行等等信息。

dump

列出未經處理的會話和臨時節點。

envi

輸出關於服務環境的詳細信息(區別於 conf命令)。

reqs

列出未經處理的請求

ruok

測試服務是否處於正確狀態。如果確實如此,那麼服務返回“imok ”,否則不做任何相應。

stat

輸出關於性能和連接的客戶端的列表。

wchs

列出服務器 watch的詳細信息。

wchc

通過 session列出服務器 watch的詳細信息,它的輸出是一個與watch相關的會話的列表。

wchp

通過路徑列出服務器 watch的詳細信息。它輸出一個與 session相關的路徑


zkServer.sh命令詳解

命令操作形式:[root@rocket zookeeper-server1]# bin/zkServer.sh status//status爲命令參數
命令參數:
start:開啓服務;
stop:停止服務;
restart:重啓服務;
start-foreground:查看啓動時報的是什麼異常,同時也可以查看運行過程中的異常
upgrade:更新zookeeper;
print-cmd:打印配置信息;
help:列出參數,如下:

[root@rocket zookeeper-server1]# bin/zkServer.sh help

JMX enabled by default

Using config: /usr/local/zookeeper-server1/bin/../conf/zoo.cfg

Usage: bin/zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}


zkCli.sh命令詳解

鏈接:[root@rocket zookeeper-server1]# bin/zkCli.sh -server localhost:2181
[zk: localhost:2181(CONNECTED) 0] help//列出命令參數

        stat path [watch]

        set path data [version]

        ls path [watch]

        delquota [-n|-b] path

        ls2 path [watch]

        setAcl path acl

        setquota -n|-b val path

        history

        redo cmdno

        printwatches on|off

        delete path [version]

        sync path

        listquota path

        rmr path

        get path [watch]

        create [-s] [-e] path data acl

        addauth scheme auth

        quit

        getAcl path

        close

        connect host:port


常用命令:

1)查看當前節點列表

[zk: localhost:2181(CONNECTED) 1] ls /

[zookeeper]

2)創建節點

[zk: localhost:2181(CONNECTED) 2] create /test "test"

Created /test

[zk: localhost:2181(CONNECTED) 3] ls /

[zookeeper, test]

3)查看節點數據

[zk: localhost:2181(CONNECTED) 4] get /test

"test"

cZxid = 0x300000007

ctime = Thu Sep 24 05:54:51 PDT 2015

mZxid = 0x300000007

mtime = Thu Sep 24 05:54:51 PDT 2015

pZxid = 0x300000007

cversion = 0

dataVersion = 0

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 6

numChildren = 0

4)設置節點數據

[zk: localhost:2181(CONNECTED) 7] set /test "111111" 

cZxid = 0x300000007

ctime = Thu Sep 24 05:54:51 PDT 2015

mZxid = 0x300000008

mtime = Thu Sep 24 05:57:40 PDT 2015

pZxid = 0x300000007

cversion = 0

dataVersion = 1

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 8

numChildren = 0

[zk: localhost:2181(CONNECTED) 8] get /test

"111111"

cZxid = 0x300000007

ctime = Thu Sep 24 05:54:51 PDT 2015

mZxid = 0x300000008

mtime = Thu Sep 24 05:57:40 PDT 2015

pZxid = 0x300000007

cversion = 0

dataVersion = 1

aclVersion = 0

ephemeralOwner = 0x0

dataLength = 8

numChildren = 0

5)刪除節點

[zk: localhost:2181(CONNECTED) 9] delete /test

[zk: localhost:2181(CONNECTED) 10] ls /

[zookeeper]




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章