2

I have installed elastic 2.2 on an Ubuntu 14.04. I left the default initial settings of elastic and the elastic instance was reachable form this system at localhost:9200.

Now when I tried via a different system using the IP/DNS name of the server as:

curl -XGET "http://<IP_ADDRESS_UBUNTU_SERVER>:9200"

I get an error as :

Failed to connect to <IP_ADDRESS_UBUNTU_SERVER> port 9200: Connection refused

I tried changing few parameters in elasticsearch.yml file and set it as:

network.host: 0.0.0.0
http.port: 9200

but this did not solve the issue. I set get the same error as connection refused. In-fact setting the above parameters and trying to access from the server using localhost:9200 also gave a connection timed-out error.

Now what is the configuration, I need to set so that this elastic instance is accessible from outside?

EDIT: I tried to set the IP Address of the Ubuntu server as network.host, but I see the following errors in the log files:

BindTransportException[Failed to bind to [9300-9400]]; nested: ChannelException[Failed to bind to: /10.173.1.176:9400]; nested: BindException[Cannot assign requested address];
        at org.elasticsearch.transport.netty.NettyTransport.bindToPort(NettyTransport.java:477)
        at org.elasticsearch.transport.netty.NettyTransport.bindServerBootstrap(NettyTransport.java:439)
        at org.elasticsearch.transport.netty.NettyTransport.doStart(NettyTransport.java:320)
        at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:68)
        at org.elasticsearch.transport.TransportService.doStart(TransportService.java:170)
        at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:68)
        at org.elasticsearch.node.Node.start(Node.java:252)
        at org.elasticsearch.bootstrap.Bootstrap.start(Bootstrap.java:221)
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:287)
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
Caused by: org.jboss.netty.channel.ChannelException: Failed to bind to: /10.173.1.176:9400
        at org.jboss.netty.bootstrap.ServerBootstrap.bind(ServerBootstrap.java:272)
        at org.elasticsearch.transport.netty.NettyTransport$1.onPortNumber(NettyTransport.java:459)
        at org.elasticsearch.common.transport.PortsRange.iterate(PortsRange.java:69)
        at org.elasticsearch.transport.netty.NettyTransport.bindToPort(NettyTransport.java:455)
        ... 9 more
Caused by: java.net.BindException: Cannot assign requested address
        at sun.nio.ch.Net.bind0(Native Method)
        at sun.nio.ch.Net.bind(Net.java:433)
        at sun.nio.ch.Net.bind(Net.java:425)
        at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
        at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
        at org.jboss.netty.channel.socket.nio.NioServerBoss$RegisterTask.run(NioServerBoss.java:193)
        at org.jboss.netty.channel.socket.nio.AbstractNioSelector.processTaskQueue(AbstractNioSelector.java:391)
        at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:315)
        at org.jboss.netty.channel.socket.nio.NioServerBoss.run(NioServerBoss.java:42)
        at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
        at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
Kiran
  • 203
  • 2
  • 3
  • 13
  • 1
    Try `network.host: ` as long as it is a public IP address it will work. – Val Mar 12 '16 at 16:27
  • btw, to rule out if there is any issue with my server , I hosted a simple page using python server on some random port. I was able to access this page from outside my server with the specified port. So I think this might be an issue with the elastic configurations – Kiran Mar 12 '16 at 16:28
  • Yes, as of ES 2.0, the server will only bind to localhost by default, so you have to explicitly tell it to bind to a public IP address in order to access it from the outside. – Val Mar 12 '16 at 16:30
  • @Val: I tried this. The IP address is accessible only from my office network. And all my tests are within this network. Giving the network.host as this IP address resulted in the same issue of refused connection... – Kiran Mar 12 '16 at 16:30
  • On setting the network.host to IP address, I see the log files shows some errors: :BindTransportException[Failed to bind to [9300-9400]]; nested: ChannelException[Failed to bind to: /10.173.1.176:9400]; nested: BindException[Cannot assign requested address]; .... Caused by: java.net.BindException: Cannot assign requested address at sun.nio.ch.Net.bind0(Native Method) ... – Kiran Mar 12 '16 at 16:37
  • Can you update your question with those logs, please? – Val Mar 12 '16 at 16:38
  • Updated with the log info – Kiran Mar 13 '16 at 17:18
  • maybe this will help: http://stackoverflow.com/questions/30611516/java-net-bindexception-cannot-assign-requested-address – daphshez Mar 13 '16 at 17:43
  • @Daphna: Sorry, it does not help – Kiran Mar 14 '16 at 13:52

2 Answers2

7

This was caused due to an error in the config file. I did not adhere to the YAML guidelines and was blindly following the elastic help doc..

The network and the port has to be specified in the YML format as below:

network:
  host: 0.0.0.0
http:
  port: 9200

After this restart the elastic service. If something goes wrong, refer to elastic log files and check if the instance is bound to the above IP and port 9200. You can also check the listening IP/port (netstat -l -n) . There has to be an entry like:

tcp 0 0 0.0.0.0:9200 0.0.0.0:* LISTEN 

Hope this helps and happy searching..

Kiran
  • 203
  • 2
  • 3
  • 13
  • We can specify our IP address as well, but it should be correct IP of your system, sometimes wrong IP also creates the above Exception. It happened with me. – Pratiksha Sharma Aug 03 '17 at 09:42
0

In addition to getting things right in the config.yml, if you're writing your own unit file, you will need to pass the boot checks by setting some settings in the unit file (not just in sysctl.conf). So in /lib/systemd/system/elasticsearch.service

Make sure you have these settings in the indicating sections:

[Unit]
LimitMEMLOCK=infinity

[Service]
LimitNOFILE=65536
labyrinth
  • 13,397
  • 7
  • 35
  • 44