consul agent Common options for commands are as follows :
-data-dir
effect : Appoint agent A directory of stored data
This is all. agent It's all necessary
about server Especially important , Because they have to persist the state of the cluster
-config-dir
effect : Appoint service The location of the configuration file and check definition for
It is usually designated as ” A certain path /consul.d”( Usually ,.d Represents the directory where a series of configuration files are stored )
-config-file
effect : Specify a profile to load
This option can be configured multiple times , And then configure multiple configuration files ( The back one will merge the front one , The same value covers )
-dev
effect : Create a development environment server node
Under this parameter configuration , There will be no persistence operations , That is, no data is written to the disk
This pattern cannot be used in production environments ( Because the second one )
-bootstrap-expect
effect : Order notification consul server We are now ready to join server Number of nodes , This parameter is used to delay the start of log replication until we specify the number of server Start after the node successfully joins .
-node
effect : Specify the name of the node in the cluster
The name must be unique in the cluster ( The default is machine host)
recommend : Direct use of machine IP
-bind
effect : Specify the IP Address
Sometimes no binding is specified IP, Will be submitted to the Failed to get advertise address: Multiple private IPs found. Please configure one. It's abnormal
-server
effect : Specify the node as server
Every data center (DC) Of server The number recommended is at least 1, At most 5
be-all server All use raft Consistency algorithm to ensure the consistency and linearization of transactions , The transaction modifies the state of the cluster , And the state of the cluster is saved in each server To ensure availability
server Also with other DC The facade of interaction (gateway)
-client
effect : Specify the node as client, Specify the binding address of the client interface , Include :HTTP、DNS、RPC
The default is 127.0.0.1, Only loopback interfaces are allowed to access
If not specified as -server, In fact, that is -client
-join
effect : Add nodes to the cluster
-datacenter( The old version is called -dc,-dc It's invalid )
effect : Specify which data center the machine will join
Example 1: Command parameter mode execution
1
consul agent -data-dir /tmp/node2 -node=node2 -bind=192.168.11.145 -datacenter=dc1 -ui -client=192.168.11.145
Example 2: Profile mode execution
Prepare a profile , Any name , for example consul.json, The contents are as follows :
start-up node1 On the machine Consul(node1 Executed on machine ):
1
consul agent -data-dir /tmp/node1 -node=node1 -bind=192.168.11.144 -datacenter=dc1 -ui
start-up node2 On the machine Consul(node2 Executed on machine ):
1
consul agent -data-dir /tmp/node2 -node=node2 -bind=192.168.11.145 -datacenter=dc1 -ui -client=192.168.11.145
take node1 Node join to node0 On (node1 Executed on machine ):
1
consul join 192.168.11.143
take node2 Node join to node0 On (node2 Executed on machine ):
1
consul join -rpc-addr=192.168.11.145:8400 192.168.11.143
It's a simple one Consul The cluster is set up , stay node1 View the current cluster node on :
1
consul members -rpc-addr=192.168.11.143:8400
give the result as follows :
1 2 3 4
Node Address Status Type Build Protocol DC node0 192.168.11.143:8301 alive server 0.7.0 2 dc1 node1 192.168.11.144:8301 alive client 0.7.0 2 dc1 node2 192.168.11.145:8301 alive client 0.7.0 2 dc1
It indicates that the cluster has been successfully built .
Let's analyze , Why the 5 And the first step 6 Step needs to add -rpc-addr Options , And the first 4 Step does not need to add any options ? as a result of -client The binding address of the client interface is specified , Include :HTTP、DNS、RPC, and consul join 、consul members It's all through RPC And Consul The interaction of .
Access test
Above , We've added... To all three nodes -ui Parameters start the built-in interface . We can go through :http://192.168.11.143:8500/ui/ perhaps http://192.168.11.145:8500/ui/ Visit , It can also be in node1 Machine pass http://127.0.0.1:8500/ui/ Visit , as a result of node1 Remote access is not turned on , The results of the three access methods are the same .