Running elasticsearch as a Service on RHEL Linux

We have to start our elasticsearch manually every time our servers are rebooted due to security patching or other OS maintenance related so I'm looking for a script to start elasticsearch automatically after a server is rebooted. We are running RHEL 6.8. It looks like we have something shipped with 0.90 release but was no longer available after 2.4 release?? Can anyone share it please?

From version 0.90:
https://www.elastic.co/guide/en/elasticsearch/reference/0.90/_linux.html

"RedHat based distributions are using chkconfig to enable and disable services. The init script is at /etc/init.d/elasticsearch, where as the configuration file is placed at /etc/sysconfig/elasticsearch"

Which Elasticsearch version do you have currently?

I have 5.3.1

{
"name" : "epgidvlbrd1860",
"cluster_name" : "elk-nonprod",
"cluster_uuid" : "DQzqtam-RfyWBaGCEvkBTw",
"version" : {
"number" : "5.3.1",
"build_hash" : "5f9cf58",
"build_date" : "2017-04-17T15:52:53.846Z",
"build_snapshot" : false,
"lucene_version" : "6.4.2"
},
"tagline" : "You Know, for Search"
}

Try this:

sudo systemctl daemon-reload
sudo systemctl enable elasticsearch
sudo systemctl start elasticsearch

RHEL6.8 is still initd-based, AFAIK

yes, I forgot it... sorry

Thanks anyway! I've just installed elasticsearch 5.4 on a new sever running REHL 7.3. I also found this doc

"Auto-starting Services with systemd" section
According to instructions in the above section, I need to have the init script for elasticsearch before I can run those commands that you gave right? It looks like 5.4 doesn't come with the script. I don't know how to write one. Can you or anyone else help please?

Did you tried to run mentioned commands now on RHEL 7.3?

Everything about installation and running Elasticsearch exists described here:

look at section Running Elasticsearch with systemd

I did try the commands:
2) Ran daemon_reload
3) Systemctl enable elasticsearch FAILED
a. [root@dzbsdlr001 init.d]# systemctl enable elasticsearch
b. Failed to execute operation: No such file or directory
Looks like the service has not been implemented yet.

1 Like

It looks like 5.4 doesn't come with a functional systemd init script located at /etc/systemd/system/multi-user.target.wants/service.service that's why the command failed:

[root@abzedlr001 init.d]# systemctl enable elasticsearch.service
Failed to execute operation: No such file or directory

            How about your system?  Where is it on your system?

On my system, that file is placed at /usr/lib/systemd/system/elasticsearch.service.

Its content:

[root@elkstack54 ~]# cat /usr/lib/systemd/system/elasticsearch.service 
[Unit]
Description=Elasticsearch
Documentation=http://www.elastic.co
Wants=network-online.target
After=network-online.target

[Service]
Environment=ES_HOME=/usr/share/elasticsearch
Environment=CONF_DIR=/etc/elasticsearch
Environment=DATA_DIR=/var/lib/elasticsearch
Environment=LOG_DIR=/var/log/elasticsearch
Environment=PID_DIR=/var/run/elasticsearch
EnvironmentFile=-/etc/sysconfig/elasticsearch

WorkingDirectory=/usr/share/elasticsearch

User=elasticsearch
Group=elasticsearch

ExecStartPre=/usr/share/elasticsearch/bin/elasticsearch-systemd-pre-exec

ExecStart=/usr/share/elasticsearch/bin/elasticsearch \
                                                -p ${PID_DIR}/elasticsearch.pid \
                                                --quiet \
                                                -Edefault.path.logs=${LOG_DIR} \
                                                -Edefault.path.data=${DATA_DIR} \
                                                -Edefault.path.conf=${CONF_DIR}

# StandardOutput is configured to redirect to journalctl since
# some error messages may be logged in standard output before
# elasticsearch logging system is initialized. Elasticsearch
# stores its logs in /var/log/elasticsearch and does not use
# journalctl by default. If you also want to enable journalctl
# logging, you can simply remove the "quiet" option from ExecStart.
StandardOutput=journal
StandardError=inherit

# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65536

# Specifies the maximum number of bytes of memory that may be locked into RAM
# Set to "infinity" if you use the 'bootstrap.memory_lock: true' option
# in elasticsearch.yml and 'MAX_LOCKED_MEMORY=unlimited' in /etc/sysconfig/elasticsearch
LimitMEMLOCK=infinity

# Disable timeout logic and wait until process is stopped
TimeoutStopSec=0

# SIGTERM signal is used to stop the Java process
KillSignal=SIGTERM

# Java process is never killed
SendSIGKILL=no

# When a JVM receives a SIGTERM signal it exits with code 143
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target

# Built for distribution-5.4.0 (distribution)

Did you install elasticsearch with RPM? I installed elasticsearch from a tar file. Silly me but I wonder if elasticsearch.service only come with RPM package?

Yes, I downloaded RPM from official site an installed it. I didn't created file elasticsearch.service manually. It was autocreated when I executed systemctl commands mentioned above.

Maybe you have to to try with the rpm?

@hungl99 i too am using the binaries from the tar and running elasticsearch. please do update if you find a solution to run elasticsearch as a service.

1 Like

Hi, I'm also having this problem because I wanted to install elasticsearch (and logstash and kibana) in /opt which is a filesystem I'd allocated extra space to for these tools.

I did the RPM install first which I then realised didn't install into /opt so I removed it and did the manual install but it is rather frustrating to find no init scripts.

I have the init script left over the from RPM install so I'm going to have a look at that and see if I can just change the paths in it to match mine, but if someone has a official one for elasticsearch 5.3.0 I'd be very grateful.

If I get it working, I'll post mine.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.