Article Directory
Environmental preparation
Node name | ip address |
---|---|
consul-s1 | 192.168.130.20 |
consul-s2 | 192.168.130.19 |
consul-s3 | 192.168.130.21 |
consul-c1 | 192.168.130.21 |
3 servers and 1 client
Install docker
slightly
Stand-alone
Create a directory
mkdir -p /root/consul_sg/conf
mkdir -p /root/consul_sg/data
start up
docker run -d --net=host --name consul-s1 \
-v /root/consul_sg/data:/consul/data \
-v /root/consul_sg/conf:/consul/config \
docker.io/consul:1.5.0 consul agent -server \
-bind=192.168.130.20 \
-client 0.0.0.0 \
-data-dir /consul/data \
-config-dir /consul/config \
-ui
Cluster
Create a directory
Create configuration directory and data directory (consul-s1\consul-s2\consul-s3 nodes are executed)
mkdir -p /root/consul/conf
mkdir -p /root/consul/data
Start server
consul-s1
docker run -d --net=host --name consul-s1 \
-v /root/consul/data:/consul/data \
-v /root/consul/conf:/consul/config \
docker.io/consul:1.5.0 consul agent -server \
-bind=192.168.130.20 \
-client 0.0.0.0 \
-bootstrap-expect=2 \
-data-dir /consul/data \
-config-dir /consul/config \
-ui
consul-s2
docker run -d --net=host --name consul-s2 \
-v /root/consul/data:/consul/data \
-v /root/consul/conf:/consul/config \
docker.io/consul:1.5.0 consul agent -server \
-bind=192.168.130.19 \
-join=192.168.130.20 \
-client 0.0.0.0 \
-bootstrap-expect=2 \
-data-dir /consul/data \
-config-dir /consul/config \
-ui
consul-s3
docker run -d --net=host --name consul-s3 \
-v /root/consul/data:/consul/data \
-v /root/consul/conf:/consul/config \
docker.io/consul:1.5.0 consul agent -server \
-bind=192.168.130.21 \
-join=192.168.130.20 \
-client 0.0.0.0 \
-bootstrap-expect=2 \
-data-dir /consul/data \
-config-dir /consul/config \
-ui
Start client
Enter consul-c1 to
create a data and configuration directory
mkdir -p /root/consul_client/data
mkdir -p /root/consul_client/conf
Since it shares a machine with the server, in order not to conflict with the port, modify the default listening
cd /root/consul_client/conf
vi basic.json
The content is as follows
{
"ports": {
"http":18501,
"dns":18601,
"serf_lan":18301,
"serf_wan":18302,
"server":18300
}
}
Start client1
docker rm -f consul-c1
docker run -d --net=host --name consul-c1 \
-v /root/consul_client/data:/consul/data \
-v /root/consul_client/conf:/consul/config \
docker.io/consul:1.5.0 consul agent \
-node kont004ecs \
-bind=192.168.130.21 \
-data-dir /consul/data \
-config-dir /consul/config \
-join 192.168.130.20:8301
Check cluster status
Enter the server node to view the cluster status
docker exec consul-s1 consul members
Node Address Status Type Build Protocol DC Segment
kont001ecs 192.168.130.20:8301 alive server 1.5.0 2 dc1 <all>
kont002ecs 192.168.130.19:8301 alive server 1.5.0 2 dc1 <all>
kont003ecs 192.168.130.21:8301 alive server 1.5.0 2 dc1 <all>
kont004ecs 192.168.130.21:18301 alive client 1.5.0 2 dc1 <default>
You can also open the browser to view
http://192.168.130.20:8500/ui/dc1/nodes