BindTransportException when starting Elasticsearch server

I am trying to start my elasticsearch server by running bin/elasticsearch from my ES directory but I keep getting a bindtransport exception. What should I do?

 idea!
[2016-08-11 04:57:45,143][INFO ][node                     ] [my-elk1] version[2.3.3], pid[30342], build[218bdf1/2016-05-17T15:40:04Z]
[2016-08-11 04:57:45,143][INFO ][node                     ] [my-elk1] initializing ...
[2016-08-11 04:57:45,683][INFO ][plugins                  ] [my-elk1] modules [lang-groovy, reindex, lang-expression], plugins [], sites []
[2016-08-11 04:57:45,707][INFO ][env                      ] [my-elk1] using [1] data paths, mounts [[/ (/dev/xvda1)]], net usable_space [16.1gb], net total_space [49gb], spins? [no], types [ext4]
[2016-08-11 04:57:45,707][INFO ][env                      ] [my-elk1] heap size [990.7mb], compressed ordinary object pointers [true]
[2016-08-11 04:57:47,647][INFO ][node                     ] [my-elk1] initialized
[2016-08-11 04:57:47,648][INFO ][node                     ] [my-elk1] starting ...
Exception in thread "main" BindTransportException[Failed to bind to [9300-9400]]; nested: ChannelException[Failed to bind to: /192.168.0.1:9400]; nested: BindException[Cannot assign requested address];
Likely root cause: java.net.BindException: Cannot assign requested address
    ...

elasticsearch.yml

# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
# name that es uses to find other clusters to join
# when you turn on a node, it will find other nodes on the network to talk to
# if found, it will cluster. name determines if node will join or not.
cluster.name: elk1
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
# everytime you turn on a node, it will choose a marvel comic character
# node.name is just a name
node.name: my-elk1
#
# Add custom attributes to the node:
#
# node.rack: r1
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
# path.data: /path/to/data
#
# Path to log files:
#
# path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
# allows jvm to lock memory on startup to avoid swapping
bootstrap.mlockall: true
#
# Make sure that the `ES_HEAP_SIZE` environment variable 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):
#
# setting to control network traffic. only allows traffic from :<> so that
# external processes cannot access elasticsearch server
# network.host: 192.168.0.1
#
# Set a custom port for HTTP:
#
# http.port: 9200
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html>
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
# discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of nodes / 2 \
+ 1):
#
# discovery.zen.minimum_master_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery.html>
...(everthing commenteed)

Have you checked to make sure another process isn't using that port? Or another ES server that may accidentally be running in the background?

I've checked

sudo lsof -iTCP -sTCP:LISTEN | grep elasticsearch

to see if elasticsearch is even running but nothing comes up.

I also tried

/etc/init.d/elasticsearch status

but it says elasticsearch daed but pid file exists.

however if I run curl 'localhost:9200/_cat/indices?v'

health status index               pri rep docs.count docs.deleted store.size pri.store.size 
yellow open   logstash-2015.05.19   5   1          0            0       795b           795b 
yellow open   logstash-2016.08.12   5   1          2            0     30.6kb         30.6kb 
yellow open   megacorp              5   1          3            0     12.7kb         12.7kb 
yellow open   logstash-2015.05.18   5   1          0            0       795b   

is returned.

It is worth mentioning that when I start elasticsearch it consistently crashes after a few minutes with

Caught exception while handling client http traffic, closing connection [id: 0x09f530e6, /127.0.0.1:46638 :> /127.0.0.1:9200]
java.lang.IllegalArgumentException: empty text

Part of the problem may be that I am starting elasticsearch with

bin/elasticsearch -Des.insecure.allow.root=true -Des.network.host=127.0.0.1

because starting it with just bin/elaticsearch throws errors about BindTransportException but I posted a question about that earlier both here and on SO and no one responded.

You'll likely need to grep for java in that lsof command (at least, that's the case on my Mac). Try: sudo lsof -iTCP -sTCP:LISTEN | grep java

Or, check the specific ports:

lsof -n -iTCP:9200
lsof -n -iTCP:9300

You can check to see if there are any general processes running with: ps aux | grep elasticsearch

The bad http traffic likely means you have some other server or service running which is trying to talk to ES. Are you running any docker containers, or any other services that may interact with ES?

Also, dont do this :stuck_out_tongue:

lsof -n -iTCP:9200

COMMAND   PID USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
java    26962 root   41u  IPv4 3381397      0t0  TCP 127.0.0.1:35939->127.0.0.1:wap-wsp (CLOSE_WAIT)

lsof -n -iTCP:9300 returns nothing

same with ps aux

ps aux | grep elasticsearch
root      4479  0.0  0.0 103360   816 pts/4    S+   11:00   0:00 grep elasticsearch

I still get a bindtransportexception "cannot assign requested address" when ES tries to access 192.168.0.1:9400. The only service trying to talk to ES currently is logstash

Well, that lsof shows a java process is sitting on 9200. Did you try killing that process before restarting Elasticsearch?

Is this a distro installation (e.g. using a deb or rpm)? I ask because I saw you try to use init.d, but are also starting it manually.

Can you shut down Logstash, then restart ES so that only ES is running to begin with? Are you using the HTTP output for Logstash (and not the java node client output)?

Sorry, I don't have a lot of specific advice :confused: I'm fairly sure the issue is that some process is squatting on the ports that ES needs, so you just need to find and remove that process (or change the ports that ES is using with transport.tcp.port and http.port, docs here: https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html)

You could also try configuring the network.host manually to make sure it binds the right interface.