Eureka高可用。
单点故障会导致系统全部死掉。所以需要来个类似集群的那种操作,死了一个,还有其他的,不至于系统用不了。
Eureka的集群,也就是Eureka之间相互注册。
Eureka集群环境搭建 Eureka01配置 ###服务端口号 server: port: 8100 ###eureka 基本信息配置 spring: application: name: eureka-server eureka: instance: ###注册到eurekaip地址 hostname: 127.0.0.1 client: serviceUrl: defaultZone: http://127.0.0.1:8200/eureka/ ###因为自己是为注册中心,不需要自己注册自己 register-with-eureka: true ###因为自己是为注册中心,不需要检索服务 fetch-registry: true Eureka02配置 ###服务端口号 server: port: 8200 ###eureka 基本信息配置 spring: application: name: eureka-server eureka: instance: ###注册到eurekaip地址 hostname: 127.0.0.1 client: serviceUrl: defaultZone: http://127.0.0.1:8100/eureka/ ###因为自己是为注册中心,不需要自己注册自己 register-with-eureka: true ###因为自己是为注册中心,不需要检索服务 fetch-registry: true
客户端调用。
客户端集成Eureka集群
server:
port: 8000
spring:
application:
name: app-itmayiedu-member
#eureka:
# client:
# service-url:
# defaultZone: http://localhost:8100/eureka
###集群地址
eureka:
client:
service-url:
defaultZone: http://localhost:8100/eureka,http://localhost:8200/eureka
register-with-eureka: true
fetch-registry: true
pom.xml配置
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.1.RELEASE</version> </parent> <!-- 管理依赖 --> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Finchley.M7</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <!--SpringCloud eureka-server --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> </dependencies> <!-- 注意: 这里必须要添加, 否者各种依赖有问题 --> <repositories> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/libs-milestone</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories>