docker cluster installation consul

1.docker mirrored pull consul

 docker pull consul 

2.consul arguments detailed

  • -net = host docker parameters, such that the container over the docker isolation net namespace, eliminating the step of manually specify the port mapping
  • -server consul to support the operation of the server or client mode, server is the core service discovery module, client is mainly used to forward requests
  • -advertise notification address for us to change the address advertised to other nodes in the cluster. By default, -bind address is advertised.
  • -retry-join node address designated consul to be added, after an unsuccessful retries, a different address can be specified multiple times
  • -client Consul bind the address of the client interfaces, including HTTP and DNS server. By default, this is "127.0.0.1", allowing only loopback connection.
  • Address -bind internal cluster communication binding. This is the IP address of all other nodes in the cluster should be able to access. By default, this is "0.0.0.0", to address all the nodes in the cluster must be reachable
  • -bootstrap-expect this flag is expected to provide the number of servers in the data center. Consistent with other servers should not provide this value, or the value must focus on the population. After you specify, Consul will wait a specified number of servers available, and then start the cluster. Allow automatic election leader, but can not be used with conventional -bootstrap mark, you need to run in server mode.
  • -data-dir This flag provides a data storage directory for the agent status. This is required for all agents. The directory when you restart should be long-lasting. This is especially important for the agents running in server mode because they must be able to maintain cluster state. In addition, the directory must support the use of file system locking, which means that certain types of loaded folders (such as VirtualBox shared folder) may not be appropriate
  • -node name of this node in the cluster, which must be unique in the cluster, the default is the host name of the node.
  • -config-dir specify the configuration file when the file has .json the end of this directory will be loaded
  • -enable-script-checks to check whether the service is active, similar to the open heart
  • -datacenter data center name. If not provided, the default is "dc1". Consul has first-class support for multiple data centers, but it depends on the correct configuration. Nodes within the same data center should be located in a single LAN.
  • -ui - Enable the built-in Web UI HTTP server and the required route. This eliminates the Consul Web UI and binary files separate maintenance needs.
  • -join designated ip, added to an existing cluster

3. Use the consul

1. Start the first node, called consul1

 docker run --name consul1 -d -p 8500:8500 -p 8300:8300 -p 8301:8301 -p 8302:8302 -p 8600:8600 consul agent -server -bootstrap-expect 2 -ui -bind=0.0.0.0 -client=0.0.0.0 

Detailed port
  • 8500: http port for http interface and the web ui access;
  • 8300: between server rpc port, the same data center consul server through the communication port
  • 8301: serf lan port, the same data center consul client communication through the port; gossip for processing the current communication in the LAN datacenter
  • 8302: serf wan ports, different data centers consul server communication through the port; agent Server using the process of communication with other datacenter Gossip;
  • 8600: dns port for the registered service discovery;

2. Check the container ip address

View consul1 ip address  docker inspect --format='{{.NetworkSettings.IPAddress}}' consul1

# 输出172.17.0.5

3.启动第二个consul服务(端口8501):consul2, 并加入consul1(使用join命令)

 docker run --name consul2 -d -p 8501:8500 consul agent -server -ui -bind=0.0.0.0 -client=0.0.0.0 -join 172.17.0.5  

4.启动第三个consul服务(端口8502):consul3, 并加入consul1(使用join命令)

 docker run --name consul3 -d -p 8502:8500 consul agent -server -ui -bind=0.0.0.0 -client=0.0.0.0 -join 172.17.0.5  

5.查看consul集群信息

 docker exec -it consul1 consul members 

// 可以看到集群里的三个节点
Node          Address          Status  Type    Build  Protocol  DC   Segment
618e9f617509  172.17.0.5:8301  alive   server  1.6.2  2         dc1  <all>
6ba34e2feb66  172.17.0.6:8301  alive   server  1.6.2  2         dc1  <all>
8cba36da0384  172.17.0.7:8301  alive   server  1.6.2  2         dc1  <all>

6.通过访问8500/8501/8502端口查看web界面

我是在阿里云上,记得开放安全端口

http://localhost:8500

Guess you like

Origin www.cnblogs.com/zhouqi666/p/11894670.html