Docker 安装单机consul与python API注册与注销
安装单机consul
mkdir -p /consul/data
docker run -d -p 8500:8500 --restart=always --name=consul -v /consul/data:/consul/data consul agent -server -ui --client=0.0.0.0 -bootstrap-expect=1
查看安装日志
docker logs <id>
访问
http://192.168.0.184:8500/ui/dc1/services
Python API注册与注销
安装
pip install python-consul
连接
import consul
consul = consul.Consul("192.168.0.184", 8500)
注册
consul.agent.service.register(name="server1",address="192.168.0.59",port=8900)
注销
consul.agent.service.deregister(service_id="server1")
测试(在192.168.0.59起一个端口)
python -m SimpleHTTPServer 8900