SpringCloud学习文章,记录学习bug
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首页