Eureka从零到1:(01)
Eureka包含两个组件
Eureka Server提供注册服务
各个微服务节点通过配置启动后,会在EurekaServer中进行注册,这样EurekaServer中的服务注册表中将会存储所有可用服务节点的信息,服务节点的信息可以在界面中直观看到。
Eureka Client通过注册中心访问
是一个JAVA客户端,用于简化Eureka Server的交互,客户端同时也是具备一个内置的、使用轮询(round-robin)
负载算法的负载均衡器。在应用启动后,将会向EurekaServer发送心跳(默认周期时30秒)。如果EurekaServer在多个心跳周期内没有收到某个节点的心跳,EurekaServer将会从服务注册表中将这个服务节点删除(默认90秒)
pom依赖
2020.2版本
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
Yaml文件
server:
port: 7001
eureka:
instance:
hostname: localhost#eureka服务端的实例名称
client:
#false表示不向注册中心注册自己
register-with-eureka: false
#false表示自己端就是注册中心,我的职责就是维护服务实例,并不需要去检索服务
fetch-registry: false
service-url:
#设置与Eureka Server交互的地址查询服务和注册服务都要依赖这个地址
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
在SpringBoot启动器上面添加@EnableEurekaServer注解
这个注解表明是作为服务器
启动SpringBoot的启动器
在浏览器输入http://localhost:7001/
即可进入erueka的页面
启动类页面类似下面页面:
System Status
Environment | test |
---|---|
Data center | default |
Current time | 2020-12-18T23:43:20 +0800 |
---|---|
Uptime | 00:11 |
Lease expiration enabled | false |
Renews threshold | 1 |
Renews (last min) | 0 |
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.
DS Replicas
Instances currently registered with Eureka
Application | AMIs | Availability Zones | Status |
---|---|---|---|
No instances available |
General Info
Name | Value |
---|---|
total-avail-memory | 364mb |
environment | test |
num-of-cpus | 4 |
current-memory-usage | 95mb (26%) |
server-uptime | 00:11 |
registered-replicas | http://localhost#eureka服务端的实例名称:7001/eureka/ |
unavailable-replicas | http://localhost#eureka服务端的实例名称:7001/eureka/, |
available-replicas |
Instance Info
Name | Value |
---|---|
ipAddr | 192.168.124.1 |
status | UP |