一、官方网站下载安装包

 

Index of /zookeeper

选择需要的版本,下载相关压缩包(例:apache-zookeeper-3.7.0-bin.tar.gz )

二、正式安装

1、解压目录,并且新建data目录

[root@i-slebi7x6 opt]# cd zookeeper/
[root@i-slebi7x6 zookeeper]# ls
apache-zookeeper-3.7.0.tar.gz
[root@i-slebi7x6 zookeeper]# tar -zxf  apache-zookeeper-3.7.0-bin.tar.gz
[root@i-slebi7x6 zookeeper]# ls
apache-zookeeper-3.7.0-bin  
[root@i-slebi7x6 zookeeper]# cd apache-zookeeper-3.7.0-bin
[root@i-slebi7x6 apache-zookeeper-3.7.0-bin]# ls
bin  conf  docs  lib  LICENSE.txt  NOTICE.txt  README.md  README_packaging.md
[root@i-slebi7x6 apache-zookeeper-3.7.0-bin]# mkdir data
[root@i-slebi7x6 apache-zookeeper-3.7.0-bin]# ls
bin  conf  data  docs  lib  LICENSE.txt  NOTICE.txt  README.md  README_packaging.md

2、复制conf目录下的zoo_sample.cfg为zoo.cfg。

[root@i-slebi7x6 conf]# cp zoo_sample.cfg zoo.cfg
[root@i-slebi7x6 conf]# ls
configuration.xsl  log4j.properties  zoo.cfg  zoo_sample.cfg

3、修改相关属性,配置dataDir地址。

zoo_sample.cfg

# 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=/tmp/zookeeper
# 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

## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true

zoo.cfg

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=5
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=2
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/opt/zookeeper/apache-zookeeper-3.7.0-bin/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

## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true

4、执行bin/zkServer.sh,启动zookeeper。

[root@i-slebi7x6 bin]# ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

停止zookeeper

./zkServer.sh stop

5、启动CLI

[root@i-slebi7x6 bin]# ./zkCli.sh
Connecting to localhost:2181
2022-01-19 16:16:37,390 [myid:] - INFO  [main:Environment@98] - Client environment:zookeeper.version=3.7.0-e3704b390a6697bfdf4b0bef79e3da7a4f6bac4b, built on 2021-03-17 09:46 UTC
2022-01-19 16:16:37,393 [myid:] - INFO  [main:Environment@98] - Client environment:host.name=i-slebi7x6
2022-01-19 16:16:37,394 [myid:] - INFO  [main:Environment@98] - Client environment:java.version=1.8.0_171
2022-01-19 16:16:37,396 [myid:] - INFO  [main:Environment@98] - Client environment:java.vendor=Oracle Corporation
2022-01-19 16:16:37,396 [myid:] - INFO  [main:Environment@98] - Client environment:java.home=/opt/jdk1.8.0_171/jre
2022-01-19 16:16:37,396 [myid:] - INFO  [main:Environment@98] - Client environment:java.class.path=/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../zookeeper-server/target/classes:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../build/classes:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../zookeeper-server/target/lib/*.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../build/lib/*.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/zookeeper-prometheus-metrics-3.7.0.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/zookeeper-jute-3.7.0.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/zookeeper-3.7.0.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/snappy-java-1.1.7.7.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/slf4j-log4j12-1.7.30.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/slf4j-api-1.7.30.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/simpleclient_servlet-0.9.0.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/simpleclient_hotspot-0.9.0.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/simpleclient_common-0.9.0.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/simpleclient-0.9.0.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/netty-transport-native-unix-common-4.1.59.Final.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/netty-transport-native-epoll-4.1.59.Final.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/netty-transport-4.1.59.Final.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/netty-resolver-4.1.59.Final.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/netty-handler-4.1.59.Final.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/netty-common-4.1.59.Final.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/netty-codec-4.1.59.Final.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/netty-buffer-4.1.59.Final.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/metrics-core-4.1.12.1.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/log4j-1.2.17.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/jline-2.14.6.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-util-ajax-9.4.38.v20210224.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-util-9.4.38.v20210224.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-servlet-9.4.38.v20210224.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-server-9.4.38.v20210224.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-security-9.4.38.v20210224.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-io-9.4.38.v20210224.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/jetty-http-9.4.38.v20210224.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/javax.servlet-api-3.1.0.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/jackson-databind-2.10.5.1.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/jackson-core-2.10.5.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/jackson-annotations-2.10.5.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/commons-cli-1.4.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../lib/audience-annotations-0.12.0.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../zookeeper-*.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../zookeeper-server/src/main/resources/lib/*.jar:/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin/../conf:.:/opt/jdk1.8.0_171/lib/dt.jar:/opt/jdk1.8.0_171/lib/tools.jar
2022-01-19 16:16:37,396 [myid:] - INFO  [main:Environment@98] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2022-01-19 16:16:37,396 [myid:] - INFO  [main:Environment@98] - Client environment:java.io.tmpdir=/tmp
2022-01-19 16:16:37,396 [myid:] - INFO  [main:Environment@98] - Client environment:java.compiler=<NA>
2022-01-19 16:16:37,396 [myid:] - INFO  [main:Environment@98] - Client environment:os.name=Linux
2022-01-19 16:16:37,396 [myid:] - INFO  [main:Environment@98] - Client environment:os.arch=amd64
2022-01-19 16:16:37,396 [myid:] - INFO  [main:Environment@98] - Client environment:os.version=4.18.0-240.el8.x86_64
2022-01-19 16:16:37,396 [myid:] - INFO  [main:Environment@98] - Client environment:user.name=root
2022-01-19 16:16:37,396 [myid:] - INFO  [main:Environment@98] - Client environment:user.home=/root
2022-01-19 16:16:37,397 [myid:] - INFO  [main:Environment@98] - Client environment:user.dir=/opt/zookeeper/apache-zookeeper-3.7.0-bin/bin
2022-01-19 16:16:37,397 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.free=52MB
2022-01-19 16:16:37,398 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.max=228MB
2022-01-19 16:16:37,398 [myid:] - INFO  [main:Environment@98] - Client environment:os.memory.total=59MB
2022-01-19 16:16:37,402 [myid:] - INFO  [main:ZooKeeper@637] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@24273305
2022-01-19 16:16:37,407 [myid:] - INFO  [main:X509Util@77] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2022-01-19 16:16:37,413 [myid:] - INFO  [main:ClientCnxnSocket@239] - jute.maxbuffer value is 1048575 Bytes
2022-01-19 16:16:37,424 [myid:] - INFO  [main:ClientCnxn@1726] - zookeeper.request.timeout value is 0. feature enabled=false
2022-01-19 16:16:37,438 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1171] - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181.
2022-01-19 16:16:37,439 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1173] - SASL config status: Will not attempt to authenticate using SASL (unknown error)
Welcome to ZooKeeper!
2022-01-19 16:16:37,447 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1005] - Socket connection established, initiating session, client: /0:0:0:0:0:0:0:1:44486, server: localhost/0:0:0:0:0:0:0:1:2181
JLine support is enabled
2022-01-19 16:16:37,501 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1438] - Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181, session id = 0x10162cbf71a0000, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0]

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