在同一主机上运行的不同consul客户端中添加服务

时间:2016-08-29 18:04:18

标签: docker consul

我使用领事跟随Testing a Consul cluster on a single host中的部分。三个consul服务器已成功添加并在同一主机中运行以进行测试。之后,我也按照教程创建了一个consul客户端node4来公开端口。是否可以添加更多服务并绑定到其中一个领事客户端?

2 个答案:

答案 0 :(得分:1)

使用新的群组模式'而不是传统的Swarm。 Swarm模式不需要Consul。服务发现和键/值存储现在是docker守护程序的一部分。以下是如何创建3节点高可用群集(3个主节点)。

  1. 创建三个节点

    docker-machine create --driver vmwarefusion node01
    docker-machine create --driver vmwarefusion node02
    docker-machine create --driver vmwarefusion node03
    
  2. 找到node01的ip

    docker-machine ls
    
  3. 将一个设为初始群主

    docker $(docker-machine config node01) swarm init --advertise-addr <ip-of-node01>
    
  4. 检索令牌以让其他节点作为主节点加入

    docker $(docker-machine config node01) swarm join-token manager
    

    这将打印出类似

    的内容
    docker swarm join \
    --token SWMTKN-1-0siwp7rzqeslnhuf42d16zcwodk543l99liy0wuq1mern8s8u9-8mbsrxzu9mgfw7x6ehpxh0dof \
    192.168.40.144:2377
    
  5. 将其他两个节点添加到群组作为母版

    docker $(docker-machine config node02) swarm join \
    --token SWMTKN-1-0siwp7rzqeslnhuf42d16zcwodk543l99liy0wuq1mern8s8u9-8mbsrxzu9mgfw7x6ehpxh0dof \
    192.168.40.144:2377
    
    docker $(docker-machine config node03) swarm join \
    --token SWMTKN-1-0siwp7rzqeslnhuf42d16zcwodk543l99liy0wuq1mern8s8u9-8mbsrxzu9mgfw7x6ehpxh0dof \
    192.168.40.144:2377
    
  6. 检查群体

    docker node ls
    
  7. 您现在应该能够关闭领导者节点并看到另一个领导者作为经理。

答案 1 :(得分:0)

Best practice for Consul, is to run consul one per HOST, and when you want to talk to consul, you always talk locally. In general, everything 1 consul node knows, every other consul node also knows. So you can just talk to your localhost consul (127.0.0.1:8500) and do everything you need to do. When you add services, you add them to the local consul node that has the service's process on it. There are projects like Registrator (https://github.com/gliderlabs/registrator) That will automatically add services from running docker containers, which makes life easier.

Overall, welcome to Consul, it's great stuff!