Cluster deployment test of consult docker

in Tutorials with 1 comment

What is consult?

Consult, however, is a tool for discovering multiple components and services. It provides the following key functions:

Designed to be friendly to the Devops community and application developers, consult is well suited for a modern, scalable infrastructure.

Let's start building the consult cluster and testing

Test configuration

1. Take the official image

 docker search consul
docker pull consul

2. Start consult

 docker run -d -e 'CONSUL_ LOCAL_ CONFIG={"skip_ leave_ on_ interrupt": true}' --name=node1 consul agent -server -bind=172.26.0.2 -bootstrap-expect=3 -node=node1

-Node: the name of the node

-Bind: an address bound. It is used for communication between nodes. It can be an internal and external network and must be an accessible address

-Server: this means that the node is a server

-Bootstrap expect: This is the number of server nodes expected to be provided. Once the number is reached, it will be activated, and then leader

 docker run -d -e 'CONSUL_ LOCAL_ CONFIG={"skip_ leave_ on_ interrupt": true}' --name=node2 consul agent -server -bind=172.26.0.3  -join=172.26.0.2 -node-id=$(uuidgen | awk '{print tolower($0)}')  -node=node2
 docker run -d -e 'CONSUL_ LOCAL_ CONFIG={"skip_ leave_ on_ interrupt": true}' --name=node3 consul agent -server -bind=172.26.0.4  -join=172.26.0.2 -node-id=$(uuidgen | awk '{print tolower($0)}')  -node=node3 -client=172.26.0.4

-Join: This indicates which cluster to join when starting. Here, it means to join the cluster of node 1

-Node ID: this seems to have been added in version 8. Here, use this to specify the unique node ID. you can view this issue

-Client: This represents the IP address operated by a series of clients such as registration or query. If this IP is not specified, the default is 127.0.0.1.

 docker run -d -e 'CONSUL_ LOCAL_ CONFIG={"leave_ on_ terminate": true}' --name=node4 consul agent -bind=172.26.0.5 -retry-join=172.26.0.2 -node-id=$(uuidgen | awk '{print tolower($0)}')  -node=node4

3. View cluster status

 docker exec -t node1 consul members

return

 Node   Address          Status  Type    Build  Protocol  DC   Segment
node1  172.26.0.2:8301  alive   server  1.0.6  2         dc1  <all>
node2  172.26.0.3:8301  alive   server  1.0.6  2         dc1  <all>
node3  172.26.0.4:8301  alive   server  1.0.6  2         dc1  <all>
node4  172.26.0.5:8301  alive   client  1.0.6  2         dc1  <default>

4. View leader

 Curl http: / / 172.26.0.4:8500 / V1 / status / leader 
 / / returns 
 "172.26.0.2:8300"

5. Add new node

 docker run -d -e 'CONSUL_ LOCAL_ CONFIG={"leave_ on_ terminate": true}' --name=node6 consul agent -bind=172.26.0.6 -retry-join=172.26.0.2 -node-id=$(uuidgen | awk '{print tolower($0)}')  -node=node6

View node1 log docker logs node1 The following information is added successfully. You can check the cluster status again

 2018/03/21 02:56:21 [INFO] serf: EventMemberJoin: node6.dc1 172.26.0.6
2018/03/21 02:56:21 [INFO] consul: Handled member-join event for server "node6.dc1" in area "wan"
2018/03/21 02:56:21 [INFO] serf: EventMemberJoin: node6 172.26.0.6
2018/03/21 02:56:21 [INFO] consul: Adding LAN server node6 (Addr: tcp/172.26.0.6:8300) (DC: dc1)

6. Accident node

If node1 is stopped, a node accident will occur, and other nodes will re elect a new leader

 docker stop node1

Look at the other log nodes docker logs node2 , log printing, heartbeat check node1 IP timeout, then start the election, node6 is elected as a new leader.

 Heartbeat timeout from "172.26.0.2:8300" reached, starting election
consul: New leader elected: node6

end

Using docker to deploy tests is really convenient.

Responses
  1. wwaf

    Homeboy benefits: https://6wll.com

    Reply