Spring Cloud注册中心集群配置文件

注册中心配置一:

eureka:
  instance:
    hostname: server1
  client:
    # 由于该应用为注册中心,所以设置为false,代表不向注册中心注册自己
    register-with-eureka: false
    # 表示是否从 Eureka Server获取注册信息,默认为true。因为这是一个单点的Eureka Server,不需要同步其他的Eureka Server节点的数据,故而为false
    fetch-registry: false
    service-url:
      defaultZone: http://localhost:2222/eureka/

server:
  # 端口号
  port: 1111

spring:
  # 注册中心服务ID
  application:
    name: eureka-server

注册中心配置二

eureka:
  instance:
    hostname: server2
  client:
    # 由于该应用为注册中心,所以设置为false,代表不向注册中心注册自己
    register-with-eureka: false
    # 表示是否从 Eureka Server获取注册信息,默认为true。因为这是一个单点的Eureka Server,不需要同步其他的Eureka Server节点的数据,故而为false
    fetch-registry: false
    service-url:
      defaultZone: http://localhost:1111/eureka/

server:
  # 端口号
  port: 2222

spring:
  # 注册中心服务ID
  application:
    name: eureka-server

注册服务配置

spring:
  application:
    # 服务器名称
    name: compute-service1
  cloud:
    config:
      discovery:
        # 启动服务发现的功能,开启了才能调用其它服务
        enabled: true
        # 发现的服务的名字--对应注测中心的服务名字
        service-id: eureka-server
server:
  # 端口号
  port: 3333
  servlet:
    context-path: /api/hello
eureka:
  client:
    service-url:
      defaultZone: http://localhost:1111/eureka/,http://localhost:2222/eureka/

更多注册中心集群只需要service-url: defaultZone: 后面相互注册引用就行了,至于pom文件可以参考我的 spring cloud单点服务注册中心、服务提供者 博客

猜你喜欢

转载自blog.csdn.net/weixin_41131531/article/details/88535291