传统配置文件的弊端
- 静态化配置,例如env文件
- 配置文件无法区分环境
- 配置文件过于分散
- 历史版本无法查看
配置中心如何解决的呢?配置中心的思路是把项目中的配置参数全部放在一个集中的地方来管理,并提供一套标准的接口,当各个服务需要获取配置的时候就来拉取信息,当配置中心有更新的时候,也能通知其他服务,实时同步最新消息。
微服务配置中心
- 配置信息的管理
- 配置信息的查看、读取、更新等,完善的Api管理界面
- 高可用、权限管理等功能
主流的配置中心
- Apollo是由携程开源的分布式配置中心
- Spring Cloud Config
- Consul
CURD操作
1. 创建或更新—>put
[root@localhost ~]# consul kv put redis/config/connection 5
Success! Data written to: redis/config/connection
[root@localhost ~]# consul kv put aaaaaaaaaaaa 5
Success! Data written to: aaaaaaaaaaaa
/redis/config会生成两个目录,connection会生成文件,文件里面的值为5。
2. 获取值—>get
[root@localhost ~]# consul kv get redis/config/connection
5
3. 查询详情—> detailed
[root@localhost ~]# consul kv get -detailed redis/config/connection
CreateIndex 454
Flags 0
Key redis/config/connection
LockIndex 0
ModifyIndex 454
Session -
Value 5
4. 删除键—>delete
[root@localhost ~]# consul kv delete redis/config/connection
Success! Deleted key: redis/config/connection
5. 递归删除—>recurse
[root@localhost ~]# consul kv put redis/one 1
Success! Data written to: redis/one
[root@localhost ~]# consul kv put redis/two 2
Success! Data written to: redis/two
[root@localhost ~]# consul kv put redis/three 3
Success! Data written to: redis/three
[root@localhost ~]# consul kv put redis/four 4
Success! Data written to: redis/four
[root@localhost ~]# consul kv delete -recurse redis/
Success! Deleted keys with prefix: redis/
[root@localhost ~]# consul kv get redis/one
Error! No key exists at: redis/one
6. 导出指定前缀的键—>export
[root@localhost ~]# consul kv put redis/one 1
Success! Data written to: redis/one
[root@localhost ~]# consul kv put redis/two 2
Success! Data written to: redis/two
[root@localhost ~]# consul kv put redis/three 2
Success! Data written to: redis/three
[root@localhost ~]# consul kv put redis/four 2
Success! Data written to: redis/four
[root@localhost ~]# consul kv export redis/
[
{
"key": "redis/four",
"flags": 0,
"value": "Mg=="
},
{
"key": "redis/one",
"flags": 0,
"value": "MQ=="
},
{
"key": "redis/three",
"flags": 0,
"value": "Mg=="
},
{
"key": "redis/two",
"flags": 0,
"value": "Mg=="
}
]
[root@localhost ~]#
7. 列出指定前缀的所有键—> keys
[root@localhost ~]# consul kv get -keys redis
redis/
[root@localhost ~]# consul kv get -keys redis/
redis/four
redis/one
redis/three
redis/two
-separator="" 表示禁用分隔符
[root@localhost ~]# consul kv get -keys -separator="" redis
redis/four
redis/one
redis/three
redis/two
redis11
redis12
[root@localhost ~]# consul kv get -keys redis
redis/
redis11
redis12
[root@localhost ~]# consul kv get -keys redis/
redis/four
redis/one
redis/three
redis/two
[root@localhost ~]#
8. 列出所有键
[root@localhost ~]# consul kv get -keys
aaaaaaaaaaaa
redis/
redis11
redis12
9. 从文件中导入键值对
[root@localhost ~]# consul kv import @vales.json
[root@localhost ~]# cat vales.json | consul kv import -
标签:操作命令,Success,consul,redis,键值,kv,root,localhost
From: https://blog.51cto.com/u_14035463/7689631