consul搭建配置记录

下载安装

wget  https://releases.hashicorp.com/consul/1.6.2/consul_1.6.2_linux_amd64.zip
unzip consul_1.6.2_linux_amd64.zip
mv consul  /usr/bin/

consul-server启动命令

 consul agent -server  -bootstrap-expect 3  -data-dir /opt/consul/data  -node=s1 -bind=192.168.100.101  -ui  -rejoin -config-dir=/opt/consul/consul.d/ -client 0.0.0.0  

启动命令说明

-server : 定义agent运行在server模式
-bootstrap-expect :在一个datacenter中期望提供的server节点数目,当该值提供的时候,consul一直等到达到指定sever数目的时候才会引导整个集群,该标记不能和bootstrap共用
-bind:该地址用来在集群内部的通讯,集群内的所有节点到地址都必须是可达的,默认是0.0.0.0
-node:节点在集群中的名称,在一个集群中必须是唯一的,默认是该节点的主机名
-ui-dir: 提供存放web ui资源的路径,该目录必须是可读的(-ui使用自带ui)
-rejoin:使consul忽略先前的离开,在再次启动后仍旧尝试加入集群中。
-config-dir:配置文件目录,里面所有以.json结尾的文件都会被加载
-client:consul服务侦听地址,这个地址提供HTTP、DNS、RPC等服务,默认是127.0.0.1所以不对外提供服务,如果你要对外提供服务改成0.0.0.0
-http-port: api端口,覆盖默认的8500

启动一个consul-client并加入现有server

consul agent -data-dir /opt/rh/data -node=c1 -bind=192.168.100.102 -config-dir=/opt/consul2/consul.d/ -join 192.168.100.101

查看consul节点

consul members

注册一个服务

curl -X PUT -d '{"id": "reg1","name": "telegraf","address": "192.168.100.103","port": 80,"tags": ["test","prome","consul"],"checks": [{"http": "http://192.168.100.103:80/metrics","interval": "15s"}]}' http://localhost:8500/v1/agent/service/register

注销一个服务(id字段为标识)

curl -X PUT http://127.0.0.1:8500/v1/agent/service/deregister/reg1
consul搭建配置记录_第1张图片
图片.png

你可能感兴趣的:(consul搭建配置记录)