SpringCloud学习文章

本文档详细介绍了在SpringCloud中配置Eureka、Zookeeper和Consul作为注册中心的过程,包括各自的配置参数和可能出现的问题。针对Eureka心跳间隔过低导致的连接不稳定问题,提出了调整配置的建议。Zookeeper的配置包括了zoo.cfg的设置,并指出其适用于单机版。Consul的配置则相对简单,只需运行exe文件即可启动。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

SpringCloud 中 注册中心

Eureka、zookeeper、Consul

Eureka(Hoxton.SR1 根据org.springCloud依赖版本)

出现加上 instance 服务就注册不上的bug
#  instance:
#    instance-id: payment8002
#    prefer-ip-address: true
#    #Eureka客户端向服务端发送心跳的实际间隔,单位为秒(默认为30秒)
#    lease-renewal-in-seconds: 1
#    #Eureka服务端收到最后一次心跳后等待时间上线,单位为秒(默认为90秒) 超时将剔除服务
#    lease-expiration-duration-in-seconds: 2
误会解除 eureka server清理无效节点的时间间隔,默认60000毫秒,即60秒(这里设置成2秒)
  server:
    #关闭自我保护模式,保证不可用服务被及时删除
    enable-self-preservation: false
    #
    eviction-interval-timer-in-ms: 2000

然后这里的问题是电脑的网络有波动,发送心跳的间隔太低,容易出现断的问题(至少我的电脑经常断,或者说用了这设置一直连不上。。)
可以适当的调整,或者注解以下的代码粗体部分

instance:
instance-id: payment8002
prefer-ip-address: true
#Eureka客户端向服务端发送心跳的实际间隔,单位为秒(默认为30秒)
lease-renewal-in-seconds: 1
#Eureka服务端收到最后一次心跳后等待时间上线,单位为秒(默认为90秒) 超时将剔除服务
lease-expiration-duration-in-seconds: 2

Zookeeper(apache-zookeeper-3.5.9-bin版本)

首先Zookeeper要下载的话,在WIN10要下载bin的,然后要创建data文件夹
Zookeeper需要自己添加一个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=C:/software/apache-zookeeper-3.5.9-bin/data
# 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
server.1=127.0.0.1:2888:3888

server.1 就是一个主机,想要测试多个可以写多个server.xxx

Consul(consul_1.9.2_windows_amd64)版本

算是注册中心最简单配置的了到exe文件目录,consul agent -dev 启动consul
http://localhost:8500 就能进consul首页

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值