1.Eureka 依赖版本的变动。新版本客户端服务端互相分离开了
搭建简单的Eureka项目Server端:
依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
yml:
server:
port: 7001
eureka:
instance:
hostname: localhost
client:
#不向注册中心注册自己
register-with-eureka: false
#自己已经是注册中心,不需要去检索服务
fetch-registry: false
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
启动器:
@SpringBootApplication
@EnableEurekaServer
public class EurekaMain7001 {
public static void main(String[] args) {
SpringApplication.run(EurekaMain7001.class,args);
}
}
需要注明其是EurekaServer
搭建Client端
依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
yml配置
eureka:
client:
#是否把自己注册进EurekaServer 默认为true
register-with-eureka: true
#是否从Eureka抓取已有的注册信息,默认true 单节点无所谓,集群必须设置为true才能配合ribbon使用负载均衡
fetch-registry: true
service-url:
defaultZone: http://localhost:7001/eureka
启动添加注解:
@EnableEurekaClient
Eureka服务集群配置
原理:
对外暴露是Eureka但是内部其实是多个Eureka Server互相注册,互相守望