概述
zookeeper是使用java编写的,所以在安装之前必须要安装java运行环境。另外,zookeeper支持单机部署和集群部署。
单机部署
安装部署
- 在apache官网下载zookeeper。
- 将下载好的安装包解压到指定目录,解压后可以看到zookeeper包含很多目录,其中conf是存放配置文件的目录,bin是zookeeper提供的可执行脚本的目录。
- ${Zookeeper_Home}\conf目录下提供了zookeeper核心配置的样例文件zoo_sample.cfg,如果将zookeeper运行起来,需要将其名称修改为zoo.cfg,内容可以暂时不修改。
[root@localhost apache-zookeeper-3.6.3-bin]# ls
bin conf docs lib LICENSE.txt NOTICE.txt README.md README_packaging.md
[root@localhost apache-zookeeper-3.6.3-bin]# cd conf/
[root@localhost conf]# ls
configuration.xsl log4j.properties zoo_sample.cfg
[root@localhost conf]# cp zoo_sample.cfg zoo.cfg
[root@localhost conf]# ls
configuration.xsl log4j.properties zoo.cfg zoo_sample.cfg
# zoo.cfg配置文件的内容
[root@localhost conf]# cat zoo.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
- 在${Zookeeper_Home}\bin路径下,执行sh zkServer.sh start,启动服务。
[root@localhost bin]# sh zkServer.sh start
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /opt/apache-zookeeper-3.6.3-bin/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
- 启动服务之后,就可以通过默认发布的2181端口来访问。如果是在同一台机器上访问。通过sh zkCli.sh即可连接到ZooKeeper服务器。如果连接到不同机器上的zookeeper服务,需要添加-server参数,即sh zkCli.sh -server targert-server-ip:2181。
[root@localhost bin]# sh zkCli.sh
/usr/bin/java
Connecting to localhost:2181
2021-04-18 10:35:56,367 [myid:] - INFO [main:Environment@98] - Client environment:zookeeper.version=3.6.3--6401e4ad2087061bc6b9f80dec2d69f2e3c8660a, built on 04/08/2021 16:35 GMT
2021-04-18 10:35:56,369 [myid:] - INFO [main:Environment@98] - Client environment:host.name=localhost
2021-04-18 10:35:56,369 [myid:] - INFO [main:Environment@98] - Client environment:java.version=1.8.0_252
2021-04-18 10:35:56,371 [myid:] - INFO [main:Environment@98] - Client environment:java.vendor=Oracle Corporation
2021-04-18 10:35:56,372 [myid:] - INFO [main:Environment@98] - Client environment:java.home=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.el8_1.x86_64/jre
2021-04-18 10:35:56,372 [myid:] - INFO [main:Environment@98] - Client environment:java.class.path=/opt/apache-zookeeper-3.6.3-bin/bin/../zookeeper-server/target/classes:/opt/apache-zookeeper-3.6.3-bin/bin/../build/classes:/opt/apache-zookeeper-3.6.3-bin/bin/../zookeeper-server/target/lib/*.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../build/lib/*.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/zookeeper-prometheus-metrics-3.6.3.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/zookeeper-jute-3.6.3.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/zookeeper-3.6.3.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/snappy-java-1.1.7.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/slf4j-log4j12-1.7.25.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/slf4j-api-1.7.25.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/simpleclient_servlet-0.6.0.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/simpleclient_hotspot-0.6.0.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/simpleclient_common-0.6.0.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/simpleclient-0.6.0.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/netty-transport-native-unix-common-4.1.63.Final.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/netty-transport-native-epoll-4.1.63.Final.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/netty-transport-4.1.63.Final.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/netty-resolver-4.1.63.Final.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/netty-handler-4.1.63.Final.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/netty-common-4.1.63.Final.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/netty-codec-4.1.63.Final.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/netty-buffer-4.1.63.Final.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/metrics-core-3.2.5.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/log4j-1.2.17.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/json-simple-1.1.1.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/jline-2.14.6.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/jetty-util-ajax-9.4.39.v20210325.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/jetty-util-9.4.39.v20210325.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/jetty-servlet-9.4.39.v20210325.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/jetty-server-9.4.39.v20210325.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/jetty-security-9.4.39.v20210325.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/jetty-io-9.4.39.v20210325.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/jetty-http-9.4.39.v20210325.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/javax.servlet-api-3.1.0.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/jackson-databind-2.10.5.1.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/jackson-core-2.10.5.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/jackson-annotations-2.10.5.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/commons-cli-1.2.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../lib/audience-annotations-0.5.0.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../zookeeper-*.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../zookeeper-server/src/main/resources/lib/*.jar:/opt/apache-zookeeper-3.6.3-bin/bin/../conf:
2021-04-18 10:35:56,372 [myid:] - INFO [main:Environment@98] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2021-04-18 10:35:56,373 [myid:] - INFO [main:Environment@98] - Client environment:java.io.tmpdir=/tmp
2021-04-18 10:35:56,373 [myid:] - INFO [main:Environment@98] - Client environment:java.compiler=<NA>
2021-04-18 10:35:56,373 [myid:] - INFO [main:Environment@98] - Client environment:os.name=Linux
2021-04-18 10:35:56,373 [myid:] - INFO [main:Environment@98] - Client environment:os.arch=amd64
2021-04-18 10:35:56,373 [myid:] - INFO [main:Environment@98] - Client environment:os.version=4.18.0-147.el8.x86_64
2021-04-18 10:35:56,373 [myid:] - INFO [main:Environment@98] - Client environment:user.name=root
2021-04-18 10:35:56,373 [myid:] - INFO [main:Environment@98] - Client environment:user.home=/root
2021-04-18 10:35:56,373 [myid:] - INFO [main:Environment@98] - Client environment:user.dir=/opt/apache-zookeeper-3.6.3-bin/bin
2021-04-18 10:35:56,373 [myid:] - INFO [main:Environment@98] - Client environment:os.memory.free=22MB
2021-04-18 10:35:56,375 [myid:] - INFO [main:Environment@98] - Client environment:os.memory.max=228MB
2021-04-18 10:35:56,375 [myid:] - INFO [main:Environment@98] - Client environment:os.memory.total=29MB
2021-04-18 10:35:56,378 [myid:] - INFO [main:ZooKeeper@1006] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@5e265ba4
2021-04-18 10:35:56,383 [myid:] - INFO [main:X509Util@77] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2021-04-18 10:35:56,389 [myid:] - INFO [main:ClientCnxnSocket@239] - jute.maxbuffer value is 1048575 Bytes
2021-04-18 10:35:56,403 [myid:] - INFO [main:ClientCnxn@1736] - zookeeper.request.timeout value is 0. feature enabled=false
Welcome to ZooKeeper!
2021-04-18 10:35:56,439 [myid:localhost:2181] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1181] - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181.
2021-04-18 10:35:56,439 [myid:localhost:2181] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1183] - SASL config status: Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2021-04-18 10:35:56,502 [myid:localhost:2181] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1013] - Socket connection established, initiating session, client: /0:0:0:0:0:0:0:1:50192, server: localhost/0:0:0:0:0:0:0:1:2181
2021-04-18 10:35:56,524 [myid:localhost:2181] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1448] - Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181, session id = 0x100000684690000, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0]
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/100351.html