【笔记】部署配置服务器
前言
连接eureka,从注册表得到配置中心的地址,连接远程配置中心,从配置中心下载指定的配置文件
配置服务器
创建项目,提取所有的配置到配置中心目录下,并注释每个模块的所有配置
在每个配置添加
禁止配置中心的配置信息覆盖客户端的配置
1 | spring: |
推送到远端Git仓库
将项目添加到本地Git仓库
提交仓库(
command+K)推送到远端(
command+shift+K)defind remote->填写url->push
配置中心服务端
- 创建新模块,作为配置中心服务端
添加依赖
1 | <dependency> |
配置
cloud.config.server.git.uri:远程地址cloud.config.server.git.search-paths:远程地址的目录cloud.config.server.git.username:如果私有仓库,还需要配置用户名cloud.config.server.git.username:指定对应用户名的密码
1 | spring: |
添加启动注解
- 添加
@EnableConfigServer注解
1 |
|
配置中心客户端
- 在每个业务模块中添加配置中心客户端的配置
添加依赖
- 编辑
pom.xml配置文件
1 | <dependency> |
配置
- 在每个模块创建
bootstrap.yml配置文件。bootstrap.yml是引导配置文件,它先于application.yml加载
cloud.connfig.discovery.service-id:配置服务器服务端的id
匹配user-service-dev.yml配置文件
cloud.connfig.name:指定在云端的配置文件前缀cloud.connfig.profile:指定在云端的配置文件后缀
1 | eureka: |