Connect to ZooKeeper via CLI
The simplest way to begin working with ZooKeeper is to use its command line interface (CLI). This console is available on each ZooKeeper node immediately after its installation. To start working with CLI, run the zkCli.sh script located in the /bin directory:
$ sudo /usr/lib/zookeeper/bin/zkCli.sh
The output
2021-12-15 11:04:55,901 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.14-f42ef4b166f1e5c63117c75aed651589a0cce1b2, built on 08/06/2019 14:49 GMT 2021-12-15 11:04:55,903 [myid:] - INFO [main:Environment@100] - Client environment:host.name=bds-adh-1.ru-central1.internal 2021-12-15 11:04:55,904 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.8.0_312 2021-12-15 11:04:55,905 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Red Hat, Inc. 2021-12-15 11:04:55,906 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.el7_9.x86_64/jre 2021-12-15 11:04:55,906 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/usr/lib/zookeeper/bin/../zookeeper-server/target/classes:/usr/lib/zookeeper/bin/../build/classes:/usr/lib/zookeeper/bin/../zookeeper-server/target/lib/*.jar:/usr/lib/zookeeper/bin/../build/lib/*.jar:/usr/lib/zookeeper/bin/../lib/slf4j-log4j12-1.7.25.jar:/usr/lib/zookeeper/bin/../lib/slf4j-api-1.7.25.jar:/usr/lib/zookeeper/bin/../lib/netty-3.10.6.Final.jar:/usr/lib/zookeeper/bin/../lib/log4j-1.2.17.jar:/usr/lib/zookeeper/bin/../lib/jline-0.9.94.jar:/usr/lib/zookeeper/bin/../lib/audience-annotations-0.5.0.jar:/usr/lib/zookeeper/bin/../zookeeper-3.4.14.jar:/usr/lib/zookeeper/bin/../zookeeper-server/src/main/resources/lib/*.jar:/usr/lib/zookeeper/bin/../conf: 2021-12-15 11:04:55,906 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib 2021-12-15 11:04:55,906 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp 2021-12-15 11:04:55,906 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA> 2021-12-15 11:04:55,906 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux 2021-12-15 11:04:55,906 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64 2021-12-15 11:04:55,906 [myid:] - INFO [main:Environment@100] - Client environment:os.version=3.10.0-1160.11.1.el7.x86_64 2021-12-15 11:04:55,907 [myid:] - INFO [main:Environment@100] - Client environment:user.name=root 2021-12-15 11:04:55,907 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/root 2021-12-15 11:04:55,907 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/home/dasha 2021-12-15 11:04:55,908 [myid:] - INFO [main:ZooKeeper@442] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@4b85612c Welcome to ZooKeeper! 2021-12-15 11:04:55,928 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1025] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error) JLine support is enabled 2021-12-15 11:04:55,973 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@879] - Socket connection established to localhost/127.0.0.1:2181, initiating session 2021-12-15 11:04:55,981 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x100005560090006, negotiated timeout = 30000 WATCHER:: WatchedEvent state:SyncConnected type:None path:null [zk: localhost:2181(CONNECTED) 0]
The ZooKeeper CLI prompt starts with [zk: localhost:2181(CONNECTED) 0]
. All subsequent commands should be written after it.
To logout from ZooKeeper CLI, use the following command:
quit