• consul 键值对操作命令


    传统配置文件的弊端


    • 静态化配置,例如env文件
    • 配置文件无法区分环境
    • 配置文件过于分散
    • 历史版本无法查看

    配置中心如何解决的呢?配置中心的思路是把项目中的配置参数全部放在一个集中的地方来管理,并提供一套标准的接口,当各个服务需要获取配置的时候就来拉取信息,当配置中心有更新的时候,也能通知其他服务,实时同步最新消息。

     

     

    微服务配置中心


    • 配置信息的管理
    • 配置信息的查看、读取、更新等,完善的Api管理界面
    • 高可用、权限管理等功能

     

     

    主流的配置中心


    • Apollo是由携程开源的分布式配置中心
    • Spring Cloud Config
    • Consul

     

     

    CURD操作


    1. 创建或更新—>put
    1. [root@localhost ~]# consul kv put redis/config/connection 5
    2. Success! Data written to: redis/config/connection
    3. [root@localhost ~]# consul kv put aaaaaaaaaaaa 5
    4. Success! Data written to: aaaaaaaaaaaa

    /redis/config会生成两个目录,connection会生成文件,文件里面的值为5。

    2. 获取值—>get
    1. [root@localhost ~]# consul kv get redis/config/connection
    2. 5
    3. 查询详情—> detailed
    1. [root@localhost ~]# consul kv get -detailed redis/config/connection
    2. CreateIndex 454
    3. Flags 0
    4. Key redis/config/connection
    5. LockIndex 0
    6. ModifyIndex 454
    7. Session -
    8. Value 5
    4. 删除键—>delete
    1. [root@localhost ~]# consul kv delete redis/config/connection
    2. Success! Deleted key: redis/config/connection
    5. 递归删除—>recurse
    1. [root@localhost ~]# consul kv put redis/one 1
    2. Success! Data written to: redis/one
    3. [root@localhost ~]# consul kv put redis/two 2
    4. Success! Data written to: redis/two
    5. [root@localhost ~]# consul kv put redis/three 3
    6. Success! Data written to: redis/three
    7. [root@localhost ~]# consul kv put redis/four 4
    8. Success! Data written to: redis/four
    9. [root@localhost ~]# consul kv delete -recurse redis/
    10. Success! Deleted keys with prefix: redis/
    11. [root@localhost ~]# consul kv get redis/one
    12. Error! No key exists at: redis/one
    6. 导出指定前缀的键—>export
    1. [root@localhost ~]# consul kv put redis/one 1
    2. Success! Data written to: redis/one
    3. [root@localhost ~]# consul kv put redis/two 2
    4. Success! Data written to: redis/two
    5. [root@localhost ~]# consul kv put redis/three 2
    6. Success! Data written to: redis/three
    7. [root@localhost ~]# consul kv put redis/four 2
    8. Success! Data written to: redis/four
    9. [root@localhost ~]# consul kv export redis/
    10. [
    11. {
    12. "key": "redis/four",
    13. "flags": 0,
    14. "value": "Mg=="
    15. },
    16. {
    17. "key": "redis/one",
    18. "flags": 0,
    19. "value": "MQ=="
    20. },
    21. {
    22. "key": "redis/three",
    23. "flags": 0,
    24. "value": "Mg=="
    25. },
    26. {
    27. "key": "redis/two",
    28. "flags": 0,
    29. "value": "Mg=="
    30. }
    31. ]
    32. [root@localhost ~]#
    7. 列出指定前缀的所有键—> keys
    1. [root@localhost ~]# consul kv get -keys redis
    2. redis/
    3. [root@localhost ~]# consul kv get -keys redis/
    4. redis/four
    5. redis/one
    6. redis/three
    7. redis/two
    8. -separator="" 表示禁用分隔符
    9. [root@localhost ~]# consul kv get -keys -separator="" redis
    10. redis/four
    11. redis/one
    12. redis/three
    13. redis/two
    14. redis11
    15. redis12
    16. [root@localhost ~]# consul kv get -keys redis
    17. redis/
    18. redis11
    19. redis12
    20. [root@localhost ~]# consul kv get -keys redis/
    21. redis/four
    22. redis/one
    23. redis/three
    24. redis/two
    25. [root@localhost ~]#
    8. 列出所有键
    1. [root@localhost ~]# consul kv get -keys
    2. aaaaaaaaaaaa
    3. redis/
    4. redis11
    5. redis12
    9. 从文件中导入键值对
    1. [root@localhost ~]# consul kv import @vales.json
    2. [root@localhost ~]# cat vales.json | consul kv import -
  • 相关阅读:
    【Flink】需求实现之独立访客数量的计算 和 布隆过滤器的原理及使用
    maven依赖问题ClassNotFoundException 和NoClassDefFoundError
    git创建新分支将项目挂载到新分支操作
    [Docker] Docker安装青龙并且设置
    850. 矩形面积 II--(每日一难phase--day16)
    【每日一题】 和为 K 的子数组
    C语言中的strcpy,strncpy,memcpy,memmove,memset函数strcmp
    M2 MacbookPro配置Spark源码运行环境
    110. 平衡二叉树
    使用docker-compose部署,宿主机可链接使用的redis cluster
  • 原文地址:https://blog.csdn.net/qq_34556414/article/details/132802898