mac運行zookeeper

參考:https://www.jianshu.com/p/5491d16e6abd

1.官方安裝指南:http://zookeeper.apache.org/doc/current/zookeeperStarted.html

2.下載地址:http://zookeeper.apache.org/releases.html(如果這個下載地址失效了,去上面的鏈接的download裏面找)

   我下載的3.4.14版本

3.下載後,雙擊就可以解壓了

4.修改zoo_sample.conf 爲zoo.conf

這裏的zoo_sample.conf只是給我們提供了示例。我們要改名爲正式的配置文件

並在zoo.conf裏修改dataDir,命令如下

先進入cd zookeeper-3.4.14/conf/目錄(pwd可查看當前目錄)

mv zoo_sample.cfg zoo.cfg
vi zoo.cfg

我在zookeeper-3.4.14/目錄下創建了data目錄,然後dataDir設置爲../data

5.啓動Server

cd /bin
./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /Users/yuchunping/development/zookeeper/zookeeper-3.4.14/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

 6.另外開個終端,啓動客戶端

cd zookeeper-3.4.14/bin //切換到 bin目錄
./zkCli.sh -server 127.0.0.1:2181
Connecting to 127.0.0.1:2181
2020-04-12 12:42:05,690 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.14-4c25d480e66aadd371de8bd2fd8da255ac140bcf, built on 03/06/2019 16:18 GMT

輸入help命令

WatchedEvent state:SyncConnected type:None path:null
[zk: 127.0.0.1:2181(CONNECTED) 0] help
ZooKeeper -server host:port cmd args
	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

7.官方測試命令

[zk: 127.0.0.1:2181(CONNECTED) 1] ls /
[zookeeper]
[zk: 127.0.0.1:2181(CONNECTED) 2] create /zk_test my_data
Created /zk_test
[zk: 127.0.0.1:2181(CONNECTED) 3] ls /
[zookeeper, zk_test]
[zk: 127.0.0.1:2181(CONNECTED) 4] get /zookeeper

cZxid = 0x0
ctime = Thu Jan 01 08:00:00 CST 1970
mZxid = 0x0
mtime = Thu Jan 01 08:00:00 CST 1970
pZxid = 0x0
cversion = -1
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 1
[zk: 127.0.0.1:2181(CONNECTED) 5] get /zk_test
my_data
cZxid = 0x7
ctime = Sun Apr 12 12:44:20 CST 2020
mZxid = 0x7
mtime = Sun Apr 12 12:44:20 CST 2020
pZxid = 0x7
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 7
numChildren = 0
[zk: 127.0.0.1:2181(CONNECTED) 6] set /zk_test junk
cZxid = 0x7
ctime = Sun Apr 12 12:44:20 CST 2020
mZxid = 0x8
mtime = Sun Apr 12 12:44:56 CST 2020
pZxid = 0x7
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0
[zk: 127.0.0.1:2181(CONNECTED) 7] get /zk_test
junk
cZxid = 0x7
ctime = Sun Apr 12 12:44:20 CST 2020
mZxid = 0x8
mtime = Sun Apr 12 12:44:56 CST 2020
pZxid = 0x7
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 4
numChildren = 0
[zk: 127.0.0.1:2181(CONNECTED) 8] delete /zk_test
[zk: 127.0.0.1:2181(CONNECTED) 9] ls /
[zookeeper]
[zk: 127.0.0.1:2181(CONNECTED) 10] quit
Quitting...
2020-04-12 12:46:33,941 [myid:] - INFO  [main:ZooKeeper@693] - Session: 0x100022da94e0000 closed
2020-04-12 12:46:33,944 [myid:] - INFO  [main-EventThread:ClientCnxn$EventThread@522] - EventThread shut down for session: 0x100022da94e0000

8.停止server

./zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /Users/yuchunping/development/zookeeper/zookeeper-3.4.14/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED

(因爲之前退出了客戶端,所以客戶端沒有報錯)

(以下內容來自上面列出的參考文章:https://www.jianshu.com/p/5491d16e6abd)

配置文件說明

  1. 文件名可以任意,不是非得改爲zoo.cfg
  2. tickTime: zookeeper中使用的基本時間單位, 毫秒
  3. dataDir: 內存數據快照的保存目錄;如果沒有自定義Log也使用該目錄
  4. clientPort: 監聽Cli連接的端口號
    # 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=../data
    # the port at which the clients will connect
    clientPort=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

     

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