zookeeper入门到精通04——zookeeper集群选举与集群操作(下)

本文涉及的产品
云原生网关 MSE Higress,422元/月
服务治理 MSE Sentinel/OpenSergo,Agent数量 不受限
注册配置 MSE Nacos/ZooKeeper,118元/月
简介: 4.zookeeper集群选举与集群操作4.1 集群选举机制4.1.1 第一次启动4.1.2 非第一次启动4.2 zookeeper启动停止脚本4.2.1 脚本编写4.2.2 脚本测试

好惨啊,为啥呢?单独关也不能关,排除了脚本的命令写错了这个问题。


[wangzhou@zookeeper01 zookeeper-3.5.7]$ ./bin/zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg
Stopping zookeeper ... no zookeeper to stop (could not find file /home/wangzhou/Downloads/zookeeper-3.5.7/zkData/zookeeper_server.pid)

看看log。没发现啥异常。把log删除了,重新连接,再查看log。

2022-04-04 12:32:57,246 [myid:] - INFO  [main:QuorumPeerConfig@135] - Reading configuration from: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg
2022-04-04 12:32:57,252 [myid:] - INFO  [main:QuorumPeerConfig@387] - clientPortAddress is 0.0.0.0:2181
2022-04-04 12:32:57,252 [myid:] - INFO  [main:QuorumPeerConfig@391] - secureClientPort is not set
2022-04-04 12:32:57,259 [myid:1] - INFO  [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
2022-04-04 12:32:57,260 [myid:1] - INFO  [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
2022-04-04 12:32:57,260 [myid:1] - INFO  [main:DatadirCleanupManager@101] - Purge task is not scheduled.
2022-04-04 12:32:57,260 [myid:1] - INFO  [main:ManagedUtil@46] - Log4j found with jmx enabled.
2022-04-04 12:32:57,269 [myid:1] - INFO  [main:QuorumPeerMain@141] - Starting quorum peer
2022-04-04 12:32:57,276 [myid:1] - INFO  [main:ServerCnxnFactory@135] - Using org.apache.zookeeper.server.NIOServerCnxnFactory as server connection factory
2022-04-04 12:32:57,278 [myid:1] - INFO  [main:NIOServerCnxnFactory@673] - Configuring NIO connection handler with 10s sessionless connection timeout, 1 selector thread(s), 2 worker threads, and 64 kB direct buffers.
2022-04-04 12:32:57,282 [myid:1] - INFO  [main:NIOServerCnxnFactory@686] - binding to port 0.0.0.0/0.0.0.0:2181
2022-04-04 12:32:57,282 [myid:1] - ERROR [main:QuorumPeerMain@101] - Unexpected exception, exiting abnormally
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 sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:67)
        at org.apache.zookeeper.server.NIOServerCnxnFactory.configure(NIOServerCnxnFactory.java:687)
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.runFromConfig(QuorumPeerMain.java:148)
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:123)
        at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:82)
~

好家伙,原来端口被占用了,谁占用了?jps看不到呀,切换到root账号,jps发现原来这个服务在root账户上跑着呢。kill停掉,再来到用户目录启动,果然启动不了。


[wangzhou@zookeeper01 bin]$ ./zkServer.sh start 
ZooKeeper JMX enabled by default
Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg
Starting zookeeper ... ./zkServer.sh: line 158: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../logs/zookeeper-wangzhou-server-zookeeper01.out: Permission denied
FAILED TO START

原因是我们把zookeeper放在普通用户的home/xxx下了,这个目录的权限默认是755。我们之前启动是用的sudo,让它跑在了root上。基础不牢,地动山摇,看来linux的基础也是不可以被忽视的。


好的,那么想办法解决下吧。我们zookeeper的权限放开吧。


[wangzhou@zookeeper03 Downloads]$ sudo chmod  777 -R zookeeper-3.5.7

测试下。

[wangzhou@zookeeper03 Downloads]$ zookeeper-3.5.7/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

最后集群测试下。

