1.下载consul_0.7.5_linux_amd64.zip
wget https://releases.hashicorp.com/consul/0.7.5/consul_0.7.5_linux_amd64.zip
2.解压consul_0.7.5_linux_amd64.zip
unzip consul_0.7.5_linux_amd64.zip
解决办法-bash: unzip: 未找到命令如果解压出现该错误
yum -y install unzip
3.检查
./consul 看到如下界面说明安装成功
4.启动
我的linux Ip地址192.168.128.149
./consul agent -dev -ui -node=consul-dev -client=192.168.128.149
5.访问
192.168.128.149:8500
如果访问不了,临时关闭防火墙
systemctl stop firewalld
6.使用postMan注册服务(Post请求)
http://192.168.128.149:8500/v1/catalog/register
参数
{
"Datacenter": "dc1",
"Node": "tomcat",
"Address": "192.168.1.100",
"Service": {
"Id": "192.168.1.100:8080",
"Service": "itmayiedu",
"tags": [
"dev"
],
"Port": 8080
}
}
参数
{
"Datacenter": "dc1",
"Node": "tomcat",
"Address": "192.168.1.100",
"Service": {
"Id": "192.168.1.100:8081",
"Service": "itmayeidu",
"tags": [
"dev"
],
"Port": 8081
}
}
Datacenter指定数据中心,Address指定注册服务的IP,Service.Id指定服务唯一标识,Service.Service指定服务分组,Service.tags指定服务标签(如测试环境、发布环境等),Service.Port指定服务端口
7.存储key/value
使用postmen 发送put请求
http://192.168.128.149:8500/v1/kv/upstreams/itmayiedu/192.168.1.100:8080
http://192.168.128.149:8500/v1/kv/upstreams/itmayiedu/192.168.1.100:8081