配置中心如何解决的呢?配置中心的思路是把项目中的配置参数全部放在一个集中的地方来管理,并提供一套标准的接口,当各个服务需要获取配置的时候就来拉取信息,当配置中心有更新的时候,也能通知其他服务,实时同步最新消息。
- [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。
- [root@localhost ~]# consul kv get redis/config/connection
- 5
- [root@localhost ~]# consul kv get -detailed redis/config/connection
- CreateIndex 454
- Flags 0
- Key redis/config/connection
- LockIndex 0
- ModifyIndex 454
- Session -
- Value 5
- [root@localhost ~]# consul kv delete redis/config/connection
- Success! Deleted key: redis/config/connection
-
- [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
- [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 ~]#
-
- [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 ~]#
-
- [root@localhost ~]# consul kv get -keys
- aaaaaaaaaaaa
- redis/
- redis11
- redis12
-
- [root@localhost ~]# consul kv import @vales.json
-
- [root@localhost ~]# cat vales.json | consul kv import -