苏苏的博客

简约至极

etcd和consul

https://github.com/coreos/etcd

https://github.com/hashicorp/consul

etcdconsul 都是由golang编写的服务发现和配置共享的软件

传统的类似软件有zookeeper等,zookeeper采用java编写

其说明比较可参见

https://blog.coding.net/blog/intro-consul?type=hot

etcd 与 consul zookeeper 对比一览

https://coreos.com/etcd/docs/latest/learning/why.html

consul

启动一个server

consul agent -data-dir=/tmp/consul

docker run –rm -it -p 8500:8500 –name=node1 consul agent -server -bootstrap-expect=1 -node=node1 -ui -client 0.0.0.0

docker run –rm -it –name=node2 consul agent -server -join=172.17.0.3 -node=node2

docker run –rm -it –name=node4 consul agent -bind=172.17.0.5 -retry-join=172.17.0.3 -node=node4

查看下集群的状态

docker exec -t node1 consul members

测试

docker run --rm -it \
--name=consul \
-m 100m \
-p 8500:8500 \
consul agent -server -ui -node=master -datacenter=dc1 -client=0.0.0.0 -bootstrap-expect=1

加密码

-e 'CONSUL_LOCAL_CONFIG={"acl_master_token": "e5fa3281-3009-4f88-bfeb-acd46438dfa0","acl_datacenter":"dc1"}' \

单节点,无密码启动

docker run -d \
--name=consul \
--restart always \
-m 100m \
-p 8500:8500 \
-v /data/consul:/consul/data \
consul agent -server -ui -node=master -client=0.0.0.0 -bootstrap-expect=1

单节点带密码

docker run -d \
--name=consul \
--restart always \
-m 100m \
-p 8500:8500 \
-v /data/consul:/consul/data \
-e 'CONSUL_LOCAL_CONFIG={"acl_master_token": "e5fa3281-3009-4f88-bfeb-acd46438dfa0","acl_default_policy": "deny", "acl_datacenter":"dc1"}' \
consul agent -server -ui -node=master -datacenter=dc1 -client=0.0.0.0 -bootstrap-expect=1

配置一个策略让某个用户使用


agent "" {
  policy = "write"
}

key "" {
  policy = "write"
}

node "" {
  policy = "write"
}
service "" {
  policy = "write"
}