1.下載
wget https://releases.hashicorp.com/consul/1.9.2/consul_1.9.2_linux_amd64.zip
2 解壓
unzip consul_1.9.2_linux_amd64.zip
3 檢查
./consul 看到如下界面說明安裝成功
4 啟動
我的linux Ip地址192.168.1.27
./consul agent -dev -ui -node=consul-dev -client=192.168.1.27
5 訪問
http://192.168.1.27:8500/
6 使用postman注冊服務(put請求)
http://192.168.1.27:8500/v1/catalog/register
參數:
{
"Datacenter": "dc1",
"Node": "tomcat",
"Address": "192.168.1.6",
"Service": {
"Id": "192.168.1.6:8080",
"Service": "user-service",
"tags": [
"dev"
],
"Port": 8080
}
}
{
"Datacenter": "dc1",
"Node": "tomcat",
"Address": "192.168.1.6",
"Service": {
"Id": "192.168.1.6:8081",
"Service": "user-service",
"tags": [
"dev"
],
"Port": 8081
}
}
Datacenter指定數據中心,
Address指定注冊服務的IP,
Service.Id指定服務唯一標識,
Service.Service指定服務分組,
Service.tags指定服務標簽(如測試環境、發布環境等),
Service.Port指定服務端口
7.存儲key/value
http://192.168.1.27:8500/v1/kv/upstreams/user-service/192.168.1.27:8080
http://192.168.1.27:8500/v1/kv/upstreams/user-service/192.168.1.27:8081