美文网首页
docker上部署consul

docker上部署consul

作者: lanughing | 来源:发表于2020-09-02 09:02 被阅读0次

    https://www.jianshu.com/p/df3ef9a4f456

    docker拉取最新的consul镜像:docker pull consul

    创建数据中心1:docker run -d -p 8501:8500 --restart=always -v /e/docker/consul/data/server1:/consul/data -v /e/docker/consul/conf/server1:/consul/config -e CONSUL_BIND_INTERFACE='eth0' --privileged=true --name=consul_server_1 consul agent -server -bootstrap-expect=3 -ui -node=node_consul_server_1 -client='0.0.0.0' -data-dir /consul/data -config-dir /consul/config -datacenter=dc1

    linux:docker run -d -p 8501:8500 --restart=always -v /home/mysite/docker/consul/data/server1:/consul/data -v /home/mysite/docker/consul/conf/server1:/consul/config -e CONSUL_BIND_INTERFACE='eth0' --privileged=true --name=consul_server_1 consul agent -server -bootstrap-expect=3 -ui -node=consul_server_1 -client='0.0.0.0' -data-dir /consul/data -config-dir /consul/config -datacenter=tengxun

    通过执行 docker inspect -f '{{.NetworkSettings.IPAddress}}' consul_server_1 获取server1的IP

    创建server2和3并加入节点:

    docker run -d -p 8502:8500 --restart=always -v /e/docker/consul/data/server2:/consul/data -v /e/docker/consul/conf/server2:/consul/config -e CONSUL_BIND_INTERFACE='eth0' --privileged=true --name=consul_server_2 consul agent -server -ui -node=consul_server_2 -client='0.0.0.0' -data-dir /consul/data -config-dir /consul/config -datacenter=dc1 -join 172.17.0.2

    docker run -d -p 8503:8500 --restart=always -v /e/docker/consul/data/server3:/consul/data -v /e/docker/consul/conf/server3:/consul/config -e CONSUL_BIND_INTERFACE='eth0' --privileged=true --name=consul_server_3 consul agent -server -ui -node=consul_server_3 -client='0.0.0.0' -data-dir /consul/data -config-dir /consul/config -datacenter=dc1 -join 172.17.0.2

    linux:docker run -d -p 8503:8500 --restart=always -v /home/mysite/docker/consul/data/server2:/consul/data -v /home/mysite/docker/consul/conf/server2:/consul/config -e CONSUL_BIND_INTERFACE='eth0' --privileged=true --name=consul_server_2 consul agent -server -ui -node=consul_server_2 -client='0.0.0.0' -data-dir /consul/data -config-dir /consul/config -datacenter=tengxun -join 172.17.0.8

    docker run -d -p 8502:8500 --restart=always -v /home/mysite/docker/consul/data/server3:/consul/data -v /home/mysite/docker/consul/conf/server3:/consul/config -e CONSUL_BIND_INTERFACE='eth0' --privileged=true --name=consul_server_3 consul agent -server -ui -node=consul_server_3 -client='0.0.0.0' -data-dir /consul/data -config-dir /consul/config -datacenter=tengxun -join 172.17.0.8

    -bootstarp-expect 3 3个才会启动集群,少于的话启动失败(所以在成功创建第三个server前,查看ui是失败的)

    执行:docker exec consul_server_1 consul operator raft list-peers 查看consul状态


    创建client1:docker run -d -p 8504:8500 --restart=always -v /e/docker/consul/conf/client1:/consul/config -e CONSUL_BIND_INTERFACE='eth0' --name=consul_client_1 consul agent -node=consul_client_1 -client='0.0.0.0' -config-dir /consul/config -datacenter=dc1 -join 172.17.0.2

    创建:client2: docker run -d -p 8505:8500 --restart=always -v /e/docker/consul/conf/client2:/consul/config -e CONSUL_BIND_INTERFACE='eth0' --name=consul_client_2 consul agent -node=consul_client_2 -client='0.0.0.0' -config-dir /consul/config -datacenter=dc1 -join 172.17.0.2

    docker run -d -p 8504:8500 --restart=always -v /home/mysite/docker/consul/conf/client1:/consul/config -e CONSUL_BIND_INTERFACE='eth0' --name=consul_client_1 consul agent -node=consul_client_1 -client='0.0.0.0' -config-dir /consul/config -datacenter=tengxun -join 172.17.0.8

    docker run -d -p 8505:8500 --restart=always -v /home/mysite/docker/consul/conf/client2:/consul/config -e CONSUL_BIND_INTERFACE='eth0' --name=consul_client_2 consul agent -node=consul_client_2 -client='0.0.0.0' -config-dir /consul/config -datacenter=tengxun -join 172.17.0.8

    创建数据中心2:docker run -d --name=consul2-1 -e CONSUL_BIND_INTERFACE='eth0' consul agent -server -bootstrap-expect 2 -datacenter='datacenter2'

    查询数据中心1的容器IP:docker inspect --format '{{ .NetworkSettings.IPAddress }}' consul1-1

    将数据中心2关联到数据中心1上: docker exec -it consul2-1 consul join -wan 172.17.0.3(好像不是这样子的)

    将节点添加数据中心2:docker run -d --name=consul2-2 -e CONSUL_BIND_INTERFACE=eth0 consul agent --datacenter=datacenter2 --server=true --client=0.0.0.0 --join 172.17.0.4

    重点:

    linux服务器上部署了一个consul server,然后其中docker中部署了3个server和2个client,但是server无法加入到集群中,client可以。搞了半天,最后发现两个consul的版本不一样,最后将 docker中的镜像更新到1.8.3和服务器上一致,问题解决。起始在docker的日志中可以看到提示版本的问题

    相关文章

      网友评论

          本文标题:docker上部署consul

          本文链接:https://www.haomeiwen.com/subject/szixnhtx.html