eureka server
Eureka是一个基于REST(Representational State Transfer)的服务,主要用于AWS cloud, 提供服务定位(locating services)、负载均衡(load balancing)、故障转移(failover of middle-tier servers)。
服务说明
详细说明可以查看博客:https://blog.rmiao.top/springcloud-eureka/
这位博主对eureka做了详细的介绍
应用说明
使用框架
- SpringBoot 2.0.3
- SpringCloud Finchley.RELEASE
使用jar包
- spring-cloud-starter-netflix-eureka-server
- spring-boot-starter-web
eureka 服务
pom文件
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
启动文件
启动类添加注释@EnableEurekaServer
配置文件
spring:
application:
name: cloud-eureka
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
register-with-eureka: false
fetch-registry: false
serviceUrl:
defaulZone: http://${eureka.instance.hostname}:${server.port}/eureka/
healthcheck:
enabled: true
server:
eviction-interval-timer-in-ms: 60000
enable-self-preservation: false
eureka client
pom文件修改
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 系统注册与监测服务 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
启动文件
启动类添加注释@EnableDiscoveryClient
配置文件
server:
port: 8771
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:8761/eureka/
spring:
application:
name: cloud-eureka-client
启动项目
做完前面的步骤一个eureka应用服务已经搭建完成了,跑起来试试吧
- 使用SpringBoot启动项目
- 访问http://localhost:8761
- 这个时候就可以看到启动好的cloud-eureka-client了
好了,项目完毕,自己试试吧!