Zookeeper 端口说明
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Zookeeper 端口说明相关的知识,希望对你有一定的参考价值。
参考技术A 1、2181:对cline端提供服务2、3888:选举leader使用
3、2888:集群内机器通讯使用(Leader监听此端口)
1、单机单实例,只要端口不被占用即可
2、单机伪集群(单机,部署多个实例),三个端口必须修改为组组不一样
如:myid1 : 2181,3888,2888
myid2 : 2182,3788,2788
myid3 : 2183,3688,2688
3、集群(一台机器部署一个实例)
#配置集群
server.l=master:2888:3888
server.2=slaver1:2888:3888
server.3=slaver2:2888:3888
server.A=B.:C:D
A:表示一个数字,这个数字表示第几个服务器,配置在myid的文件
B:服务器地址,也就是ip地址
C:本台服务器与集群中的lender服务器交换信息端口
D:万一leader挂了就需要这个端口重新选举
4.集群最少要几台机器
集群规则是怎样的集群规则为2N+1台,N>0,即3台。
zookeeper集群搭建Exception when following the leader java.io.EOFException
zk配置后集群选举失败,集群中全部无法进行选举,但是应用又起来了。
先讲原因:后经人指点,server的端口配置错误导致。server占用了client的端口号导致的。说明server.1=127.0.0.1:2181:3181中2181是server端口但是我又配置了clientPort=2181.把server端口和client端口混为一谈导致的(汗颜并吐槽:zk既然配置错误了,就不应该让项目启动成功,应该直接停止程序或者直接报错)。
修改zoo.cnf中集群错误配置:
server.1=127.0.0.1:2181:3181
server.2=127.0.0.1:2182:3182
server.3=127.0.0.1:2183:3183
为正确配置:
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3899
server.3=127.0.0.1:2890:3890
附件:
Exception when following the leader
java.io.EOFException
线上异常截图:
用zkServer.sh status的状态命令查看如下:
错误配置文件:
# 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=D:/Dev/data/zookeeper/z1 # 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 server.1=127.0.0.1:2181:3181 server.2=127.0.0.1:2182:3182 server.3=127.0.0.1:2183:3183
正确配置:
# 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=D:/Dev/data/zookeeper/z1 # 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 server.1=127.0.0.1:2888:3888 server.2=127.0.0.1:2889:3899 server.3=127.0.0.1:2890:3890
以上是关于Zookeeper 端口说明的主要内容,如果未能解决你的问题,请参考以下文章