# Metricbeat failed to connect with elasticsearch

**URL:** <https://discuss.elastic.co/t/metricbeat-failed-to-connect-with-elasticsearch/188922>\
**Category:** Elasticsearch\
**Created:** [July 4, 2019, 1:54pm UTC](https://discuss.elastic.co/t/metricbeat-failed-to-connect-with-elasticsearch/188922 "2019-07-04T13:54:25Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![zmira\_meriem](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zmira_meriem/32/49360_2.png) [@zmira\_meriem](https://discuss.elastic.co/u/zmira_meriem)\
**Post date:** [July 4, 2019, 1:54pm UTC](https://discuss.elastic.co/t/metricbeat-failed-to-connect-with-elasticsearch/188922/1 "2019-07-04T13:54:25Z")

</div>

[root@scw-elated-franklin ~]# sudo metricbeat test output  
elasticsearch: [http://51.77](http://51.77).:9200...  
parse url... OK  
connection...  
parse host... OK  
dns lookup... OK  
addresses: 51.77..  
dial up... ERROR dial tcp 51.77.:9200: connect: connection refused

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [July 4, 2019, 2:42pm UTC](https://discuss.elastic.co/t/metricbeat-failed-to-connect-with-elasticsearch/188922/2 "2019-07-04T14:42:09Z")

</div>

Hi @zmira_meriem,

Did you check if you can connect to your 51.77... instance on the port 9200 from your scw-elated-franklin istance?

Look like it's a network problem. Can you share the result of a  
`curl -XGET 51.77....:9200`

if it's work it will return a json result with the elastic version information.

---

<div class="post-metadata">

**Author:** ![zmira\_meriem](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zmira_meriem/32/49360_2.png) [@zmira\_meriem](https://discuss.elastic.co/u/zmira_meriem)\
**Post date:** [July 4, 2019, 3:33pm UTC](https://discuss.elastic.co/t/metricbeat-failed-to-connect-with-elasticsearch/188922/3 "2019-07-04T15:33:24Z")

</div>

tnx for your reply @gabriel_tessier  
that result for this cmd:  
[root@scw-elated-franklin ~]# curl -XGET 51.77..:9200  
curl: (7) Failed connect to 51.77..:9200; Connection refused  
[root@scw-elated-franklin ~]#

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [July 4, 2019, 3:35pm UTC](https://discuss.elastic.co/t/metricbeat-failed-to-connect-with-elasticsearch/188922/4 "2019-07-04T15:35:37Z")

</div>

So it's a network problem need to check on your 51.77 server that elastic is correctly running and thre's no firewall blocking the access.

---

<div class="post-metadata">

**Author:** ![zmira\_meriem](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zmira_meriem/32/49360_2.png) [@zmira\_meriem](https://discuss.elastic.co/u/zmira_meriem)\
**Post date:** [July 4, 2019, 3:37pm UTC](https://discuss.elastic.co/t/metricbeat-failed-to-connect-with-elasticsearch/188922/5 "2019-07-04T15:37:50Z")

</div>

> [@gabriel\_tessier](#):
>
> 1.77

@gabriel_tessier elasticsearch is starting  
[root@vps705402 ~]# systemctl status elasticsearch  
● elasticsearch.service - Elasticsearch  
Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: disabled)  
Active: active (running) since jeu. 2019-07-04 16:27:23 CEST; 1h 9min ago  
Docs: [http://www.elastic.co](http://www.elastic.co)  
Main PID: 21492 (java)  
CGroup: /system.slice/elasticsearch.service  
├─21492 /usr/share/elasticsearch/jdk/bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative...  
└─21570 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86\_64/bin/controller

juil. 04 16:27:23 [vps705402.ovh.net](http://vps705402.ovh.net) systemd[1]: Stopped Elasticsearch.  
juil. 04 16:27:23 [vps705402.ovh.net](http://vps705402.ovh.net) systemd[1]: Started Elasticsearch.  
juil. 04 16:27:24 [vps705402.ovh.net](http://vps705402.ovh.net) elasticsearch[21492]: OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.  
[root@vps705402 ~]#

---

<div class="post-metadata">

**Author:** ![zmira\_meriem](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zmira_meriem/32/49360_2.png) [@zmira\_meriem](https://discuss.elastic.co/u/zmira_meriem)\
**Post date:** [July 4, 2019, 3:39pm UTC](https://discuss.elastic.co/t/metricbeat-failed-to-connect-with-elasticsearch/188922/6 "2019-07-04T15:39:25Z")

</div>

@gabriel_tessier

the netsat cmd show that:

[root@vps705402 ~]# netstat -ntlp  
Connexions Internet actives (seulement serveurs)  
Proto Recv-Q Send-Q Adresse locale Adresse distante Etat PID/Program name  
tcp 0 0 0.0.0.0:22 0.0.0.0:\* LISTEN 3416/sshd  
tcp 0 0 127.0.0.1:25 0.0.0.0:\* LISTEN 3361/master  
tcp 0 0 0.0.0.0:5601 0.0.0.0:\* LISTEN 21581/node  
tcp6 0 0 127.0.0.1:9200 :::\* LISTEN 21492/java  
tcp6 0 0 127.0.0.1:9300 :::\* LISTEN 21492/java  
tcp6 0 0 :::22 :::\* LISTEN 3416/sshd  
[root@vps705402 ~]#

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [July 4, 2019, 3:44pm UTC](https://discuss.elastic.co/t/metricbeat-failed-to-connect-with-elasticsearch/188922/7 "2019-07-04T15:44:58Z")

</div>

If elastic is running it's ok what about firewall rules?  
you can maybe get the list of your open port with `iptables -L`

---

<div class="post-metadata">

**Author:** ![zmira\_meriem](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zmira_meriem/32/49360_2.png) [@zmira\_meriem](https://discuss.elastic.co/u/zmira_meriem)\
**Post date:** [July 4, 2019, 3:51pm UTC](https://discuss.elastic.co/t/metricbeat-failed-to-connect-with-elasticsearch/188922/8 "2019-07-04T15:51:27Z")

</div>

@gabriel_tessier  
this is the open ports:

[root@vps705402 ~]# sudo firewall-cmd --list-ports  
9200/tcp 5601/tcp  
[root@vps705402 ~]#

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [July 4, 2019, 3:56pm UTC](https://discuss.elastic.co/t/metricbeat-failed-to-connect-with-elasticsearch/188922/9 "2019-07-04T15:56:17Z")

</div>

If the firewall allow you to connect but curl is not working my guess is that something else and it's sound like a hosting problem.  
As elastic is correctly running but you can't access it from the scw-elated-franklin instance.

You may have more chance to figure out the ovh network configuration on [developpez.net](http://developpez.net) forum. 😀

Bonne continuation.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 4, 2019, 5:37pm UTC](https://discuss.elastic.co/t/metricbeat-failed-to-connect-with-elasticsearch/188922/10 "2019-07-04T17:37:17Z")

</div>

It looks like your instance is configured to just bind to local host. Can you post your Elasticsearch config?

---

<div class="post-metadata">

**Author:** ![zmira\_meriem](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zmira_meriem/32/49360_2.png) [@zmira\_meriem](https://discuss.elastic.co/u/zmira_meriem)\
**Post date:** [July 5, 2019, 7:52am UTC](https://discuss.elastic.co/t/metricbeat-failed-to-connect-with-elasticsearch/188922/11 "2019-07-05T07:52:01Z")

</div>

@Christian_Dahlqvist thnx for u r reply  
this a elastic search configuration:

# Make sure that the heap size is set to about half the memory available

# on the system and that the owner of the process is allowed to use this

# limit.

# 

# Elasticsearch performs poorly when the system is swapping the memory.

# 

# ---------------------------------- Network -----------------------------------

# 

# Set the bind address to a specific IP (IPv4 or IPv6):

# 

network.host: localhost

# 

# Set a custom port for HTTP:

# 

http.port: 9200

# 

# For more information, consult the network module documentation.

# 

# --------------------------------- Discovery ---

---

<div class="post-metadata">

**Author:** ![zmira\_meriem](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zmira_meriem/32/49360_2.png) [@zmira\_meriem](https://discuss.elastic.co/u/zmira_meriem)\
**Post date:** [July 5, 2019, 8:34am UTC](https://discuss.elastic.co/t/metricbeat-failed-to-connect-with-elasticsearch/188922/12 "2019-07-05T08:34:36Z")

</div>

it is just listning to localhost

`Preformatted text`[root@vps705402 kibana]# netstat -anp|grep 9200  
tcp 0 0 127.0.0.1:49890 127.0.0.1:9200 ESTABLISHED 17398/node  
tcp 0 0 127.0.0.1:49912 127.0.0.1:9200 ESTABLISHED 17398/node  
tcp 0 0 127.0.0.1:49892 127.0.0.1:9200 ESTABLISHED 17398/node  
tcp 0 0 127.0.0.1:49918 127.0.0.1:9200 ESTABLISHED 17398/node  
tcp 0 0 127.0.0.1:49920 127.0.0.1:9200 ESTABLISHED 17398/node  
tcp 0 0 127.0.0.1:49922 127.0.0.1:9200 ESTABLISHED 17398/node  
tcp 0 0 127.0.0.1:49908 127.0.0.1:9200 ESTABLISHED 17398/node  
tcp 0 0 127.0.0.1:49886 127.0.0.1:9200 ESTABLISHED 17398/node  
tcp 0 0 127.0.0.1:49884 127.0.0.1:9200 ESTABLISHED 17398/node  
tcp 0 0 127.0.0.1:49928 127.0.0.1:9200 ESTABLISHED 17398/node  
tcp 0 0 127.0.0.1:49916 127.0.0.1:9200 ESTABLISHED 17398/node  
tcp 0 0 127.0.0.1:49914 127.0.0.1:9200 ESTABLISHED 17398/node  
tcp 0 0 127.0.0.1:49896 127.0.0.1:9200 ESTABLISHED 17398/node  
tcp 0 0 127.0.0.1:49910 127.0.0.1:9200 ESTABLISHED 17398/node  
tcp 0 0 127.0.0.1:49906 127.0.0.1:9200 ESTABLISHED 17398/node  
tcp 0 0 127.0.0.1:49926 127.0.0.1:9200 ESTABLISHED

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [July 5, 2019, 8:47am UTC](https://discuss.elastic.co/t/metricbeat-failed-to-connect-with-elasticsearch/188922/13 "2019-07-05T08:47:06Z")

</div>

Sorry I mess it @Christian_Dahlqvist found it !!

You need to set  
`network.host: [_eth0_, _local_]`

Also don't forget to restrict access to your elastic server only for the metricbeat instance.

---

<div class="post-metadata">

**Author:** ![zmira\_meriem](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zmira_meriem/32/49360_2.png) [@zmira\_meriem](https://discuss.elastic.co/u/zmira_meriem)\
**Post date:** [July 5, 2019, 9:16am UTC](https://discuss.elastic.co/t/metricbeat-failed-to-connect-with-elasticsearch/188922/14 "2019-07-05T09:16:14Z")

</div>

```
indent preformatted text by 4 spaces

```

@gabriel_tessier i change it like u say but the elasticsearch failed to starting

# Set the bind address to a specific IP (IPv4 or IPv6):

# 

network.host: `[_eth0_, _local_]`

# 

# Set a custom port for HTTP:

# 

http.port: 9200

# 

# For more information, consult the network module documentation.

# 

# --------------------------------- Discovery -------------------`Preformatted text`

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 5, 2019, 9:16am UTC](https://discuss.elastic.co/t/metricbeat-failed-to-connect-with-elasticsearch/188922/15 "2019-07-05T09:16:39Z")

</div>

Please format your code, logs or configuration files using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) and not the citation button. It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

This is the icon to use if you are not using markdown format:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/e/7e6e239431ec2d71cbf1beef741f2e93e7cc762c.jpg)

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.  
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.  
Please update your post.

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [July 5, 2019, 2:34pm UTC](https://discuss.elastic.co/t/metricbeat-failed-to-connect-with-elasticsearch/188922/17 "2019-07-05T14:34:07Z")

</div>

Sorry, I copy the value from my file as example you'd better to check the documentation for your elastic version.

as describe in the documentation you can use environment variable, you can try.  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/settings.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/settings.html)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 2, 2019, 2:34pm UTC](https://discuss.elastic.co/t/metricbeat-failed-to-connect-with-elasticsearch/188922/18 "2019-08-02T14:34:12Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
