在CentOS7上安裝和使用ZooKeeper最新版本(V3.4.11)
阿新 • • 發佈:2018-08-21
eve nvi rgs tty time history hang info js xml
0.ZooKeeper文檔
http://zookeeper.apache.org/doc/r3.4.11/zookeeperOver.html
1.準備
在CentOS7上安裝zookeeper時,如下工具必須要有:wget
如果沒有,則進行安裝:
yum -y install wget
2.下載安裝
下載到本地
- cd /usr/local/src
- wget http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.tar.gz
解壓
tar -xzvf zookeeper-3.4.11.tar.gz
創建的安裝目錄,並移動解壓後的目錄到其下
- mkdir -p ../zookeeper
- mv zookeeper-3.4.11/ ../zookeeper
創建數據目錄,用於存放數據
mkdir -p /var/lib/zookeeper
創建配置
- cd ../zookeeper/zookeeper-3.4.11/conf
- cp zoo_sample.cfg zoo.cfg
修改其中配置dataDir:
vi zoo.cfg
dataDir=/var/lib/zookeeper
3.啟動服務
- cd ..
- ./bin/zkServer.sh start
輸出如下信息,表示啟動成功
- Connecting to 127.0.0.1:2181
- 2018-02-09 14:56:10,914 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.11-37e277162d567b55a07d1755f0b31c32e93c01a0, built on 11/01/2017 18:06 GMT
-
2018-02-09 14:56:10,922 [myid:] - INFO [main:Environment@100] - Client environment:host.name=jiaodacailei-thinkpad-centos7
- 2018-02-09 14:56:10,922 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.8.0_161
- 2018-02-09 14:56:10,927 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
- 2018-02-09 14:56:10,927 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/usr/local/jdk/jdk1.8.0_161/jre
- 2018-02-09 14:56:10,927 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/usr/local/zookeeper/zookeeper-3.4.11/bin/../build/classes:/usr/local/zookeeper/zookeeper-3.4.11/bin/../build/lib/*.jar:/usr/local/zookeeper/zookeeper-3.4.11/bin/../lib/slf4j-log4j12-1.6.1.jar:/usr/local/zookeeper/zookeeper-3.4.11/bin/../lib/slf4j-api-1.6.1.jar:/usr/local/zookeeper/zookeeper-3.4.11/bin/../lib/netty-3.10.5.Final.jar:/usr/local/zookeeper/zookeeper-3.4.11/bin/../lib/log4j-1.2.16.jar:/usr/local/zookeeper/zookeeper-3.4.11/bin/../lib/jline-0.9.94.jar:/usr/local/zookeeper/zookeeper-3.4.11/bin/../lib/audience-annotations-0.5.0.jar:/usr/local/zookeeper/zookeeper-3.4.11/bin/../zookeeper-3.4.11.jar:/usr/local/zookeeper/zookeeper-3.4.11/bin/../src/java/lib/*.jar:/usr/local/zookeeper/zookeeper-3.4.11/bin/../conf::/usr/local/jdk/jdk1.8.0_161/lib/dt.jar:/usr/local/jdk/jdk1.8.0_161/lib/tools.jar:/usr/local/jdk/jdk1.8.0_161/jre/lib/dt.jar
- 2018-02-09 14:56:10,927 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
- 2018-02-09 14:56:10,928 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
- 2018-02-09 14:56:10,928 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA>
- 2018-02-09 14:56:10,928 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux
- 2018-02-09 14:56:10,928 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64
- 2018-02-09 14:56:10,928 [myid:] - INFO [main:Environment@100] - Client environment:os.version=3.10.0-693.el7.x86_64
- 2018-02-09 14:56:10,929 [myid:] - INFO [main:Environment@100] - Client environment:user.name=root
- 2018-02-09 14:56:10,929 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/root
- 2018-02-09 14:56:10,929 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/usr/local/zookeeper/zookeeper-3.4.11
- 2018-02-09 14:56:10,932 [myid:] - INFO [main:ZooKeeper@441] - Initiating client connection, connectString=127.0.0.1:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@579bb367
- Welcome to ZooKeeper!
- 2018-02-09 14:56:10,983 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1035] - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
- JLine support is enabled
- 2018-02-09 14:56:11,141 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@877] - Socket connection established to 127.0.0.1/127.0.0.1:2181, initiating session
- [zk: 127.0.0.1:2181(CONNECTING) 0] 2018-02-09 14:56:11,242 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1302] - Session establishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x1000150f9ff0000, negotiated timeout = 30000
- WATCHER::
- WatchedEvent state:SyncConnected type:None path:null
4.啟動客戶端
./bin/zkCli.sh -server 127.0.0.1:2181
輸入如下,等待用戶輸入命令:
[zk: 127.0.0.1:2181(CONNECTED) 0]
5.獲取幫助
輸入如下命令,可以獲取幫助信息:
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
上面是所有可以使用的命令
6.ls命令
ls /
默認根節點下有一個zookeeper節點
[zookeeper]
7.創建節點
創建節點采用create命令,創建之後查看根路徑,發現多了一個節點;
通過get命令,可以查詢節點路徑對應的數據
- [
- Created /zk_test
- [
- [
- [
- test_data
- cZxid = 0x2
- ctime = Fri Feb 09 15:19:11 CST 2018
- mZxid = 0x2
- mtime = Fri Feb 09 15:19:11 CST 2018
- pZxid = 0x2
- cversion = 0
- dataVersion = 0
- aclVersion = 0
- ephemeralOwner = 0x0
- dataLength = 9
- numChildren = 0
8.修改節點數據
set命令可以修改路徑對應的節點數據,修改後再通過get命令查看結果
[zk: 127.0.0.1:2181(CONNECTED) 8] set /zk_test test_data_change
cZxid = 0x2
ctime = Fri Feb 09 15:19:11 CST 2018
mZxid = 0x3
mtime = Fri Feb 09 15:21:31 CST 2018
pZxid = 0x2
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 16
numChildren = 0
[zk: 127.0.0.1:2181(CONNECTED) 10] get /zk_test
test_data_change
cZxid = 0x2
ctime = Fri Feb 09 15:19:11 CST 2018
mZxid = 0x3
mtime = Fri Feb 09 15:21:31 CST 2018
pZxid = 0x2
cversion = 0
dataVersion = 1
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 16
numChildren = 0
9.刪除節點
delete命令可以刪除路徑對應的節點,刪除之後,通過ls命令查看其父路徑,可以看到節點已經減少一個
- [
- [
- [
10.退出客戶端
quit
11.停止服務
./bin/zkServer.sh stop
在CentOS7上安裝和使用ZooKeeper最新版本(V3.4.11)