简体   繁体   中英

Can't Connect to Elasticsearch (through Curl)

I've recently installed Elasticsearch and everything was working well for the first few days, but somehow today it stopped working

When I start the service, it claims to be fine...

sudo /etc/init.d/elasticsearch start
* Starting Elasticsearch Server
...done.

But then I get
curl -GET http://127.0.0.1:9200
curl: (7) couldn't connect to host

Looking at the elasticsearch logs:

[WARN ][bootstrap                ] jvm uses the client vm, make sure to run `java` with the server vm for best performance by adding `-server` to the command line

Looks like there is a warning regarding the Java VM; could that be the problem? What else should I try/look at?

1) Check what's the status of your port 9200, with lsof command in linux.

In my case following is the result when elasticsearch is started.

prayag@prayag:~$ sudo lsof -i TCP | grep 9200 
chrome  2639 praayg   84u  IPv4 116310      0t0  TCP prayag.local:58989->10.0.4.70:9200 (ESTABLISHED)
chrome  2639 prayag   99u  IPv4 116313      0t0  TCP prayag.local:58990->10.0.4.70:9200 (ESTABLISHED)
java    7634 prayag  141u  IPv6 130960      0t0  TCP *:9200 (LISTEN)

elasticsearch is not a service to me, otherwise to find the port es is running; on I could have checked,

$ sudo lsof -iTCP -sTCP:LISTEN | grep elasticsearch

2) check the elasticsearch endpoint

$ curl -IGET http://localhost:9200
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 327
  • -IGET is equivalent to --head that returns http response headers only.

  • response 200 means elasticsearch endpoint is responding properly.

curl -GET http://127.0.0.1:9200 is the wrong command.

Try curl -XGET http://127.0.0.1:9200 . It should return the short info about your running local node and status 200. If that doesn't work then something else must be wrong.

Anyway, I'd try the command:

curl -XGET http://localhost:9200

Pay attention to memory allocation and usage. In case you let it use unlimited memory it might crash when you least suspect. Here is a tutorial on Elasticseach 5 and Kibana in case anyone else runs into this issue. https://medium.com/@adnanxteam/how-to-install-elasticsearch-5-and-kibana-on-homestead-vagrant-60ea757ff8c7

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM