1. centos7.6最小化安装 2. jdk1.8 3. zookeeper-3.4.14
[root@localhost soft]# tar -zxvf zookeeper-3.4.14.tar.gz
[root@localhost zookeeper-3.4.14]# cp conf/zoo_sample.cfg conf/zoo.cfg
将dataDir修改为/soft/zookeeper-3.4.14/dataDir
[root@localhost zookeeper-3.4.14]# mkdir /soft/zookeeper-3.4.14/dataDir
[root@localhost zookeeper-3.4.14]# cd /soft/zookeeper-3.4.14/bin [root@localhost bin]# ./zkServer.sh start ZooKeeper JMX enabled by default Using config: /soft/zookeeper-3.4.14/bin/…/conf/zoo.cfg Starting zookeeper … STARTED
[root@localhost bin]# ./zkCli.sh Connecting to localhost:2181 … Welcome to ZooKeeper! … WATCHER:: WatchedEvent state:SyncConnected type:None path:null [zk: localhost:2181(CONNECTED) 0] 看到这里说明成功的连接到了服务端
[zk: localhost:2181(CONNECTED) 0] ls / [zookeeper]
[zk: localhost:2181(CONNECTED) 1] create /zkdemo "this is a demo" Created /zkdemo
[zk: localhost:2181(CONNECTED) 2] ls / [zookeeper, zkdemo]
[zk: localhost:2181(CONNECTED) 3] get /zkdemo this is a demo cZxid = 0x2 ctime = Tue May 21 23:17:38 CST 2019 mZxid = 0x2 mtime = Tue May 21 23:17:38 CST 2019 pZxid = 0x2 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 14 numChildren = 0
[zk: localhost:2181(CONNECTED) 4] set /zkdemo "another" cZxid = 0x2 ctime = Tue May 21 23:17:38 CST 2019 mZxid = 0x3 mtime = Tue May 21 23:21:43 CST 2019 pZxid = 0x2 cversion = 0 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 7 numChildren = 0
[zk: localhost:2181(CONNECTED) 5] get /zkdemo another cZxid = 0x2 ctime = Tue May 21 23:17:38 CST 2019 mZxid = 0x3 mtime = Tue May 21 23:21:43 CST 2019 pZxid = 0x2 cversion = 0 dataVersion = 1 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 7 numChildren = 0
[zk: localhost:2181(CONNECTED) 6] delete /zkdemo [zk: localhost:2181(CONNECTED) 7] ls / [zookeeper]
[zk: localhost:2181(CONNECTED) 8] quit Quitting… 2019-05-21 23:27:21,823 [myid:] - INFO [main:ZooKeeper@693] - Session: 0x1000025f0f80000 closed 2019-05-21 23:27:21,829 [myid:] - INFO [main-EventThread:ClientCnxn$EventThread@522] - EventThread shut down for session: 0x1000025f0f80000
[root@localhost bin]# ./zkServer.sh stop ZooKeeper JMX enabled by default Using config: /soft/zookeeper-3.4.14/bin/…/conf/zoo.cfg Stopping zookeeper … STOPPED 其他:上面启动zkServer是后台执行的方式,如果想前台启动的话使用命令: [root@localhost bin]# ./zkServer.sh start-foreground