SpringCloud之Eureka配置


单机配置:

注册中心配置
# 配置服务端口.
server:
    port: 7001

spring:
    application:
        name: eureka-server-7001

# Eureka 配置
eureka:
    instance:
        hostname: localhost   #eureka服务器实例名

    client:
        register-with-eureka: false   #false 标识不向注册中心注册自己.
        fetch-registry: false         #false 标识自己端就是注册中心,职责就是维护实例,不需要去检索服务.

        service-url:
            #服务注册地址
            defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

服务提供端配置
eureka:
    instance:
        instance-id: provider-member-center-8001    # 显示服务名称.
        prefer-ip-address: true #访问路径显示IP

    client:
        service-url:
            #配置Eureka注册中心地址.
            defaultZone: http://localhost:7001/eureka/

服务消费端配置
#配置注册中心.
eureka:
    client:
        register-with-eureka: false #false 标识不向注册中心注册自己.
        service-url:
            defaultZone: http://localhost.com:7001/eureka/

集群配置:

注册中心 7001 配置:
# 配置服务端口.
server:
    port: 7001

spring:
  application:
    name: eureka7001.com

# Eureka 配置
eureka:
    instance:
        hostname: eureka7001.com  #eureka服务器实例名

    client:
        register-with-eureka: false   #false 标识不向注册中心注册自己.
        fetch-registry: false       #false 不通过eureka获取注册信息.
        service-url:
            defaultZone: http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/

注册中心 7002 配置:
# 配置服务端口.
server:
    port: 7002

spring:
  application:
    name: eureka7002.com

# Eureka 配置
eureka:
    instance:
        hostname: eureka7002.com  #eureka服务器实例名

    client:
        register-with-eureka: false   #false 标识不向注册中心注册自己.
        fetch-registry: false       #false 不通过eureka获取注册信息.
        service-url:
            defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7003.com:7003/eureka/

注册中心 7003 配置:
# 配置服务端口.
server:
    port: 7003

spring:
  application:
    name: eureka7003.com

# Eureka 配置
eureka:
    instance:
        hostname: eureka7003.com  #eureka服务器实例名

    client:
        register-with-eureka: false   #false 标识不向注册中心注册自己.
        fetch-registry: false       #false 不通过eureka获取注册信息.
        service-url:
            defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/

服务提供端配置
eureka:
    instance:
        instance-id: provider-member-center-8001    # 显示服务名称.
        prefer-ip-address: true #访问路径显示IP

    client:
        service-url:
            #配置Eureka注册中心地址.
            defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/,http://eureka7003.com:7003/eureka/

Ribbon 服务消费端配置:
#配置注册中心.
eureka:
    client:
        register-with-eureka: false #false 标识不向注册中心注册自己.
        service-url:
            defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka,http://eureka7003.com:7003/eureka

你可能感兴趣的:(Java)