zookeeper 配置文件解读
本地配置文件奉上:
# 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=/tmp/zookeeper
# 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
- tickTime =2000:通信心跳数,zookeeper服务器与客户端心跳时间,单位毫秒
zookeeper使用的基本时间,服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个tickTime时间就会发送一个心跳,时间单位为毫秒。它用于心跳机制,并且设置最小的session超时时间为两倍心跳时间。(session的最小超时时间是2*tickTime)
2. initLimit =10:LF初始通信时限
集群中的follower跟随者服务器(F)与leader领导者服务器(L)之间初始连接时能容忍的最多心跳数(tickTime的数量),用它来限定集群中的Zookeeper服务器连接到Leader的时限。投票选举新leader的初始化时间。Follower在启动过程中,会从Leader同步所有最新数据,然后确定自己能够对外服务的起始状态。Leader允许F在initLimit时间内完成这个工作。
3.syncLimit =5:LF同步通信时限
集群中Leader与Follower之间的最大响应时间单位,假如响应超过syncLimit * tickTime,Leader认为Follwer死掉,从服务器列表中删除Follwer。在运行过程中,Leader负责与ZK集群中所有机器进行通信,例如通过一些心跳检测机制,来检测机器的存活状态。如果L发出心跳包在syncLimit之后,还没有从F那收到响应,那么就认为这个F已经不在线了。
4.dataDir:数据文件目录+数据持久化路径
主要用于保存Zookeeper中的数据。
5.clientPort =2181:客户端连接端口
监听客户端连接的端口。
本地启动zookeeper
查看注册的服务
我使用dubble 写了两个服务 其中一个服务提供者为 studentservice-provider, 服务消费者为 studentservice-consumer 都注册到zookeeper 里面
代码结构如下:
studentservice-provider,
studentservice-consumer
如果本地zk的地址为127.0.0.1端口为默认端口2181。
ls /dubbo 查看注册的服务 例如: service.StudentService
ls /dubbo/service.StudentService/consumers 查看注册的消费者
ls /dubbo/service.StudentService/providers 查看注册的生产者
ls /dubbo 查看注册的服务
ls /dubbo/service.StudentService/consumers 查看注册的消费者
consumer://20.0.0.211/service.StudentService?application=studentservice-consumer&category=consumers&check=false&dubbo=2.0.2&init=false&interface=service.StudentService&metadata-type=remote&methods=queryStudent&pid=36596&qos.enable=false&release=2.7.8&revision=1.0.0&side=consumer&sticky=false×tamp=1670681475579&version=1.0.0, consumer://20.0.0.211/service.StudentService?application=studentservice-consumer&category=consumers&check=false&dubbo=2.0.2&init=false&interface=service.StudentService&metadata-type=remote&methods=queryStudent&pid=36596&qos.enable=false&release=2.7.8&revision=2.0.0&side=consumer&sticky=false×tamp=1670681475935&version=2.0.0
ls /dubbo/service.StudentService/providers 查看注册的生产者
dubbo://20.0.0.211:20880/service.StudentService?anyhost=true&application=studentservice-provider&default=true&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&interface=service.StudentService&metadata-type=remote&methods=queryStudent&pid=26340&release=2.7.8&revision=1.0.0&side=provider&timeout=5×tamp=1670681455072&version=1.0.0, dubbo://20.0.0.211:20880/service.StudentService?anyhost=true&application=studentservice-provider&default=true&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&interface=service.StudentService&metadata-type=remote&methods=queryStudent&pid=26340&release=2.7.8&revision=2.0.0&side=provider×tamp=1670681454792&version=2.0.0