Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch: Job for elasticsearch.service failed

I am currently trying to setup Elasticsearch for a project. I have installed Elasticsearch 7.4.1 and I have also installed Java, that is openjdk 11.0.4.

But when I try to start Elasticsearch using the command

sudo systemctl start elasticsearch

I get the error below

Job for elasticsearch.service failed because the control process exited with error code.

See "systemctl status elasticsearch.service" and "journalctl -xe" for details.

And when I try to run the command

systemctl status elasticsearch.service

I get the error message

● elasticsearch.service - Elasticsearch

Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; disabled; vend

Active: failed (Result: exit-code) since Fri 2019-11-01 06:09:54 UTC; 12s ago

Docs: http://www.elastic.co

Process: 5960 ExecStart=/usr/share/elasticsearch/bin/elasticsearch -p ${PID_DI

Main PID: 5960 (code=exited, status=1/FAILURE)

I have removed/purged Elasticsearch from my machine and re-installed several times, but it doesn't seem to fix the issue.

I have tried to modify the default network.host and host.port settings in /etc/default/elasticsearch to network.host: 0.0.0.0 and http.port: 9200 to fix the issue, but no luck yet.

I need some assistance. Thanks in advance.

like image 631
Promise Preston Avatar asked Nov 01 '19 09:11

Promise Preston


4 Answers

Here's how I solved

Firstly, Open /etc/elasticsearch/elasticsearch.yml in your nano editor using the command below:

sudo nano /etc/elasticsearch/elasticsearch.yml

Your network settings should be:

# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 127.0.0.1
#
# Set a custom port for HTTP:
#
http.port: 9200

In order for Elasticsearch to allow connections from localhost, and to also listen on port 9200.

Next, run the code below to determine the cause of the error:

journalctl -xe

Error 1

There is insufficient memory for the Java Runtime Environment to continue

Solution

As a JVM application, the Elasticsearch main server process only utilizes memory devoted to the JVM. The required memory may depend on the JVM used (32- or 64-bit). The memory used by JVM usually consists of:

  • heap space (configured via -Xms and -Xmx)
  • metaspace (limited by the amount of available native memory)
  • internal JVM (usually tens of Mb)
  • OS-dependent memory features like memory-mapped files.

Elasticsearch mostly depends on the heap memory, and this setting manually by passing the -Xms and -Xmx(heap space) option to the JVM running the Elasticsearch server.

Solution

Open /etc/elasticsearch/jvm.options in your nano editor using the command below:

sudo nano /etc/elasticsearch/jvm.options

First, un-comment the value of Xmx and Xms

Next, modify the value of -Xms and -Xmx to no more than 50% of your physical RAM. The value for these settings depends on the amount of RAM available on your server and Elasticsearch requires memory for purposes other than the JVM heap and it is important to leave space for this.

Minimum requirements: If your physical RAM is <= 1 GB

Then, your settings should be:

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms128m
-Xmx128m

OR

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms256m
-Xmx256m

Medium requirements: If your physical RAM is >= 2 GB but <= 4 GB

Then, your settings should be:

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms512m
-Xmx512m

OR

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms750m
-Xmx750m

Large requirements: If your physical RAM is >= 4 GB but <= 8 GB

Then, your settings should be:

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms1024m
-Xmx1024m

OR

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms2048m
-Xmx2048m

Note: If your physical RAM is >= 8 GB you can decide how much heap space you want to allocate to Elasticsearch. You can allocate -Xms2048m and -Xmx2048m OR -Xms4g and -Xmx4g or even higher for better performance based on your available resources.

Error 2

Initial heap size not equal to the maximum heap size

Solution

Ensure the value of -Xms and Xmx are equal. That is, say, you are using the minimum requirements since your physical RAM is <= 1 GB, instead of this:

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms128m
-Xmx256m

it should be this:

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms128m
-Xmx128m

OR this:

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms256m
-Xmx256m

Error 3

the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

Solution

Open /etc/elasticsearch/elasticsearch.yml in your nano editor using the command below:

sudo nano /etc/elasticsearch/elasticsearch.yml

Your discovery settings should be:

# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.seed_hosts: []

Once all the errors are fixed run the command below to start and confirm the status of Elasticsearch:

sudo systemctl start elasticsearch
sudo systemctl status elasticsearch

That's all.

I hope this helps

like image 53
Promise Preston Avatar answered Nov 20 '22 20:11

Promise Preston


Had the same problem with a small virtual machine. The above configurations were already set. The only thing that helped was to increase the start timeout. The standard systemd timeout was just not enough.

As a precaution, I set the timeout to 5 minutes as follows.

sudo nano /usr/lib/systemd/system/elasticsearch.service

Added under [Service] section in elasticsearch.service file.

TimeoutStartSec=300

Activate change to service.

sudo /bin/systemctl enable elasticsearch.service

Start service again.

service elasticsearch start
like image 22
Volker Fried Avatar answered Nov 20 '22 22:11

Volker Fried


A basic solution to this problem is to just uninstall Elasticsearch and Kibana and again re-install them and your problem will be solved.

For uninstalling Elasticsearch:

sudo apt-get remove --purge elasticsearch

The message was:

dpkg: warning: while removing elasticsearch, directory '/var/lib/elasticsearch' not empty so not removed
dpkg: warning: while removing elasticsearch, directory '/etc/elasticsearch' not empty so not removed

Removed those directories as well:

sudo rm -rf /etc/elasticsearch
sudo rm -rf /var/lib/elasticsearch

Then install it again:

sudo apt-get install elasticsearch=7.10.1
sudo systemctl start elasticsearch
curl http://localhost:9200/

For uninstalling Kibana:

sudo apt-get remove --purge kibana

Removed those directories as well:

sudo rm -rf /etc/kibana
sudo rm -rf /var/lib/kibana

Then install it again:

sudo apt-get install kibana=7.10.1
sudo systemctl start kibana

For opening Kibana on browser:

http://localhost:5601
like image 9
ashwini borla Avatar answered Nov 20 '22 20:11

ashwini borla


If you installed using package management, check if the owner of /etc/elasticsearch directory is elasticsearch.

sudo chown -R elasticsearch:elasticsearch /etc/elasticsearch/
like image 4
Andromeda Avatar answered Nov 20 '22 22:11

Andromeda