场景:将开发的springboot项目配置到注册中心中
Eureka 注册中心组件分为两部分 Eureka Server 和 Eureka Client
Eureka Client负责将每个微服务注册到 Eureka Server中去
- 结构分为两部分 配置中心服务端(Eureka server),配置中心客户端(Eureka Client)
- 配置中心服务端即为要配置到的配置中心
- 配置中心客户端即为开发的springboot项目
配置中心服务端(Eureka server)
1 2 3 4 5 6 7 8 9 10
| <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-actuator</artifactId> </dependency>
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| server: port: 1111 eureka: server: enable-self-preservation: false eviction-interval-timer-in-ms: 1000 client: register-with-eureka: false fetch-registry: false serviceUrl.defaultZone: http://localhost:${server.port}/eureka/
|
配置中心客户端(Eureka Client)
1 2 3 4 5 6 7 8 9 10
| <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency>
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| server: port: 1112 spring: application: name: eureka-client
eureka: client: serviceUrl: defaultZone: http://localhost:1111/eureka/ healthcheck: enabled: true instance: lease-renewal-interval-in-seconds: 10 lease-expiration-duration-in-seconds: 10
|
配置中心
场景,可以将yml中配置的一些信息放在git或者本地仓库中,便于维护
举例存在gitee仓库中
1 2 3 4 5
| <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency>
|
此处推荐写在 bootstrap.yml 文件中,官方规定此处 bootstrap.yml的优先级大于 application.yml
1 2 3 4 5 6 7 8 9 10 11
| spring: application: name: config-server cloud: config: server: git: uri: https://gitee.com/****/****.git label: master
|
注:若为私人仓库需要配置用户和密码
自我理解:
去git仓库或者本地仓库把配置信息取到本地,然后通过restful接口访问文件中的数据