Consul use record

Disclaimer: This article is a blogger original article, reproduced, please attach Bowen link! https://blog.csdn.net/Little_fxc/article/details/90446410

1. consul cluster model

consul agent -server -data-dir=./data/ -node=s1 -bind=192.168.217.86 -ui -rejoin -client=0.0.0.0 -bootstrap-expect=1 -ui

Parameter Description:

  • -server information indicates that the identity of the server is started, remove this parameter indicates the clientmode
  • -bind indicate which bind to ip (some servers will bind multiple network cards, you can force a specified ip bound by bind parameters), generally the local IP
  • -client specify client access ip (consul has a wealth of api interface here refers to the client browser or caller), 0.0.0.0 not represent a client ip
  • -bootstrap-expect = 3 represents the lowest cluster server nodes 3, below this value will not work properly (Note: similar zookeeper, as is usually an odd number of clusters to facilitate the elections, consul uses a raft algorithm)
  • -data-dir indicates designation data storage (persistent) directory (which must exist)
  • -node represents the name of the node displayed in the web ui

After a successful start, do not close the terminal window, you can in the browser, the next visit, similar http://192.168.212.73:8500/, normal, normal can open the web interface.

In order to prevent the terminal is turned off, consul quit, just be on the command, add a little something like this:nohup xxx > /dev/null 2>&1 &

1.1. Command line build consul cluster

Server 1:

consul agent -server -bootstrap-expect=2 -data-dir=./data/ -bind=192.168.217.134 -client=0.0.0.0 -node=s1 -ui

2 server:

consul agent -server -bootstrap-expect=2 -data-dir=./data/ -bind=192.168.217.72 -client=0.0.0.0 -join 192.168.217.134 -node=s2 -ui

3 server:

consul agent -server -bootstrap-expect=2 -data-dir=./data/ -bind=192.168.217.86 -client=0.0.0.0 -join 192.168.217.134 -node=s3 -ui

Client 1:

consul agent -data-dir=./data/ -bind=192.168.217.87 -client=0.0.0.0 -join 192.168.217.134 -node=c1 -ui

1.2 Establish consul way cluster configuration file

Here Insert Picture Description

Example:

{
  /* 表示server集群最低节点数 */
  "bootstrap_expect": 2,
  /* 表示该节点绑定的地址, 默认0.0.0.0 */
  "bind_addr": "192.168.217.86",
  /* 访问该节点的地址, 默认127.0.0.1*/
  "client_addr": "0.0.0.0",
  /* 访问该节点的数据中心*/
  "datacenter": "data-center-1",
  /* 必须, 数据保存的地址*/
  "data_dir": "/home/awifi/consul-server/data",
  "addresses": {
    /* 表示该节点绑定的dns地址, 以空格分隔的要绑定的地址列表*/
    "dns": "192.168.217.86",
    /* 表示该节点绑定的http地址, 以空格分隔的要绑定的地址列表*/
    "http": "192.168.217.86 127.0.0.1"
  },
  /* 节点名,必须*/
  "node_name": "server:192.168.212.73:8500",
  "rejoin_after_leave": true,
  /* 表示该节点类型是server*/
  "server": true,
  /* 允许在第一次尝试失败时重试连接 */
"retry_join": [
        "192.168.217.72",
        "192.168.217.134"
    ],
  /* 表示开启web界面*/
  "ui": true
}

Is then executed on another machine
./consul join 192.168.217.86
or may be added to configure

{
  "start_join":[],
  "retry_join":[]
}

start_join: Equivalent to the command line parameter -join: indicates the start cluster address added
retry_join: equivalent to the command line parameters -retry-join: retry is connected at the first attempt fails, the list may include IPv4, IPv6, or DNS address.

1.2.1. Why http address to bind 127.0.0.1?

If you do not bind 127.0.0.1, the command will not be used except ./consul agent on that server,

For example:
the formation of cluster model of core commands: consul join 192.168.217.86
graceful logoff node command:consul leave
Here Insert Picture Description

2. Check the cluster status

consul operator raft list-peers

operation result:

View cluster status

Operating results can be seen in the red box part of the cluster model who is leader

Guess you like

Origin blog.csdn.net/Little_fxc/article/details/90446410