Fork me on GitHub

用git2consul从Git同步配置到Consul

目录

TIPS

当且仅当 spring.cloud.consul.config.format=files 时,才可用git2consul管理配置,其他格式无法使用。

单机版Consul的配置是不持久化的,一旦重启就会丢失,而开发过程中,重启Consul可能比较频繁。要想解决这个问题,可将配置存储到Git仓库,并使用git2consul将配置同步到Consul中,以下是步骤。

安装Node.js

下载Node.js

前往 https://nodejs.org/en/download/ 可下载最新版本Node.js;前往 https://nodejs.org/en/download/releases/ 可下载指定版本Node.js;根据自己的操作系统,下载安装即可。

TIPS

尽量安装LTS版本,例如:10.16.3

安装Node.js

参考 https://www.runoob.com/nodejs/nodejs-install-setup.html 安装Node.js,常见系统安装说明都有。

安装git2consul

指定如下命令即可安装git2consul

1
npm install -g git2consul

如果网络不好,安装速度过慢,可使用如下命令:

1
npm install -g git2consul --registry=https://registry.npm.taobao.org

注意:对于Windows操作系统,需执行:

1
npm install -g consul-windows

配置git2consul

准备配置文件,名为 git2consul.json 内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
// 配置版本
"version": "1.0",
"repos": [
{
// 名称,指的是在consul里面的目录名称
"name": "config",
// 要同步的Git仓库
"url": "你的git仓库",
"branches": [
// 要同步的分支
"master"
],
// 是否要把分支名称作为Consul的key前缀
"include_branch_name": false,
"hooks": [
{
// 拉取模式
"type": "polling",
// 同步的间隔(分钟)
"interval": "1"
}
]
}
]
}

其他选项详见:https://github.com/breser/git2consul

启动git2consul

执行如下命令,即可启动git2consul

1
git2consul --config-file /Users/itmuch/develop/git2consul.json

注意:对于Windows操作系统,需执行:

1
git2consul-windows --config-file C:/xxxx/xxx/git2consul.json

参考文档

相关文章

评论系统未开启,无法评论!