2019年第一篇blog打算从微服务开始,正所谓本身立下的flag趴着也要写完^^.因此从今天开始打算会持续写Spring-Cloud相关文章.java
由于单体用用存在一些问题,总结概括以下:spring
- Eureka:在英文词典中意为"找到了,发现了", 顾名思义,他在Spring-Cloud中承担的角色是服务的注册与发现
- Spring Cloud Eureka 是基于Netflix Eureka作的二次封装
- Spring Cloud Eureka 组件由两部分组成 Eureka-Server, Eureka-Client
- Eureka-Server:服务注册中心
- Eureka-Client:服务注册和服务调用
打开idea,选择建立Spring项目 bootstrap
选择Maven坐标:gav 架构
选择项目类型为Eureka-Server app
建立完项目以后,查看Pom中Spring-Cloud与Boot版本:ide
<!-- spring-boot版本 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<!-- spring-cloud版本 -->
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.RC1</spring-cloud.version>
</properties>
复制代码
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
复制代码
- 因为Spring-Cloud中bootstrap.yml/properties(这里采用yml)是项目的启动加载配置文件,因此咱们先将配置文件重命名为bootstrap.yml
eureka:
client:
service-url:
defaultZone: http://localhost:8762/eureka/,http://localhost:8763/eureka/
register-with-eureka: false
spring:
application:
name: eureka-server
server:
port: 8761
复制代码
Eureka-Server2的配置文件以下:spring-boot
spring:
application:
name: eureka-server2
server:
port: 8762
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/,http://localhost:8763/eureka/
register-with-eureka: false
复制代码
Eureka-Server3的配置文件以下:微服务
spring:
application:
name: eureka-server3
server:
port: 8763
eureka:
client:
register-with-eureka: false
service-url:
defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/
复制代码
配置说明:url
- spring.application.name: 是服务的名称
- server.port: 表明服务的端口
- eureka.client.register-with-eureka=false 表示让Eureka-Server本身不须要注册到本身
- 由上面三个Eureka-Server的配置咱们能够看到,在注册Eureka-Server集群中,咱们只须要将不一样的Eureka-Server相互注册,就能够实现Eureka-Server的高可用
到这里,咱们集群式的Eureka-Server已经搭建好了, 咱们下一节来搭建Eureka-Client来发现服务.好了,预知后事如何, 请听下回分解!idea