思考:
为什么要注册到多个注册中心
答:如果一个注册中心宕机了,就需要使用另一个注册中心来调用服务,不然注册中心集群还是不能高可用。
步骤:
一,修改微服务的配置文件yml,将微服务引用多个eurekaServer
server:
port: 9001
spring:
application:
name: service-product
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/springclouddemo?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
username: root
password: root
jpa:
database: MySQL
show-sql: true
open-in-view: true
eureka:
client:
service-url:
defaultZone: http://localhost:9003/eureka/,http://localhost:9004/eureka/
instance:
prefer-ip-address: true
instance-id: ${spring.cloud.client.ip-address}:${server.port} #向注册中心中注册服务id
# EurekaServer地址,多个地址以','隔开
defaultZone: http://localhost:9003/eureka/,http://localhost:9004/eureka/
该博客讨论了为何要将微服务注册到多个注册中心,以实现高可用性。当一个注册中心出现故障时,其他注册中心可以接管服务调用。文章详细介绍了配置步骤,包括在微服务的yml配置文件中添加多个Eureka Server的URL,确保即使一个注册中心宕机,服务仍能正常运行。
9677

被折叠的 条评论
为什么被折叠?



