1、搭建多节点Eureka服务
-
pom文件加入依赖
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency>
-
application文件配置,搭建双节点服务注册中心集群
配置如图
1、application.yml文件配置 spring: profiles: active: one 2、application-one.yml文件配置 server: # 配置服务端口 port: 10081 eureka: instance: hostname: eureka-one client: service-url: # 配置eureka服务器地址,双节点的服务注册中心集群 defaultZone: http://eureka-two:1081/eureka #是否需要将自己注册到注册中心(注册中心集群需要设置为true,才能配合ribbon使用负载均衡,注意这个坑啊) register-with-eureka: true #是否需要搜索服务信息 fetch-registry: true server: enableSelfPreservation: false # 本地调试环境下关闭自我保护机制 3、application-two.yml文件配置 server: # 配置服务端口 port: 1081 eureka: instance: hostname: eureka-two client: service-url: # 配置eureka服务器地址 defaultZone: http://eureka-one:10081/eureka #是否需要将自己注册到注册中心(注册中心集群需要设置为true,才能配合ribbon使用负载均衡) register-with-eureka: true #是否需要搜索服务信息 fetch-registry: true server: enableSelfPreservation: false # 本地调试环境下关闭自我保护机制
在C:\Windows\System32\drivers\etc环境下配置hosts
127.0.0.1 eureka-one 127.0.0.1 eureka-two
-
配置启动类
/** * 开启Eureka服务 */ @SpringBootApplication @EnableE