The services on each node inconsistency

I installed a consul cluster, 3 nodes. At first, this cluster was good worked. The leader was elected yet.

  node1
    ./consul agent -server -bootstrap -syslog \
        -ui \
        -data-dir=/opt/consul/data \
        -config-dir=/opt/consul/conf \
        -pid-file=/opt/consul/run/consul.pid \
        -client=0.0.0.0 \
        -bind=node1 \
        -node=consul-server01 -disable-host-node-id -join=node1

node2
    ./consul agent -server -syslog \
        -ui \
        -data-dir=/opt/consul/data \
        -config-dir=/opt/consul/conf \
        -pid-file=/opt/consul/run/consul.pid \
        -client=0.0.0.0 \
        -bind=node2 \
        -node=consul-server02 -disable-host-node-id -join=node1 

    node3	
    ./consul agent -server -syslog \
        -ui \
        -data-dir=/opt/consul/data \
        -config-dir=/opt/consul/conf \
        -pid-file=/opt/consul/run/consul.pid \
        -client=0.0.0.0 \
        -bind=node3 \
        -node=consul-server03 -disable-host-node-id  -join=node1 

And then, I registered three services(A,B,C) via HTTP API.
registered the A service via HTTP API of node1
(curl -X PUT -d '{"id": "livtix0atcf01","name": "Docker-service1","address": "livtix0atcf01","port":9100,"tags": ["node_exporter"]}' http://node1:8500/v1/agent/service/register )
registered the B service via HTTP API of node2
(curl -X PUT -d '{"id": "livtix0atcf02","name": "Docker-service2","address": "livtix0atcf02","port":9100,"tags": ["node_exporter"]}' http://node2:8500/v1/agent/service/register )
registered the C service via HTTP API of node3
(curl -X PUT -d '{"id": "livtix0atcf03","name": "Docker-service3","address": "livtix0atcf03","port":9100,"tags": ["node_exporter"]}' http://node3:8500/v1/agent/service/register )

I expect to have these three services at each point to high availability. But it’s not, serviceA only exist on the node1, and serviceB only exist on the node2, serviceC only exist on the node3.

And then, when I stopped the node3, the serviceC doesn’t existed.

The state of each node is consistent.

**consul info command output: The raft part of each node is consistent **
image

I want to know what the problem is.
Thank you so much!

Should I register one service to all three nodes at the same time?

Hi @cycwll,

Consul is designed for services to be registered against the local agent running on the same host where the service is deployed. For example, if you have multiple copies of service A deployed across servers 1 - 3, then you would register each instance separately with its local Consul agent.

When consumers perform a service lookup over DNS (Find Services - DNS Interface | Consul by HashiCorp) or HTTP (/v1/health/service/:service?passing), they would receive a response with the list of healthy and available endpoints. If the instance of service A on server 2 becomes unavailable, then the catalog will not return it in the response, and will only return the healthy instances on server 1 and 3. See Register a Service with Consul Service Discovery | Consul - HashiCorp Learn for a bit more information on service registration and discovery.

I hope this helps. Let me know if you have any other questions.

1 Like

Thank you for your help!
And now I understand.

Hi blake,
I have a question yet.
Can I sync a service to node1 via copy the service file in services directory on node2?
Thank you so much!

Hi @cycwll,

Yes, you can copy the same service registration file into Consul’s configuration directory on the second host in order to register it on that server.

1 Like

Thank you for your help!