Zookeeper安装与服务注册

本文档详细介绍了如何在Windows 10上安装和配置Zookeeper,包括从官方网站下载软件,修改配置文件zoo.cfg,设置dataDir和dataLogDir等参数,并启动Zookeeper服务。此外,还展示了如何通过zkCli客户端查看服务注册信息,以及Java应用程序如何将服务注册到Zookeeper。
摘要由CSDN通过智能技术生成

Zookeeper安装与服务注册

了解完Eureka之后,顺便学习下Zookeeper,本来打算用远程服务器的,谁知道公司内网不仅不能跟远程ping通,虚拟机也是麻烦的一批,遂转投windows

1. win10安装很简单,官网下载.tar.gz,解压了一样能用

官方下载地址如下:https://zookeeper.apache.org/releases.html#download

2. 解压后在conf下复制 zoo_sample.cfg 文件的并命名为为 zoo.cfg

并修改zoo.cfg,修改为图中(并新建相应目录)

image-20210204171011668

以下为我的配置文件

# 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\apache-zookeeper-3.6.2-bin/data

# 日志文件夹
dataLogDir=D:\dev\apache-zookeeper-3.6.2-bin/logs
# 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

audit.enable=true

配置文件简单解析

  • 1、tickTime:这个时间是作为 Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。
  • 2、dataDir:顾名思义就是 Zookeeper 保存数据的目录,默认情况下,Zookeeper 将写数据的日志文件也保存在这个目录里。
  • 3、dataLogDir:顾名思义就是 Zookeeper 保存日志文件的目录
  • 4、clientPort:这个端口就是客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求。
3. 可以直接使用了

启动zkServer: 进入bin目录,双击zkServer.cmd即可启动

启动zkClient: 进入bin目录,双击zkCli.cmd即可启动

查看节点信息: ls /

Java下,将服务注册进Zookeeper很简单,只需要在主程序添加@EnableDiscoveryClient(服务发现),application.yml中配置相关信息

server:
  port: 8004

spring:
  application:
    name: cloud-provider-payment
  cloud:
    zookeeper:
      connect-string: localhost:2181

启动后即可在zkClient(双击zkCli.cmd启动的窗口)

[zk: localhost:2181(CONNECTED) 19] ls /
[services, zookeeper]   // 原本服务注册之前,只有一个zookeeper

再依次深入,可以看到服务内部各种信息

image-20210204171850385

最后用json格式化工具打开就是这个注册到zookeeper的服务的信息

image-20210204171956075

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值