Connection refused in cluster configuration

I am using elasticsearch and have outgrown one server.
Therefore, I would like to create a cluster configuration of two elasticsearch servers with the following manual.

I have deployed elasticsearch on two servers, but I get connection refused.
I do not know the cause of this problem. Please give me some advice.

  • elasticsearch.yml

    [root@ELSTEST-01 ~]# vi /etc/elasticsearch/elasticsearch.yml
    ... snip ...
    cluster.name: mycluster
    node.name: elasticserver1
    network.host: XXX.XXX.XXX.001
    discovery.seed_hosts:
      - "XXX.XXX.XXX.001"
      - "XXX.XXX.XXX.002"
    cluster.initial_master_nodes:
      - "XXX.XXX.XXX.001"
      - "XXX.XXX.XXX.002"
    ... snip ...
    
    [root@ELSTEST-02 ~]# vi /etc/elasticsearch/elasticsearch.yml
    ... snip ...
    cluster.name: mycluster
    node.name: elasticserver2
    network.host: XXX.XXX.XXX.002
    discovery.seed_hosts:
      - "XXX.XXX.XXX.001"
      - "XXX.XXX.XXX.002"
    cluster.initial_master_nodes:
      - "XXX.XXX.XXX.001"
      - "XXX.XXX.XXX.002"
    ... snip ...
    
  • mycluster.log (<- connection refused)

    [root@ELSTEST-02 sysconfig]# tail -n 20 /var/log/elasticsearch/mycluster.log
    ... snip ...
    [2022-07-11T15:54:11,688][WARN ][o.e.c.c.ClusterFormationFailureHelper] [elasticserver2] master not discovered yet, this node has not previously joined a bootstrapped cluster, and this node must discover master-eligible nodes [XXX.XXX.XXX.001, XXX.XXX.XXX.002] to bootstrap a cluster: have discovered [{elasticserver2}{fcux0tenQhSC-tuDyJRz_w}{PsNwBO0PSYiKsx7TLisrvg}{elasticserver2}{ELSTEST-02}{127.0.0.1:9300}{cdfhilmrstw}]; discovery will continue using [XXX.XXX.XXX.001:9300, XXX.XXX.XXX.002:9300] from hosts providers and [{elasticserver2}{fcux0tenQhSC-tuDyJRz_w}{PsNwBO0PSYiKsx7TLisrvg}{elasticserver2}{ELSTEST-02}{127.0.0.1:9300}{cdfhilmrstw}] from last-known cluster state; node term 0, last-accepted version 0 in term 0
    [2022-07-11T15:54:12,440][WARN ][o.e.d.PeerFinder         ] [elasticserver2] address [XXX.XXX.XXX.001:9300], node [null], requesting [false] discovery result: [][XXX.XXX.XXX.001:9300] connect_exception: Connection refused: /XXX.XXX.XXX.001:9300: Connection refused
    [2022-07-11T15:54:12,440][WARN ][o.e.d.PeerFinder         ] [elasticserver2] address [XXX.XXX.XXX.002:9300], node [null], requesting [false] discovery result: [][XXX.XXX.XXX.002:9300] connect_exception: Connection refused: /XXX.XXX.XXX.002:9300: Connection refused
    ... snip ...
    
  • lsof

    [root@ELSTEST-01 ~]# lsof -i:9300
    COMMAND   PID          USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
    java    19757 elasticsearch  371u  IPv4 4946348      0t0  TCP ELSTEST-01:vrace (LISTEN)
    
    [root@ELSTEST-02 ~]# lsof -i:9300
    COMMAND  PID          USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
    java    7590 elasticsearch  371u  IPv4 1017002      0t0  TCP ELSTEST-02:vrace (LISTEN)
    

Please comment if you need any other information.

I found the following article, which I hope will be of interest to you

Perhaps it is because node.name and cluster.initial_master_nodes do not match exactly?

However, I lined up the cluster.initial_master_nodes with what I specified in node.name, but it didn't work.

If I don't specify node.name, the server name is set by default.
I removed the node.name.

What was also very difficult was the need to remove the old node information.
I am sure the following article will help you with that.

If you keep getting an error after starting Elasticsearch, deleting /var/lib/elasticsearch/nodes and restarting it seems to work.

I was able to configure my cluster with this response, but if you have any advice, please comment.