一、Eureka配置
①Eureka Server
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
@Slf4j
@SpringBootApplication
// eureka服务端
@EnableEurekaServer
public class EurekaMain7001 {
public static void main(String[] args) {
SpringApplication.run(EurekaMain7001.class,args);
log.info("=====================Eureka7001服务启动成功!=====================");
}
}
server:
port: 7001
servlet:
context-path: /eureka
eureka:
instance:
hostname: localhost #eureka服务端的实例名称
client:
register-with-eureka: false #false表示不向注册中心注册自己
fetch-registry: false #fasle表示自己就是注册中心,我的职责就是维护服务实列,并不需要去检索服务
service-url:
#设置与Eureka server交互的地址查询服务器和注册服务都需要依赖这个地址
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
②Client
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-client</artifactId>
</dependency>
@Slf4j
@SpringBootApplication
@EnableEurekaClient
public class PaymentMain8001 {
public static void main(String[] args) {
SpringApplication.run(PaymentMain8001.class,args);
log.info("========支付服务8001启动成功!======");
}
}
# 注册中心
eureka:
client:
register-with-eureka: true # 表示是否将自己注册进Eureka Server默认true
# 是否从EurekaServer中抓取已有的注册信息,默认为true。单点登录无所谓,集群必须设置为true才能配合ribbon使用负载均衡
fetch-registry: true
service-url:
defaultZone: http://localhost:7001/eureka/
二、特性
心跳:30s
三、相关问题
1.Eureka报警:EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER THAN THRESHOLD AND HENCE THE INSTANCES ARE NOT BEING EXPIRED JUST TO BE SAFE.
紧急!Eureka可能错误地声称实例已经启动,而实际上它们并没有。更新小于阈值,因此实例不会过期,只是为了安全。
这是Eureka自我保护机制,