配置中心如何解决的呢?配置中心的思路是把项目中的配置参数全部放在一个集中的地方来管理,并提供一套标准的接口,当各个服务需要获取配置的时候就来拉取信息,当配置中心有更新的时候,也能通知其他服务,实时同步最新消息。
1.添加配置信息
2.获取配置信息
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
}
]
补充一下单点服务器Consul集群的步骤,我的虚拟机ip 192.168.88.144
,配置3个节点, 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
目录:
├── 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详细参数,执行命令consul 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详细参数,执行命令consul 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详细参数,执行命令consul 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"
]
}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有