title: Configuring Elasticsearch 7 cluster
body: <p>I have three server and I have installed elasticsearch on all of them.</p>
  
  <p>In the elasticsearch.yml I have the following config:</p>
  
  <p><strong>first server: 172.31.1.1</strong></p>
  
  <pre><code># /etc/elasticsearch/elasticsearch.yml
  cluster.name: es-cluster
  node.name: es-1
  network.host: 172.31.1.1
  http.port: 9200
  network.host:
  discovery.seed_hosts: ["172.31.1.1", "172.31.1.2", "172.31.1.3"]
  cluster.initial_master_nodes:["es-1", "es-2", "es-3"]
  
  gateway.recover_after_nodes: 2
  gateway.expected_nodes: 3
  path.data: /var/lib/elasticsearch
  path.logs: /var/log/elasticsearch
  # some more default values
  </code></pre>
  
  <p><strong>second server: 172.31.1.2</strong></p>
  
  <pre><code>node.name: es-2
  network.host: 172.31.1.2
  # everything else same as first server
  </code></pre>
  
  <p><strong>second server: 172.31.1.3</strong></p>
  
  <pre><code>node.name: es-3
  network.host: 172.31.1.3
  # everything else same as first server
  </code></pre>
  
  <p>Now when I run: curl <a href="http://es-1:9200/_cluster/stats" rel="nofollow noreferrer">http://es-1:9200/_cluster/stats</a></p>
  
  <p>I notice that the cluster size is 1. if I run the same curl command on a different server, again the cluster size is 1 and the cluster_name is the same, but cluster_uuid is different...</p>
  
  <p>It seems that nodes are not able to connect to each other...</p>
  
  <hr>
  
  <p>I am using Ubuntu server, for node name I edited /etc/hostname and changed the host name to
  es-1 and used the same name in elasticsearch.yml... but it seems that cluster nodes are not able to communicate with one another...</p>
  
  <hr>
  
  <h2>Update 1</h2>
  
  <pre><code>curl http://es-1:9200/_cat/health
  prod-es-cluster red 1 1 0 0 0 0 0 0 - NaN%
  
  curl http://es-1/:9200/_cat/nodes
  172.31.1.1 8 38 1 0.03 0.03 0.00 mdi * ip-172-31-1-1
  </code></pre>
  
  <p>I just check the log and it's strange... </p>
  
  <pre><code>sudo cat /var/log/elasticsearch/elasticsearch.log
  [INFO ][o.e.n.Node               ] [es-1] stopping ...
  [INFO ][o.e.x.w.WatcherService   ] [es-1] stopping watch service, reason [shutdown initiated]
  [INFO ][o.e.x.m.p.l.CppLogMessageHandler] [es-1] [controller/19159] [Main.cc@148] Ml controller exiting
  [INFO ][o.e.x.m.p.NativeController] [es-1] Native controller process has stopped - no new native processes can be started
  [INFO ][o.e.n.Node               ] [es-1] stopped
  [INFO ][o.e.n.Node               ] [es-1] closing ...
  [INFO ][o.e.n.Node               ] [es-1] closed
  </code></pre>
  
  <p>That is all written to the log file... after restarting Elasticsearch nothing new gets added to the log file... it feels like I am either reading the wrong log file or I have put the configuration in the wrong .yml file</p>
  
  <h2>Update 2</h2>
  
  <p>This is how I start the service:</p>
  
  <pre><code>sudo /bin/systemctl enable elasticsearch.service
  </code></pre>
  
  <h2>Update 3</h2>
  
  <p>As pointed out by @hamidbayat, I think there is permission issues. Only super user have permission to /var/lib/elasticsearch</p>
  
  <p>If I try to run elastic search as my ubuntu user I will get this error:</p>
  
  <pre><code>ubuntu@my-ip:~$ /usr/share/elasticsearch/bin/elasticsearch
  /usr/share/elasticsearch/bin/elasticsearch-env: line 73: 
  /etc/default/elasticsearch: Permission denied
  </code></pre>
  
  <p>If I try to run it as root, I will get this error:</p>
  
  <pre><code>ubuntu@myip:~$ sudo /usr/share/elasticsearch/bin/elasticsearch
  OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
  [data][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [es-1] uncaught exception in thread [main]
  org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
          at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:163) ~[elasticsearch-7.1.0.jar:7.1.0]
          at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.1.0.jar:7.1.0]
          at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.1.0.jar:7.1.0]
          at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-7.1.0.jar:7.1.0]
          at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.1.0.jar:7.1.0]
          at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.1.0.jar:7.1.0]
          at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.1.0.jar:7.1.0]
  Caused by: java.lang.RuntimeException: can not run elasticsearch as root
          at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:102) ~[elasticsearch-7.1.0.jar:7.1.0]
          at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:169) ~[elasticsearch-7.1.0.jar:7.1.0]
          at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:325) ~[elasticsearch-7.1.0.jar:7.1.0]
          at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.1.0.jar:7.1.0]
          ... 6 more
  </code></pre>