Elasticsearch won\'t start using ./bin/elasticsearch
.
It raises the following exception:
- ElasticsearchIllegalStateException[Failed to obtain n
the reason is another instance is running!
first find the id of running elastic.
ps aux | grep 'elastic'
then kill using kill -9 <PID_OF_RUNNING_ELASTIC>
.
There were some answers to remove node.lock file but that didn't help since the running instance will make it again!
In my situation I had wrong permissions on the ES dir folder. Setting correct owner solved it.
# change owner
chown -R elasticsearch:elasticsearch /data/elasticsearch/
# to validate
ls /data/elasticsearch/ -la
# prints
# drwxr-xr-x 2 elasticsearch elasticsearch 4096 Apr 30 14:54 CLUSTER_NAME
chown -R elasticsearch:elasticsearch /var/lib/elasticsearch
It directly shows it doesn't have permission to obtain a lock. So need to give permissions.
As with many others here replying, this was caused by wrong permissions on the directory (not owned by the elasticsearch user). In our case it was caused by uninstalling Elasticsearch and reinstalling it (via yum, using the official repositories).
As of this moment, the repos do not delete the nodes
directory when they are uninstalled, but they do delete the elasticsearch
user/group that owns it. So then when Elasticsearch is reinstalled, a new, different elasticsearch
user/group is created, leaving the old nodes
directory still present, but owned by the old UID/GID. This then conflicts and causes the error.
A recursive chown as mentioned by @oleksii is the solution.
To add to the above answers there could be some other scenarios in which you can get the error.In fact I had done a update from 5.5 to 6.3 for elasticsearch.I have been using the docker compose setup with named volumes for data directories.I had to do a docker volume prune
to remove the stale ones.After doing that I was no longer facing the issue.
Try the following:
1. find the port 9200, e.g.: lsof -i:9200
This will show you which processes use the port 9200.
2. kill the pid(s), e.g. repeat kill -9 pid
for each PID that the output of lsof
showed in step 1
3. restart elasticsearch, e.g. elasticsearch