侧边栏壁纸
  • 累计撰写 30 篇文章
  • 累计创建 35 个标签
  • 累计收到 4 条评论

Linux系统安装zookeeper

GoDan
2022-05-07 / 0 评论 / 0 点赞 / 144 阅读 / 10,919 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2022-05-07,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

官方包源:zookeeper

下载包,解压

wget https://archive.apache.org/dist/zookeeper/zookeeper-3.8.0/apache-zookeeper-3.8.0-bin.tar.gz
tar -zxvf apache-zookeeper-3.8.0-bin.tar.gz -C /usr/local/

配置

cd /usr/local/apache-zookeeper-3.8.0-bin
# 创建数据和数据日志目录
mkdir data log
# 复制模版文件
cd /usr/local/apache-zookeeper-3.8.0-bin/conf
cp zoo_sample.cfg zoo.cfg
# 编辑配置文件
vim 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=/usr/local/apache-zookeeper-3.8.0-bin/data
dataLogDir=/usr/local/apache-zookeeper-3.8.0-bin/log
# 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.
#
# https://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.httpHost=0.0.0.0
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true

启动

cd /usr/local/apache-zookeeper-3.8.0-bin/bin
./zkServer.sh start

测试链接

./zkCli.sh  -server localhost:2182
Connecting to localhost:2181
2022-05-07 14:05:06,715 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:zookeeper.version=3.8.0-5a02a05eddb59aee6ac762f7ea82e92a68eb9c0f, built on 2022-02-25 08:49 UTC
2022-05-07 14:05:06,717 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:host.name=iZ2ze6yvokbfcctdwj7pi3Z
2022-05-07 14:05:06,717 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:java.version=1.8.0_60
2022-05-07 14:05:06,717 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:java.vendor=Oracle Corporation
2022-05-07 14:05:06,717 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:java.home=/usr/local/jdk/jre
2022-05-07 14:05:06,717 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:java.class.path=/usr/local/apache-zookeeper-3.8.0-bin/bin/../zookeeper-server/target/classes:/usr/local/apache-zookeeper-3.8.0-bin/bin/../build/classes:/usr/local/apache-zookeeper-3.8.0-bin/bin/../zookeeper-server/target/lib/*.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../build/lib/*.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/zookeeper-prometheus-metrics-3.8.0.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/zookeeper-jute-3.8.0.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/zookeeper-3.8.0.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/snappy-java-1.1.7.7.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/slf4j-api-1.7.30.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/simpleclient_servlet-0.9.0.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/simpleclient_hotspot-0.9.0.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/simpleclient_common-0.9.0.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/simpleclient-0.9.0.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/netty-transport-native-unix-common-4.1.73.Final.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/netty-transport-native-epoll-4.1.73.Final.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/netty-transport-classes-epoll-4.1.73.Final.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/netty-transport-4.1.73.Final.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/netty-tcnative-classes-2.0.48.Final.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/netty-tcnative-2.0.48.Final.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/netty-resolver-4.1.73.Final.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/netty-handler-4.1.73.Final.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/netty-common-4.1.73.Final.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/netty-codec-4.1.73.Final.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/netty-buffer-4.1.73.Final.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/metrics-core-4.1.12.1.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/logback-core-1.2.10.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/logback-classic-1.2.10.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/jline-2.14.6.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/jetty-util-ajax-9.4.43.v20210629.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/jetty-util-9.4.43.v20210629.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/jetty-servlet-9.4.43.v20210629.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/jetty-server-9.4.43.v20210629.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/jetty-security-9.4.43.v20210629.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/jetty-io-9.4.43.v20210629.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/jetty-http-9.4.43.v20210629.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/javax.servlet-api-3.1.0.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/jackson-databind-2.13.1.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/jackson-core-2.13.1.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/jackson-annotations-2.13.1.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/commons-io-2.11.0.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/commons-cli-1.4.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../lib/audience-annotations-0.12.0.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../zookeeper-*.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../zookeeper-server/src/main/resources/lib/*.jar:/usr/local/apache-zookeeper-3.8.0-bin/bin/../conf:.:/usr/local/jdk/lib:/lib:
2022-05-07 14:05:06,717 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2022-05-07 14:05:06,717 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:java.io.tmpdir=/tmp
2022-05-07 14:05:06,717 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:java.compiler=<NA>
2022-05-07 14:05:06,717 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:os.name=Linux
2022-05-07 14:05:06,717 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:os.arch=amd64
2022-05-07 14:05:06,717 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:os.version=5.4.0-86-generic
2022-05-07 14:05:06,718 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:user.name=root
2022-05-07 14:05:06,718 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:user.home=/root
2022-05-07 14:05:06,718 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:user.dir=/usr/local/apache-zookeeper-3.8.0-bin/bin
2022-05-07 14:05:06,718 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:os.memory.free=222MB
2022-05-07 14:05:06,718 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:os.memory.max=238MB
2022-05-07 14:05:06,718 [myid:] - INFO  [main:o.a.z.Environment@98] - Client environment:os.memory.total=238MB
2022-05-07 14:05:06,721 [myid:] - INFO  [main:o.a.z.ZooKeeper@637] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@1b604f19
2022-05-07 14:05:06,724 [myid:] - INFO  [main:o.a.z.c.X509Util@77] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
2022-05-07 14:05:06,728 [myid:] - INFO  [main:o.a.z.ClientCnxnSocket@239] - jute.maxbuffer value is 1048575 Bytes
2022-05-07 14:05:06,734 [myid:] - INFO  [main:o.a.z.ClientCnxn@1732] - zookeeper.request.timeout value is 0. feature enabled=false
Welcome to ZooKeeper!
2022-05-07 14:05:06,737 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):o.a.z.ClientCnxn$SendThread@1171] - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181.
2022-05-07 14:05:06,737 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):o.a.z.ClientCnxn$SendThread@1173] - SASL config status: Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2022-05-07 14:05:06,744 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):o.a.z.ClientCnxn$SendThread@1005] - Socket connection established, initiating session, client: /0:0:0:0:0:0:0:1:42062, server: localhost/0:0:0:0:0:0:0:1:2181
2022-05-07 14:05:06,767 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):o.a.z.ClientCnxn$SendThread@1444] - Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181, session id = 0x102306d94bc0000, negotiated timeout = 30000

WATCHER::

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

其他命令

# 显示可执行命令
./zkServer.sh sdffsdfs
# 查看启动状态
./zkServer.sh status

错误

8080端口冲突

cat /usr/local/apache-zookeeper-3.8.0-bin/logs/zookeeper-root-server-beijing-platform-dev-01a.out

2022-05-07 13:50:05,309 [myid:] - ERROR [main:o.a.z.s.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:194)
	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:185)
	... 5 common frames omitted
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:433)
	at sun.nio.ch.Net.bind(Net.java:425)
	at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
	at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
	at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:344)
	... 12 common frames omitted
Unable to start AdminServer, exiting abnormally
2022-05-07 13:50:05,309 [myid:] - INFO  [main:o.a.z.a.ZKAuditProvider@42] - ZooKeeper audit is disabled.
2022-05-07 13:50:05,310 [myid:] - ERROR [main:o.a.z.u.ServiceUtils@42] - Exiting JVM with code 4

修改zoo.cfg,增加admin.serverPort 默认占8080端口

0

评论区