1. Spring Cloud Eureka的介绍
Spring Cloud Eureka是基于Netflix Eureka之上做了二次封装。它主要由Eureka Server和Eureka Client组成。
Eureka Server即注册中心服务端,供服务注册的服务器。服务端记录着每个服务的名字,运行状态、在哪台机器上啊。
Eureka Client即服务注册客户端,用来简化与服务端的交互,作为轮询负载均衡器并提供服务的故障切换支持。系统中的其他服务通过客户端连接到服务端,并维持心跳连接,检测各个服务间是否正常运行。
2. Eureka Server的开发
创建项目,我用的是idea开发。



创建完项目后可删除一些不必要的文件

注意这里的版本要跟我保持一致,要不然掉坑里就难爬出来

spring cloud 与其他的版本关系: https://projects.spring.io/spring-cloud/

在启动类加上@EnableEurekaServer ,加这个注解表示这是注册中心服务端,然后启动项目。

启动后打开 http://localhost:8080/ 这就是注册中心

一直报错是因为这个项目既是Server端同时,它也是一个client端。按照下面的进行配置,这样启动完成后就不会报错了

如下图所示,eureka服务就注册到服务端了。

实际情况中,这个eureka服务就是一个服务端,它不应该注册到服务中心,可以通过如下配置,不注册到服务中心。


代码git地址: https://github.com/hmilyos/springCloud-eureka.git
网友评论