1:eureka集群:原则,相互注册即可
注意:
a:必须要有示例名,且必须相同
b:集群模式必须开启注册registerWithEureka: true,单机情况下这个是false
c:如果用域名,必须映射hosts
以下用两个节点做演示server1,server2
server-1:
server: port: 8080 eureka: server: #禁止自我保护,剔除无效服务 enable-self-preservation: false #清理自我保护时间间隔 默认是60秒 单位毫秒 设定3s eviction-interval-timer-in-ms: 3000 instance: hostname: eurekserveranode1 client: #单机设置false,集群需要设置为true,负责找不到其他示例,无法相互注册 registerWithEureka: true #要不要去注册中心获取其他服务的地址 fetchRegistry: false serviceUrl: #erureka-server集群指向其他服务 defaultZone: http://eurekserveranode2:8081/eureka/ #集群EurekaServer的applicationname必须有且必须相同 spring: application: name: eureka-server
server2:
server: port: 8081 eureka: server: #禁止自我保护,剔除无效服务 enable-self-preservation: false #清理自我保护时间间隔 默认是60秒 单位毫秒 设定3s eviction-interval-timer-in-ms: 3000 instance: hostname: eurekserveranode2 client: #单机设置false,集群需要设置为true registerWithEureka: true fetchRegistry: false serviceUrl: #集群指向另外地址 defaultZone: http://eurekserveranode1:8080/eureka/ #集群EurekaServer的applicationname必须有且必须相同 spring: application: name: eureka-server
eureka-client:
eureka: client: serviceUrl: defaultZone: http://eurekserveranode1:8080/eureka/,http://eurekserveranode2:8081/eureka/ server: port: 8758 spring: application: name: service-member
zuul:
eureka: client: serviceUrl: defaultZone: http://localhost:8080/eureka/ #设置eureka-client多久拉取注册信息 默认30s registry-fetch-interval-seconds: 5 server: port: 8766 spring: application: name: service-zuul zuul: routes: api-a: path: /api-member/** service-id: service-member api-b: path: /api-order/** service-id: service-order