eureka之前演示的图片就是集群的,但是没有说如何配置eureka集群的配置方式,这次说下eureka集群的配置。
上图是来自eureka的官方架构图,这是基于集群配置的eureka
源码:08-ms-eureka-server-ha
引入依赖
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency>
application.yml配置如下(见配置文件application-ha.yml)
spring: application: name: microservice-eureka-server-ha --- spring: profiles: peer1 # 指定profile=peer1 server: port: 8761 eureka: instance: hostname: peer1 # 指定当profile=peer1时,主机名是peer1 client: serviceUrl: defaultZone: http://peer2:8762/eureka/,http://peer3:8763/eureka/ # 将自己注册到peer2这个Eureka上面去 --- spring: profiles: peer2 server: port: 8762 eureka: instance: hostname: peer2 client: serviceUrl: defaultZone: http://peer1:8761/eureka/,http://peer3:8763/eureka/ --- spring: profiles: peer3 server: port: 8763 eureka: instance: hostname: peer3 client: serviceUrl: defaultZone: http://peer1:8761/eureka/,http://peer2:8762/eureka/
配置host文件修改:127.0.0.1 peer1 peer2 peer3
java -jar 项目的jar包 --spring.profiles.active=peer1
java -jar 项目的jar包 --spring.profiles.active=peer2
java -jar 项目的jar包 --spring.profiles.active=peer3
PS:集群其实很好配置,选择点的时候是相互的。A点需要配置B和C点,B点需要配置A和C点,C点配置A和B点。