consul部署及使用

192 阅读1分钟

参考:kingfree.gitbook.io/consul/gett…

部署

CentOS系统使用yum安装

sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
sudo yum -y install consul

修改配置文件

cd /etc/consul.d/
cp consul.hcl consul.hcl.bak
vi consul.hcl
修改client_addr="0.0.0.0" # 默认是127.0.0.1 无法外网访问

启动consul服务

# 开启consul服务,-ui参数开启ui,可通过 http://${公网ip}:8500/ui 管理
consul agent -dev -ui -config-dir=/etc/consul.d

使用

服务注册与发现

参考:www.consul.io/docs/discov… 1、直接配置服务在 /etc/consul.d 目录下 2、通过http接口进行register,unregister

python-consul

官网:python-consul.readthedocs.io/en/latest/

web管理

部署完成后,可以通过 http://${公网ip}:8500/ui访问,官网提供一个demo可以体验: demo.consul.io/ui/dc1/serv…

consul-templete

参考:zhuanlan.zhihu.com/p/95602359