注册中心 Eureka
Eureka客户端
1.pom文件引入依赖
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency>
2.修改yml配置文件
eureka: client: register-with-eureka: true fetch-registry: true service-url: defaultZone: http://localhost:7001/eureka,http://localhost:7002/eureka instance: instance-id: order80 prefer-ip-address: true ## 客户端向eureka服务端发送心跳间隔的时间,默认30s lease-renewal-interval-in-seconds: 1 ## Eureka服务端收到最后一次心跳的等待时间上限,默认90s,否则剔除服务 lease-expiration-duration-in-seconds: 2
3.主启动类上添加 @EnableEurekaServer 注解
@SpringBootApplication @EnableEurekaClientpublic class OrderMain80 { public static void main(String[] args) { SpringApplication.run(OrderMain80.class, args); } }
Eureka服务端
1.pom文件引入依赖
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency>
2.修改yml配置文件
eureka: instance: ## 服务端实例名称 hostname: zxz1 client: ## 不向注册中心注册自己 register-with-eureka: false ## false表示自己就是注册中心,不从eureka服务检索服务信息 fetch-registry: false service-url: defaultZone: http://localhost:7002/eureka server: ## 禁用保护机制 enable-self-preservation: false ## 设置剔除服务的时间 eviction-interval-timer-in-ms: 2000
3.主启动类上添加 @EnableEurekaServer 注解
@SpringBootApplication @EnableEurekaServer public class EurekaMain7001 { public static void main(String[] args) { SpringApplication.run(EurekaMain7001.class, args); } }
作者:[一柒微笑]