环境机器三台如下:
172.22.122.22
172.22.122.23
172.22.122.24
目标就是要在这三台上,搭建一个高可用注册中心:
截图.PNG
基础教程网上有很多,这里就不详细列举了,这里记录一个大家肯定会遇到的问题,就是我配置了多个点相互注册之后,从一点上看另外亮点都是处于unavailable-replicas状态。网上的很多教程都是修改host,这一点是显得不方便的。
经过搜索,然后自己踩坑,先贴下配置,实践可用:
application-eureka1.properties
#注册应用名必须都相同
spring.application.name=DISCOVERY
server.port=8761
eur.cluster.server2.host=172.22.122.23
eur.cluster.server3.host=172.22.122.24
eur.cluster.server2.port=8761
eur.cluster.server3.port=8761
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.service-url.defaultZone=\
http://${eur.cluster.server2.host}:${eur.cluster.server2.port}/eureka/,\
http://${eur.cluster.server3.host}:${eur.cluster.server3.port}/eureka/
eureka.instance.hostname=172.22.122.22
eureka.instance.prefer-ip-address=true
#这一段配置很关键
eureka.instance.instance-id=${eureka.instance.hostname}:${server.port}
eureka.server.enable-self-preservation=false
application-eureka2.properties
#注册应用名必须都相同
spring.application.name=DISCOVERY
server.port=8761
eur.cluster.server1.host=172.22.122.22
eur.cluster.server3.host=172.22.122.24
eur.cluster.server1.port=8761
eur.cluster.server3.port=8761
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.service-url.defaultZone=\
http://${eur.cluster.server1.host}:${eur.cluster.server1.port}/eureka/,\
http://${eur.cluster.server3.host}:${eur.cluster.server3.port}/eureka/
eureka.instance.hostname=172.22.122.23
eureka.instance.prefer-ip-address=true
#这一段配置很关键
eureka.instance.instance-id=${eureka.instance.hostname}:${server.port}
eureka.server.enable-self-preservation=false
application-eureka3.properties
#注册应用名必须都相同
spring.application.name=DISCOVERY
server.port=8761
eur.cluster.server1.host=172.22.122.22
eur.cluster.server2.host=172.22.122.23
eur.cluster.server1.port=8761
eur.cluster.server2.port=8761
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.service-url.defaultZone=\
http://${eur.cluster.server1.host}:${eur.cluster.server1.port}/eureka/,\
http://${eur.cluster.server2.host}:${eur.cluster.server2.port}/eureka/
eureka.instance.hostname=172.22.122.24
eureka.instance.prefer-ip-address=true
#这一段配置很关键
eureka.instance.instance-id=${eureka.instance.hostname}:${server.port}
eureka.server.enable-self-preservation=false
网友评论