Utilice Docker para crear rápidamente un clúster de cónsul

Preparación ambiental

Nombre del nodo dirección IP
cónsul-s1 192.168.130.20
cónsul-s2 192.168.130.19
cónsul-s3 192.168.130.21
cónsul-c1 192.168.130.21

3 servidores y 1 cliente

Instalar ventana acoplable

levemente

Ser único

Crea un directorio

mkdir -p /root/consul_sg/conf
mkdir -p /root/consul_sg/data

puesta en marcha

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

Grupo

Crea un directorio

Crear directorio de configuración y directorio de datos (se ejecutan los nodos consul-s1 \ consul-s2 \ consul-s3)

mkdir -p /root/consul/conf

mkdir -p /root/consul/data

Iniciar servidor

cónsul-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

cónsul-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

cónsul-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

Iniciar cliente

Ingrese consul-c1 para
crear un directorio de datos y configuración

mkdir -p /root/consul_client/data
mkdir -p /root/consul_client/conf

Dado que comparte una máquina con el servidor, para no entrar en conflicto con el puerto, modifique la escucha predeterminada

cd /root/consul_client/conf
vi basic.json

El contenido es el siguiente

{
    
    

     "ports": {
    
    

        "http":18501,

        "dns":18601,

        "serf_lan":18301,

        "serf_wan":18302,

        "server":18300
    }
}

Iniciar cliente1

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

Verificar el estado del clúster

Ingrese al nodo del servidor para ver el estado del clúster

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>

También puede abrir el navegador para ver
http://192.168.130.20:8500/ui/dc1/nodes

Supongo que te gusta

Origin blog.csdn.net/kk3909/article/details/111938043
Recomendado
Clasificación