天天看点

配置Eureka集群注册中心

1.本机集群时需要使用域名,配置 localhost 和 127.0.0.1的时候集群不可用(集群模式会显示unavailable-replicas)

2.非本机环境使用ip地址的形式进行注册,添加:

eureka:

instance:

prefer-ip-address: true

3.注意yml首尾字母的间隔

启动时指定profiles即可

java -jar -Xms512m -Xmx1024m xxxxx.jar --spring.profiles.active=dev1

application.yml配置信息:

#公共配置

spring:

application:

name: registry

eureka:

#dashboard:

#enabled: true

#path: /admin #访问eureka时地址上带admin

server:

eviction-interval-timer-in-ms: 5000 #清理无效节点的时间 5秒

enable-self-preservation: false #关闭自我保护模式

##日志

logging:

level:

com.eureka.registry: debug

file: ./logs/registry.log

server:

port: 8760

spring:

profiles: dev1

eureka:

instance:

prefer-ip-address: true

instance-id: 10.144.128.10:8760

client:

serviceUrl:

defaultZone: http://10.144.128.11:8760/eureka/,http://10.144.128.12:8760/eureka/

server:

port: 8761

spring:

profiles: dev2

eureka:

instance:

prefer-ip-address: true

instance-id: 10.144.128.11:8761

client:

serviceUrl:

defaultZone: http://10.144.128.10:8760/eureka/,http://10.144.128.12:8760/eureka/

server:

port: 8762

spring:

profiles: dev3

eureka:

instance:

prefer-ip-address: true

instance-id: 10.144.128.12:8762

client:

serviceUrl:

defaultZone: http://10.144.128.10:8760/eureka/,http://10.144.128.11:8760/eureka/

##本机localhost环境 需要配置hosts :

##127.0.0.1 eureka1

##127.0.0.1 eureka2

server:

port: 8760

spring:

profiles: local1

eureka:

instance:

hostname: eureka1

#prefer-ip-address: true #本机集群时需要使用域名 localhost 127.0.0.1不识别

instance-id: 127.0.0.1:8760

client:

serviceUrl:

defaultZone: http://eureka2:8761/eureka/

server:

port: 8761

spring:

profiles: local2

eureka:

instance:

hostname: eureka2

#prefer-ip-address: true

instance-id: 127.0.0.1:8761

client:

serviceUrl:

defaultZone: http://eureka1:8760//