Eureka是一套框架,它的做用是提供服务注册与服务发现。
Eureka做为注册中心,它由服务端与客户端两个组件构成,客户端一般分为两种:1.服务提供方;2.服务消费方。系统中的其它微服务,使用Eureka客户端链接到Eureka的服务端,并持续保持链接。这样,系统维护人员能够经过Eureka服务端来监控系统中各个微服务是否正常运行。
以下是搭建一个注册中心的流程
1.新建一个maven module,在pom.xml添加以下依赖spring
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> </dependencies>
如上是Eureka注册中心服务端jar包
2.启动代码添加注册服务注解@EnableEurekaServer,以下app
@SpringBootApplication @EnableEurekaServer public class EurekaserverApplication { public static void main(String[] args) { SpringApplication.run(EurekaserverApplication.class, args); } }
3.配置文件中作以下配置框架
spring.application.name=spider-registry server.port=8026 eureka.instance.hostname= ${spring.cloud.client.ipAddress} eureka.client.register-with-eureka=false eureka.client.fetch-registry=false
spring.application.name:表示注册服务名称
server.port:注册服务端口
eureka.instance.hostname:注册服务在注册中心显示形式为Ip+端口显示,而不是以域名形式显示
eureka.client.register-with-eureka:eureka客户端是否注册到服务端
eureka.client.fetch-registry:eureka客户端是否从注册中心获取注册信息
4.运行起工程
在地址栏输入ip+端口就能看到注册中心的页面
eg:http://localhost:8026/maven