Microservices - build Consul cluster service, Consul configuration center

Drawbacks of Traditional Profiles

  • Static configuration, such as env file
  • config files cannot distinguish between environments
  • Configuration files are too scattered
  • Historical versions cannot be viewed

How does the configuration center solve it? The idea of ​​the configuration center is to manage all the configuration parameters in the project in a centralized place, and provide a set of standard interfaces to pull information when each service needs to obtain configuration. When the configuration center is updated, it can also notify other services and synchronize the latest news in real time.

Microservice Configuration Center

  • Management of configuration information
  • View, read, update, etc. of configuration information, perfect Api management interface
  • High availability, authority management and other functions

Mainstream Configuration Center

  • Apollo is a distributed configuration center open sourced by Ctrip
  • Spring Cloud Config
  • Consul

Consul configuration operations

1. Add configuration information

3.png

2. Obtain configuration information

GET http://192.168.88.144:8500/v1/kv/mic/pro/pro
[
    {
        "LockIndex":0,
        "Key":"mic/pro/pro",
        "Flags":0,
        "Value":"ewoJImhvc3QiOiIxMjcuMC4wLjEiLAogICJwcm90IjogMzMwNiwKICAidXNlciI6InRlc3QiLAogICJwd2QiOiIxMjcuMC4wLjEiCn0=",
        "CreateIndex":473,
        "ModifyIndex":473
    }
]

Single point server Consul cluster

Add the steps of the single-point server Consul cluster, my virtual machine ip 192.168.88.144, configure 3 nodes,Consul v1.12.1

server01@server01-virtual-machine:~$ consul version
Consul v1.12.1
wget https://releases.hashicorp.com/consul/1.12.1/consul_1.12.1_darwin_arm64.zip
unzip consul_1.12.1_darwin_arm64.zip
mv consul /usr/local/bin/consul

Table of contents:

├── client1
├── client2
├── condifg
├── data
├── server1
│   ├── basic.json
│   ├── data
│   ├── log
│   └── nohup.out
├── server2
│   ├── basic.json
│   ├── data
│   ├── log
│   └── nohup.out
└── server3
    ├── basic.json
    ├── data
    ├── log
    └── nohup.out

server1 basic.json detailed parameters, execute the commandconsul agent -config-dir=/home/server01/soft/consul/server1/basic.json

{
    "bind_addr":"127.0.0.1",
    "client_addr":"0.0.0.0",
    "ports":{
        "http":8500,
        "dns":8600,
        "serf_lan":8011,
        "serf_wan":8002,
        "server":8700
    },
    "datacenter":"dc1",
    "data_dir":"/home/server01/soft/consul/server1/data",
    "log_level":"INFO",
    "log_file":"/home/server01/soft/consul/server1/log/consul.log",
    "node_name":"consul-server-1",
    "disable_host_node_id":true,
    "server":true,
    "ui":true,
    "bootstrap_expect":3,
    "rejoin_after_leave":true,
    "retry_join":[
        "127.0.0.1:8011",
        "127.0.0.1:8101",
        "127.0.0.1:8201"
    ]
}

server2 basic.json detailed parameters, execute the commandconsul agent -config-dir=/home/server01/soft/consul/server2/basic.json

{
    "bind_addr":"127.0.0.1",
    "client_addr":"0.0.0.0",
    "ports":{
        "http":8501,
        "dns":8601,
        "serf_lan":8111,
        "serf_wan":8102,
        "server":8701
    },
    "datacenter":"dc1",
    "data_dir":"/home/server01/soft/consul/server2/data",
    "log_level":"INFO",
    "log_file":"/home/server01/soft/consul/server2/log/consul.log",
    "node_name":"consul-server-2",
    "disable_host_node_id":true,
    "server":true,
    "ui":true,
    "bootstrap_expect":3,
    "rejoin_after_leave":true,
    "retry_join":[
        "127.0.0.1:8011",
        "127.0.0.1:8111",
        "127.0.0.1:8211"
    ]
}

server3 basic.json detailed parameters, execute the commandconsul agent -config-dir=/home/server01/soft/consul/server3/basic.json

{
    "bind_addr":"127.0.0.1",
    "client_addr":"0.0.0.0",
    "ports":{
        "http":8502,
        "dns":8602,
        "serf_lan":8211,
        "serf_wan":8202,
        "server":8702
    },
    "datacenter":"dc1",
    "data_dir":"/home/server01/soft/consul/server3/data",
    "log_level":"INFO",
    "log_file":"/home/server01/soft/consul/server3/log/consul.log",
    "node_name":"consul-server-3",
    "disable_host_node_id":true,
    "server":true,
    "ui":true,
    "bootstrap_expect":3,
    "rejoin_after_leave":true,
    "retry_join":[
        "127.0.0.1:8011",
        "127.0.0.1:8111",
        "127.0.0.1:8211"
    ]
}

2.png

Guess you like

Origin blog.csdn.net/xuezhiwu001/article/details/130310782