目录
- 一、下载Zookeeper
- 二、修改配置
- 1、设置启动配置文件
- 2、修改配置
- 三、启动Zookeeper服务命令
- 1、bin目录下执行
- (1)启动Zookeeper命令
- (2)查看Zookeeper状态命令
- (3)停止Zookeeper命令
- 2、配置环境变量执行
- (1)配置环境变量
- (2)启动Zookeeper命令
- (3)查看Zookeeper状态命令
- (4)停止Zookeeper命令
- 四、启动Zookeeper客户端命令
注:环境下要默认安装JDK。
一、下载Zookeeper
下载地址:https://zookeeper.apache.org/releases.html
下载压缩包,然后解压到自己的目录中。
二、修改配置
1、设置启动配置文件
进入 Zookeeper
的 conf
目录,将 zoo_sample.cfg
配置文件复制一份,重新命名为 zoo.cfg
(默认启动配置文件)。
2、修改配置
打开 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=/Users/davis/soft/zookeeper-3.6.3/data
dataLogDir=/Users/davis/soft/zookeeper-3.6.3/logs
# 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
...
三、启动Zookeeper服务命令
执行Zookeeper命令有两种方式,一种是到bin目录下执行命令启动,另一种是配置好环境变量后执行命令启动。
1、bin目录下执行
进入到Zookeeper的bin目录下,执行如下命令来操作Zookeeper。
(1)启动Zookeeper命令
./zkServer.sh start
执行结果:
ZooKeeper JMX enabled by default
Using config: /Users/davis/soft/zookeeper-3.6.3/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
(2)查看Zookeeper状态命令
./zkServer.sh status
执行结果:
ZooKeeper JMX enabled by default
Using config: /Users/davis/soft/zookeeper-3.6.3/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: standalone
(3)停止Zookeeper命令
./zkServer.sh stop
2、配置环境变量执行
(1)配置环境变量
设置环境变量,打开 .bash_profile
文件,输入如下命令进行修改:
sudo vi ~/.bash_profile
添加如下内容:
# Zookeeper
export ZK_HOME=/Users/davis/soft/zookeeper-3.6.3
export PATH=$PATH:$ZK_HOME/bin
修改完后,执行 source
命令保存:
source ~/.bash_profile
配置好环境变量后,在终端直接输入命令即可:
(2)启动Zookeeper命令
zkServer.sh start
执行结果:
ZooKeeper JMX enabled by default
Using config: /Users/davis/soft/zookeeper-3.6.3/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
(3)查看Zookeeper状态命令
zkServer.sh status
执行结果:
ZooKeeper JMX enabled by default
Using config: /Users/davis/soft/zookeeper-3.6.3/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: standalone
(4)停止Zookeeper命令
zkServer.sh stop
四、启动Zookeeper客户端命令
# Zookeeper的bin目录下执行
./zkCli.sh -server 127.0.0.1:2181
./zkCli.sh -server localhost# 配置环境变量后执行
zkCli.sh -server 127.0.0.1:2181
zkCli.sh -server localhost
结果:
Connecting to localhost
2022-03-04 17:10:23,677 [myid:] - INFO [main:Environment@98] - Client environment:zookeeper.version=3.6.3--6401e4ad2087061bc6b9f80dec2d69f2e3c8660a, built on 04/08/2021 16:35 GMT
2022-03-04 17:10:23,681 [myid:] - INFO [main:Environment@98] - Client environment:host.name=10.0.22.112
2022-03-04 17:10:23,681 [myid:] - INFO [main:Environment@98] - Client environment:java.version=1.8.0_121
2022-03-04 17:10:23,683 [myid:] - INFO [main:Environment@98] - Client environment:java.vendor=Oracle Corporation
2022-03-04 17:10:23,684 [myid:] - INFO [main:Environment@98] - Client environment:java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre
2022-03-04 17:10:23,684 [myid:] - INFO [main:Environment@98] - Client environment:java.class.path=/Users/davis/soft/zookeeper-3.6.3/bin/../zookeeper-server/target/classes:/Users/davis/soft/zookeeper-3.6.3/bin/../build/classes:/Users/davis/soft/zookeeper-3.6.3/bin/../zookeeper-server/target/lib/*.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../build/lib/*.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/zookeeper-prometheus-metrics-3.6.3.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/zookeeper-jute-3.6.3.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/zookeeper-3.6.3.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/snappy-java-1.1.7.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/slf4j-log4j12-1.7.25.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/slf4j-api-1.7.25.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/simpleclient_servlet-0.6.0.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/simpleclient_hotspot-0.6.0.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/simpleclient_common-0.6.0.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/simpleclient-0.6.0.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/netty-transport-native-unix-common-4.1.63.Final.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/netty-transport-native-epoll-4.1.63.Final.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/netty-transport-4.1.63.Final.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/netty-resolver-4.1.63.Final.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/netty-handler-4.1.63.Final.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/netty-common-4.1.63.Final.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/netty-codec-4.1.63.Final.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/netty-buffer-4.1.63.Final.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/metrics-core-3.2.5.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/log4j-1.2.17.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/json-simple-1.1.1.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/jline-2.14.6.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/jetty-util-ajax-9.4.39.v20210325.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/jetty-util-9.4.39.v20210325.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/jetty-servlet-9.4.39.v20210325.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/jetty-server-9.4.39.v20210325.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/jetty-security-9.4.39.v20210325.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/jetty-io-9.4.39.v20210325.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/jetty-http-9.4.39.v20210325.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/javax.servlet-api-3.1.0.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/jackson-databind-2.10.5.1.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/jackson-core-2.10.5.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/jackson-annotations-2.10.5.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/commons-cli-1.2.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../lib/audience-annotations-0.5.0.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../zookeeper-*.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../zookeeper-server/src/main/resources/lib/*.jar:/Users/davis/soft/zookeeper-3.6.3/bin/../conf:
2022-03-04 17:10:23,684 [myid:] - INFO [main:Environment@98] - Client environment:java.library.path=/Users/davis/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
2022-03-04 17:10:23,684 [myid:] - INFO [main:Environment@98] - Client environment:java.io.tmpdir=/var/folders/5n/6g464jd97r13x39t5w69ybfr0000gn/T/
2022-03-04 17:10:23,684 [myid:] - INFO [main:Environment@98] - Client environment:java.compiler=<NA>
2022-03-04 17:10:23,684 [myid:] - INFO [main:Environment@98] - Client environment:os.name=Mac OS X
2022-03-04 17:10:23,685 [myid:] - INFO [main:Environment@98] - Client environment:os.arch=x86_64
2022-03-04 17:10:23,685 [myid:] - INFO [main:Environment@98] - Client environment:os.version=10.15.5
2022-03-04 17:10:23,685 [myid:] - INFO [main:Environment@98] - Client environment:user.name=davis
2022-03-04 17:10:23,685 [myid:] - INFO [main:Environment@98] - Client environment:user.home=/Users/davis
2022-03-04 17:10:23,685 [myid:] - INFO [main:Environment@98] - Client environment:user.dir=/Users/davis/soft/zookeeper-3.6.3
2022-03-04 17:10:23,685 [myid:] - INFO [main:Environment@98] - Client environment:os.memory.free=237MB
2022-03-04 17:10:23,687 [myid:] - INFO [main:Environment@98] - Client environment:os.memory.max=245MB
2022-03-04 17:10:23,687 [myid:] - INFO [main:Environment@98] - Client environment:os.memory.total=245MB
2022-03-04 17:10:23,692 [myid:] - INFO [main:ZooKeeper@1006] - Initiating client connection, connectString=localhost sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@5aaa6d82
2022-03-04 17:10:23,695 [myid:] - INFO [main:X509Util@77] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2022-03-04 17:10:23,705 [myid:] - INFO [main:ClientCnxnSocket@239] - jute.maxbuffer value is 1048575 Bytes
2022-03-04 17:10:23,712 [myid:] - INFO [main:ClientCnxn@1736] - zookeeper.request.timeout value is 0. feature enabled=false
Welcome to ZooKeeper!
2022-03-04 17:10:23,720 [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.
2022-03-04 17:10:23,721 [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
2022-03-04 17:10:23,778 [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:63550, server: localhost/0:0:0:0:0:0:0:1:2181
2022-03-04 17:10:23,810 [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 = 0x1005b53cb000000, negotiated timeout = 30000WATCHER::WatchedEvent state:SyncConnected type:None path:null
[zk: localhost(CONNECTED) 0]