[wangzhou@zookeeper01 bin]$ ./zk.sh status
-------------- zookeeper01 状态 ----------------
ZooKeeper JMX enabled by default
Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Error contacting service. It is probably not running.
-------------- zookeeper02 状态 ----------------
ZooKeeper JMX enabled by default
Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Error contacting service. It is probably not running.
-------------- zookeeper03 状态 ----------------
ZooKeeper JMX enabled by default
Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Error contacting service. It is probably not running.
[wangzhou@zookeeper01 bin]$ ./zk.sh start
-------------- zookeeper01 启动 ----------------
ZooKeeper JMX enabled by default
Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
-------------- zookeeper02 启动 ----------------
ZooKeeper JMX enabled by default
Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
-------------- zookeeper03 启动 ----------------
ZooKeeper JMX enabled by default
Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[wangzhou@zookeeper01 bin]$ ./zk.sh status
-------------- zookeeper01 状态 ----------------
ZooKeeper JMX enabled by default
Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
-------------- zookeeper02 状态 ----------------
ZooKeeper JMX enabled by default
Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: leader
-------------- zookeeper03 状态 ----------------
ZooKeeper JMX enabled by default
Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
[wangzhou@zookeeper01 bin]$ ./zk.sh stop
-------------- zookeeper01 停止 ----------------
ZooKeeper JMX enabled by default
Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
-------------- zookeeper02 停止 ----------------
ZooKeeper JMX enabled by default
Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
-------------- zookeeper03 停止 ----------------
ZooKeeper JMX enabled by default
Using config: /home/wangzhou/Downloads/zookeeper-3.5.7/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED


相关实践学习
基于MSE实现微服务的全链路灰度
通过本场景的实验操作,您将了解并实现在线业务的微服务全链路灰度能力。
相关文章
|
13天前
|
存储 SpringCloudAlibaba Java
【SpringCloud Alibaba系列】一文全面解析Zookeeper安装、常用命令、JavaAPI操作、Watch事件监听、分布式锁、集群搭建、核心理论
一文全面解析Zookeeper安装、常用命令、JavaAPI操作、Watch事件监听、分布式锁、集群搭建、核心理论。
【SpringCloud Alibaba系列】一文全面解析Zookeeper安装、常用命令、JavaAPI操作、Watch事件监听、分布式锁、集群搭建、核心理论
|
3月前
|
分布式计算 负载均衡 算法
Hadoop-31 ZooKeeper 内部原理 简述Leader选举 ZAB协议 一致性
Hadoop-31 ZooKeeper 内部原理 简述Leader选举 ZAB协议 一致性
40 1
|
3月前
|
分布式计算 Java Hadoop
Hadoop-30 ZooKeeper集群 JavaAPI 客户端 POM Java操作ZK 监听节点 监听数据变化 创建节点 删除节点
Hadoop-30 ZooKeeper集群 JavaAPI 客户端 POM Java操作ZK 监听节点 监听数据变化 创建节点 删除节点
81 1
|
3月前
|
分布式计算 监控 Hadoop
Hadoop-29 ZooKeeper集群 Watcher机制 工作原理 与 ZK基本命令 测试集群效果 3台公网云服务器
Hadoop-29 ZooKeeper集群 Watcher机制 工作原理 与 ZK基本命令 测试集群效果 3台公网云服务器
56 1
|
3月前
|
分布式计算 Hadoop Unix
Hadoop-28 ZooKeeper集群 ZNode简介概念和测试 数据结构与监听机制 持久性节点 持久顺序节点 事务ID Watcher机制
Hadoop-28 ZooKeeper集群 ZNode简介概念和测试 数据结构与监听机制 持久性节点 持久顺序节点 事务ID Watcher机制
58 1
|
3月前
|
分布式计算 Hadoop
Hadoop-27 ZooKeeper集群 集群配置启动 3台云服务器 myid集群 zoo.cfg多节点配置 分布式协调框架 Leader Follower Observer
Hadoop-27 ZooKeeper集群 集群配置启动 3台云服务器 myid集群 zoo.cfg多节点配置 分布式协调框架 Leader Follower Observer
64 1
|
4月前
|
安全 应用服务中间件 API
微服务分布式系统架构之zookeeper与dubbo-2
微服务分布式系统架构之zookeeper与dubbo-2
|
4月前
|
负载均衡 Java 应用服务中间件
微服务分布式系统架构之zookeeper与dubbor-1
微服务分布式系统架构之zookeeper与dubbor-1
|
4月前
|
存储 负载均衡 Dubbo
分布式-Zookeeper(一)
分布式-Zookeeper(一)
|
2月前
|
存储 运维 NoSQL
分布式读写锁的奥义:上古世代 ZooKeeper 的进击
本文作者将介绍女娲对社区 ZooKeeper 在分布式读写锁实践细节上的思考,希望帮助大家理解分布式读写锁背后的原理。

热门文章

最新文章