单机启动
consul agent -data-dir=/root/consul -bind=192.168.100.12 -server -bootstrap -client 0.0.0.0 -ui
-bootstrap 参数 单机启动并且声明自己是Leader
-ui 参数 启动web界面
-server 参数 是声明自己是服务端
服务注册
vim service.json
{
"ID": "ws001",
"Name": "websocket",
"Tags": [
"primary"
],
"Address": "192.168.137.144",
"Port": 18308,
"Check": {
"HTTP": "http://192.168.137.144:18308/health",
"Interval": "5s"
}
}
address 是要注册服务的ip。name是服务器名。id自己主机的身份
curl \
--request PUT \
--data @service.json \
192.168.100.12:8500/v1/agent/service/register
服务注销(反注册)
curl \
--request PUT \
192.168.100.12:8500/v1/agent/service/deregister/ws001
服务注销 /v1/agent/service/deregister/{ID}