官方文档
https://zookeeper.apache.org/doc/current/zookeeperStarted.html
下载Zookeeper
在下面的地址内下载最新的稳定版本:https://zookeeper.apache.org/releases.html
在linux服务器上执行下面的命令:
wget https://dlcdn.apache.org/zookeeper/zookeeper-3.7.1/apache-zookeeper-3.7.1-bin.tar.gz
king@king-server:~/workspace/zookeeper$ wget https://dlcdn.apache.org/zookeeper/zookeeper-3.7.1/apache-zookeeper-3.7.1-bin.tar.gz
--2023-04-01 15:33:03-- https://dlcdn.apache.org/zookeeper/zookeeper-3.7.1/apache-zookeeper-3.7.1-bin.tar.gz
Resolving dlcdn.apache.org (dlcdn.apache.org)... 2a04:4e42::644, 151.101.2.132
Connecting to dlcdn.apache.org (dlcdn.apache.org)|2a04:4e42::644|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 12649765 (12M) [application/x-gzip]
Saving to: ‘apache-zookeeper-3.7.1-bin.tar.gz’
apache-zookeeper-3.7.1-bin.tar.gz 100%[==============================================================================================>] 12.06M 13.5KB/s in 11m 30s
2023-04-01 15:44:43 (17.9 KB/s) - ‘apache-zookeeper-3.7.1-bin.tar.gz’ saved [12649765/12649765]
下载asc和sha512
使用下面的命令分别下载:
wget https://downloads.apache.org/zookeeper/zookeeper-3.7.1/apache-zookeeper-3.7.1-bin.tar.gz.asc
king@king-server:~/workspace/zookeeper$ wget https://downloads.apache.org/zookeeper/zookeeper-3.7.1/apache-zookeeper-3.7.1-bin.tar.gz.asc
--2023-04-01 16:05:48-- https://downloads.apache.org/zookeeper/zookeeper-3.7.1/apache-zookeeper-3.7.1-bin.tar.gz.asc
Resolving downloads.apache.org (downloads.apache.org)... 2a01:4f8:10a:201a::2, 2a01:4f9:3a:2c57::2, 135.181.214.104, ...
Connecting to downloads.apache.org (downloads.apache.org)|2a01:4f8:10a:201a::2|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 833 [text/plain]
Saving to: ‘apache-zookeeper-3.7.1-bin.tar.gz.asc’
apache-zookeeper-3.7.1-bin.tar.gz.asc 100%[==============================================================================================>] 833 --.-KB/s in 0s
2023-04-01 16:05:50 (303 MB/s) - ‘apache-zookeeper-3.7.1-bin.tar.gz.asc’ saved [833/833]
wget https://downloads.apache.org/zookeeper/zookeeper-3.7.1/apache-zookeeper-3.7.1-bin.tar.gz.sha512
king@king-server:~/workspace/zookeeper$ wget https://downloads.apache.org/zookeeper/zookeeper-3.7.1/apache-zookeeper-3.7.1-bin.tar.gz.sha512
--2023-04-01 16:06:29-- https://downloads.apache.org/zookeeper/zookeeper-3.7.1/apache-zookeeper-3.7.1-bin.tar.gz.sha512
Resolving downloads.apache.org (downloads.apache.org)... 2a01:4f9:3a:2c57::2, 2a01:4f8:10a:201a::2, 88.99.95.219, ...
Connecting to downloads.apache.org (downloads.apache.org)|2a01:4f9:3a:2c57::2|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 163 [text/plain]
Saving to: ‘apache-zookeeper-3.7.1-bin.tar.gz.sha512’
apache-zookeeper-3.7.1-bin.tar.gz.sha512 100%[==============================================================================================>] 163 --.-KB/s in 0s
2023-04-01 16:06:30 (46.2 MB/s) - ‘apache-zookeeper-3.7.1-bin.tar.gz.sha512’ saved [163/163]
验证文件的完整性
官方要求必须使用 PGP 签名(.asc文件)或散列(.md5或.sha*文件)验证下载文件的完整性
king@king-server:~/workspace/zookeeper$ ls
apache-zookeeper-3.7.1-bin.tar.gz apache-zookeeper-3.7.1-bin.tar.gz.asc apache-zookeeper-3.7.1-bin.tar.gz.sha512
验证文件的哈希值
king@king-server:~/workspace/zookeeper$ sha512sum apache-zookeeper-3.7.1-bin.tar.gz
9103628a50745fa1a289bca666fda4a9c08ec17c55cf13e66887e7ba76e93dbae60a1f1ffd6c10798be3a16069344ecbc00cebb29bf03d9cd7096ccd098ed011 apache-zookeeper-3.7.1-bin.tar.gz
与下载的sha512对比下
king@king-server:~/workspace/zookeeper$ sha512sum apache-zookeeper-3.7.1-bin.tar.gz
9103628a50745fa1a289bca666fda4a9c08ec17c55cf13e66887e7ba76e93dbae60a1f1ffd6c10798be3a16069344ecbc00cebb29bf03d9cd7096ccd098ed011 apache-zookeeper-3.7.1-bin.tar.gz
king@king-server:~/workspace/zookeeper$ cat apache-zookeeper-3.7.1-bin.tar.gz.sha512
9103628a50745fa1a289bca666fda4a9c08ec17c55cf13e66887e7ba76e93dbae60a1f1ffd6c10798be3a16069344ecbc00cebb29bf03d9cd7096ccd098ed011 apache-zookeeper-3.7.1-bin.tar.gz
单机部署
先将压缩包解压:
tar -zxvf apache-zookeeper-3.7.1-bin.tar.gz
king@king-server:~/workspace/zookeeper$ ls
apache-zookeeper-3.7.1-bin apache-zookeeper-3.7.1-bin.tar.gz apache-zookeeper-3.7.1-bin.tar.gz.asc apache-zookeeper-3.7.1-bin.tar.gz.sha512
进入conf目录:
king@king-server:~/workspace/zookeeper$ cd apache-zookeeper-3.7.1-bin/conf/
king@king-server:~/workspace/zookeeper/apache-zookeeper-3.7.1-bin/conf$ ls
configuration.xsl log4j.properties zoo_sample.cfg
其中zoo_sample.cfg是官方给出的示例文件
官方建议三个主要的配置:
tickTime=2000
dataDir=/var/lib/zookeeper
clientPort=2181
在给出实例中是:
tickTime=2000
dataDir=/tmp/zookeeper
clientPort=2181
可以使用实例默认的配置就可以。
tickTime:ZooKeeper 使用的基本时间单位,以毫秒为单位。它用于执行心跳,最小会话超时将是 tickTime 的两倍。
dataDir:存储内存数据库快照的位置,除非另有说明,否则存储更新数据库的事务日志。
clientPort:侦听客户端连接的端口
这里要在conf目录下新增文件zoo.cfg,然后将zoo_sample.cfg内的配置复制进去,因为启动时读取的配置是zoo_sample.cfg
启动
使用下面的命令启动:
../bin/zkServer.sh start
king@king-server:~/workspace/zookeeper/apache-zookeeper-3.7.1-bin/conf$ ls ../
bin conf docs lib LICENSE.txt NOTICE.txt README.md README_packaging.md
king@king-server:~/workspace/zookeeper/apache-zookeeper-3.7.1-bin/conf$ ../bin/zkServer.sh start
Error: JAVA_HOME is not set and java could not be found in PATH.
可以发现这里出现了一个错误,没有找到JAVA_HOME,这里还要安装下jdk。
安装jdk:
king@king-server:~/workspace/zookeeper/apache-zookeeper-3.7.1-bin/conf$ java -version
Command 'java' not found, but can be installed with:
sudo apt install openjdk-11-jre-headless # version 11.0.18+10-0ubuntu1~20.04.1, or
sudo apt install default-jre # version 2:1.11-72
sudo apt install openjdk-16-jre-headless # version 16.0.1+9-1~20.04
sudo apt install openjdk-17-jre-headless # version 17.0.6+10-0ubuntu1~20.04.1
sudo apt install openjdk-8-jre-headless # version 8u362-ga-0ubuntu1~20.04.1
sudo apt install openjdk-13-jre-headless # version 13.0.7+5-0ubuntu1~20.04
king@king-server:~/workspace/zookeeper/apache-zookeeper-3.7.1-bin/conf$ sudo apt install openjdk-8-jre-headless
[sudo] password for king:
...
king@king-server:~/workspace/zookeeper/apache-zookeeper-3.7.1-bin/conf$ java -version
openjdk version "1.8.0_362"
OpenJDK Runtime Environment (build 1.8.0_362-8u362-ga-0ubuntu1~20.04.1-b09)
OpenJDK 64-Bit Server VM (build 25.362-b09, mixed mode)
再次尝试启动:
king@king-server:~/workspace/zookeeper/apache-zookeeper-3.7.1-bin/conf$ ../bin/zkServer.sh start
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../conf/zoo.cfg
Starting zookeeper ... FAILED TO START
king@king-server:~/workspace/zookeeper/apache-zookeeper-3.7.1-bin/conf$
测试连接
使用下面的命令进行测试:
bin/zkCli.sh -server 127.0.0.1:2181
king@king-server:~/workspace/zookeeper/apache-zookeeper-3.7.1-bin/conf$ ../bin/zkCli.sh -server 127.0.0.1:2181
2023-04-05 04:36:34,559 [myid:127.0.0.1:2181] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1171] - Opening socket connection to server localhost/127.0.0.1:2181. 2023-04-05 04:36:34,559 [myid:127.0.0.1:2181] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1173] - SASL config status: Will not attempt to authenticate using SASL (unknown error)2023-04-05 04:36:34,559 [myid:127.0.0.1:2181] - WARN [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1294] - Session 0x0 for server localhost/127.0.0.1:2181, Closing socket connection. Attempting reconnect except it is a SessionExpiredException.java.net.ConnectException: Connection refused at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:716) at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:344) at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1283)
发现大量的报错。。。
将配置文件内dataDir修改为:/opt/zkData再次启动:
king@king-server:~/workspace/zookeeper/apache-zookeeper-3.7.1-bin$ bin/zkServer.sh start
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../conf/zoo.cfg
mkdir: cannot create directory ‘/opt/zkData’: Permission denied
Starting zookeeper ... bin/zkServer.sh: line 175: /opt/zkData/zookeeper_server.pid: No such file or directory
FAILED TO WRITE PID
看来并不会自动创建目录(也可能是权限不够用)
创建并修改权限(自行设置权限就好,我这里贪图方便直接777了):
king@king-server:~/workspace/zookeeper/apache-zookeeper-3.7.1-bin$ mkdir /opt/zkData
mkdir: cannot create directory ‘/opt/zkData’: Permission denied
king@king-server:~/workspace/zookeeper/apache-zookeeper-3.7.1-bin$ sudo mkdir /opt/zkData
king@king-server:~/workspace/zookeeper/apache-zookeeper-3.7.1-bin$ sudo chmod 777 /opt/zkData/
再次运行:
king@king-server:~/workspace/zookeeper/apache-zookeeper-3.7.1-bin$ bin/zkServer.sh start
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../conf/zoo.cfg
Starting zookeeper ... FAILED TO START
检查日志:
king@king-server:~/workspace/zookeeper/apache-zookeeper-3.7.1-bin$ cd logs
king@king-server:~/workspace/zookeeper/apache-zookeeper-3.7.1-bin/logs$ ls
zookeeper_audit.log zookeeper-king-server-king-server.out
king@king-server:~/workspace/zookeeper/apache-zookeeper-3.7.1-bin/logs$ less zookeeper-king-server-king-server.out
发现错误日志:
2023-04-05 04:50:54,373 [myid:1] - INFO [main:DefaultSessionIdManager@334] - DefaultSessionIdManager workerName=node0
2023-04-05 04:50:54,374 [myid:1] - INFO [main:DefaultSessionIdManager@339] - No SessionScavenger set, using defaults
2023-04-05 04:50:54,374 [myid:1] - INFO [main:HouseKeeper@132] - node0 Scavenging every 660000ms
2023-04-05 04:50:54,377 [myid:1] - WARN [main:ConstraintSecurityHandler@759] - ServletContext@o.e.j.s.ServletContextHandler@34cd072c{/,null,STARTING} has uncovered http methods for path: /*
2023-04-05 04:50:54,382 [myid:1] - INFO [main:ContextHandler@915] - Started o.e.j.s.ServletContextHandler@34cd072c{/,null,AVAILABLE}
2023-04-05 04:50:54,386 [myid:1] - ERROR [main:ZooKeeperServerMain@86] - Unable to start AdminServer, exiting abnormally
org.apache.zookeeper.server.admin.AdminServer$AdminServerException: Problem starting AdminServer on address 0.0.0.0, port 8080 and command URL /commands
at org.apache.zookeeper.server.admin.JettyAdminServer.start(JettyAdminServer.java:188)
at org.apache.zookeeper.server.ZooKeeperServerMain.runFromConfig(ZooKeeperServerMain.java:155)
at org.apache.zookeeper.server.ZooKeeperServerMain.initializeAndRun(ZooKeeperServerMain.java:113)
at org.apache.zookeeper.server.ZooKeeperServerMain.main(ZooKeeperServerMain.java:68)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:141)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:91)
Caused by: java.io.IOException: Failed to bind to /0.0.0.0:8080
at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:349)
at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:310)
at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:234)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:73)
at org.eclipse.jetty.server.Server.doStart(Server.java:401)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:73)
at org.apache.zookeeper.server.admin.JettyAdminServer.start(JettyAdminServer.java:179)
... 5 more
Caused by: java.net.BindException: Address already in use
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:461)
at sun.nio.ch.Net.bind(Net.java:453)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:222)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:85)
at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:344)
... 12 more
Unable to start AdminServer, exiting abnormally
2023-04-05 04:50:54,387 [myid:1] - INFO [main:ZKAuditProvider@42] - ZooKeeper audit is disabled.
2023-04-05 04:50:54,388 [myid:1] - ERROR [main:ServiceUtils@48] - Exiting JVM with code 4
原因是存在其他进程占用了8080端口,检查具体的进程:
king@king-server:~/workspace/zookeeper/apache-zookeeper-3.7.1-bin/logs$ sudo lsof -i :8080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
docker-pr 2263 root 4u IPv4 48370 0t0 TCP *:http-alt (LISTEN)
docker-pr 2270 root 4u IPv6 48375 0t0 TCP *:http-alt (LISTEN)
发现是docker容器占用了进程,检查具体的容器:
king@king-server:~/workspace/zookeeper/apache-zookeeper-3.7.1-bin/logs$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7c39ae707be0 importkey_server "/bin/sh -c './serve…" 2 months ago Up 2 weeks 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp server
9c0de2584f09 mysql:8.0.21 "docker-entrypoint.s…" 3 months ago Up 2 weeks 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp Mysql
发现是以前给老婆写的一个小server占用的。。。因为时间太久就忘了,这里先kill掉这个容器
king@king-server:~/workspace/zookeeper/apache-zookeeper-3.7.1-bin/logs$ docker kill 7c39ae707be0
7c39ae707be0
再次重新启动:
king@king-server:~/workspace/zookeeper/apache-zookeeper-3.7.1-bin$ bin/zkServer.sh start
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
发现已经可以启动成功,使用client测试:
king@king-server:~/workspace/zookeeper/apache-zookeeper-3.7.1-bin$ bin/zkCli.sh -server 127.0.0.1:2181
/usr/bin/java
Connecting to 127.0.0.1:2181
2023-04-05 05:18:30,578 [myid:] - INFO [main:Environment@98] - Client environment:zookeeper.version=3.7.1-a2fb57c55f8e59cdd76c34b357ad5181df1258d5, built on 2022-05-07 06:45 UTC
2023-04-05 05:18:30,580 [myid:] - INFO [main:Environment@98] - Client environment:host.name=king-server
2023-04-05 05:18:30,580 [myid:] - INFO [main:Environment@98] - Client environment:java.version=1.8.0_362
2023-04-05 05:18:30,580 [myid:] - INFO [main:Environment@98] - Client environment:java.vendor=Private Build
2023-04-05 05:18:30,580 [myid:] - INFO [main:Environment@98] - Client environment:java.home=/usr/lib/jvm/java-8-openjdk-amd64/jre
2023-04-05 05:18:30,580 [myid:] - INFO [main:Environment@98] - Client environment:java.class.path=/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../zookeeper-server/target/classes:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../build/classes:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../zookeeper-server/target/lib/*.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../build/lib/*.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/zookeeper-prometheus-metrics-3.7.1.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/zookeeper-jute-3.7.1.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/zookeeper-3.7.1.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/snappy-java-1.1.7.7.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/slf4j-reload4j-1.7.35.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/slf4j-api-1.7.35.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/simpleclient_servlet-0.9.0.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/simpleclient_hotspot-0.9.0.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/simpleclient_common-0.9.0.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/simpleclient-0.9.0.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/reload4j-1.2.19.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/netty-transport-native-unix-common-4.1.76.Final.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/netty-transport-native-epoll-4.1.76.Final.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/netty-transport-classes-epoll-4.1.76.Final.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/netty-transport-4.1.76.Final.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/netty-resolver-4.1.76.Final.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/netty-handler-4.1.76.Final.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/netty-common-4.1.76.Final.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/netty-codec-4.1.76.Final.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/netty-buffer-4.1.76.Final.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/metrics-core-4.1.12.1.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/jline-2.14.6.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/jetty-util-ajax-9.4.43.v20210629.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/jetty-util-9.4.43.v20210629.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/jetty-servlet-9.4.43.v20210629.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/jetty-server-9.4.43.v20210629.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/jetty-security-9.4.43.v20210629.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/jetty-io-9.4.43.v20210629.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/jetty-http-9.4.43.v20210629.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/javax.servlet-api-3.1.0.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/jackson-databind-2.13.2.1.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/jackson-core-2.13.2.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/jackson-annotations-2.13.2.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/commons-cli-1.4.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../lib/audience-annotations-0.12.0.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../zookeeper-*.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../zookeeper-server/src/main/resources/lib/*.jar:/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin/bin/../conf:
2023-04-05 05:18:30,580 [myid:] - INFO [main:Environment@98] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib
2023-04-05 05:18:30,581 [myid:] - INFO [main:Environment@98] - Client environment:java.io.tmpdir=/tmp
2023-04-05 05:18:30,581 [myid:] - INFO [main:Environment@98] - Client environment:java.compiler=<NA>
2023-04-05 05:18:30,581 [myid:] - INFO [main:Environment@98] - Client environment:os.name=Linux
2023-04-05 05:18:30,581 [myid:] - INFO [main:Environment@98] - Client environment:os.arch=amd64
2023-04-05 05:18:30,581 [myid:] - INFO [main:Environment@98] - Client environment:os.version=5.4.0-144-generic
2023-04-05 05:18:30,581 [myid:] - INFO [main:Environment@98] - Client environment:user.name=king
2023-04-05 05:18:30,581 [myid:] - INFO [main:Environment@98] - Client environment:user.home=/home/king
2023-04-05 05:18:30,581 [myid:] - INFO [main:Environment@98] - Client environment:user.dir=/home/king/workspace/zookeeper/apache-zookeeper-3.7.1-bin
2023-04-05 05:18:30,581 [myid:] - INFO [main:Environment@98] - Client environment:os.memory.free=51MB
2023-04-05 05:18:30,581 [myid:] - INFO [main:Environment@98] - Client environment:os.memory.max=228MB
2023-04-05 05:18:30,581 [myid:] - INFO [main:Environment@98] - Client environment:os.memory.total=59MB
2023-04-05 05:18:30,585 [myid:] - INFO [main:ZooKeeper@657] - Initiating client connection, connectString=127.0.0.1:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@449b2d27
2023-04-05 05:18:30,588 [myid:] - INFO [main:X509Util@77] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2023-04-05 05:18:30,592 [myid:] - INFO [main:ClientCnxnSocket@239] - jute.maxbuffer value is 1048575 Bytes
2023-04-05 05:18:30,601 [myid:] - INFO [main:ClientCnxn@1735] - zookeeper.request.timeout value is 0. feature enabled=false
Welcome to ZooKeeper!
2023-04-05 05:18:30,608 [myid:127.0.0.1:2181] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1171] - Opening socket connection to server localhost/127.0.0.1:2181.
2023-04-05 05:18:30,608 [myid:127.0.0.1:2181] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1173] - SASL config status: Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2023-04-05 05:18:30,624 [myid:127.0.0.1:2181] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1005] - Socket connection established, initiating session, client: /127.0.0.1:56296, server: localhost/127.0.0.1:2181
2023-04-05 05:18:30,671 [myid:127.0.0.1:2181] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1446] - Session establishment complete on server localhost/127.0.0.1:2181, session id = 0x100075903100000, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: 127.0.0.1:2181(CONNECTED) 0]
完全ok!!!
上面的容器测试时是直接kill掉的,但是应该有些人是需要继续留着的,这时有两个解决方式:
1、修改 ZooKeeper 的 AdminServer 端口:可以编辑 ZooKeeper 的配置文件,将 AdminServer 的端口修改为其他未被占用的端口。在 ZooKeeper 的配置文件 zoo.cfg 中,可以找到 admin.serverPort 参数,将其值修改为其他端口,例如 admin.serverPort=8888。文章来源:https://www.toymoban.com/news/detail-427622.html
2、避免使用 Docker 占用 ZooKeeper 默认的 AdminServer 端口:在启动 Docker 容器时,可以通过 -p 参数将容器的端口映射到宿主机的其他端口,以避免占用 ZooKeeper 默认的 AdminServer 端口 8080。
例如,可以使用类似于以下命令启动 Docker 容器,并将容器的 8080 端口映射到宿主机的 8888 端口:docker run -p 8888:8080 <image_name>. 这样,ZooKeeper 将能够使用默认的 8080 端口启动 AdminServer,而不会与 Docker 进程冲突。请注意,<image_name> 是要运行的 Docker 镜像的名称。具体的命令参数可能会因使用的 Docker 版本和镜像而有所不同,根据环境进行相应的调整。文章来源地址https://www.toymoban.com/news/detail-427622.html
到了这里,关于Zookeeper篇:本地安装的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!