# Running elasticsearch as a Service on RHEL Linux

**URL:** <https://discuss.elastic.co/t/running-elasticsearch-as-a-service-on-rhel-linux/85969>\
**Category:** Elasticsearch\
**Created:** [May 16, 2017, 3:38pm UTC](https://discuss.elastic.co/t/running-elasticsearch-as-a-service-on-rhel-linux/85969 "2017-05-16T15:38:03Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![hungl99](https://avatars.discourse-cdn.com/v4/letter/h/ed8c4c/32.png) [@hungl99](https://discuss.elastic.co/u/hungl99)\
**Post date:** [May 16, 2017, 3:38pm UTC](https://discuss.elastic.co/t/running-elasticsearch-as-a-service-on-rhel-linux/85969/1 "2017-05-16T15:38:03Z")

</div>

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](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"

---

<div class="post-metadata">

**Author:** ![jovanmal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jovanmal/32/17330_2.png) [@jovanmal](https://discuss.elastic.co/u/jovanmal)\
**Post date:** [May 16, 2017, 8:45pm UTC](https://discuss.elastic.co/t/running-elasticsearch-as-a-service-on-rhel-linux/85969/2 "2017-05-16T20:45:00Z")

</div>

Which Elasticsearch version do you have currently?

---

<div class="post-metadata">

**Author:** ![hungl99](https://avatars.discourse-cdn.com/v4/letter/h/ed8c4c/32.png) [@hungl99](https://discuss.elastic.co/u/hungl99)\
**Post date:** [May 16, 2017, 8:55pm UTC](https://discuss.elastic.co/t/running-elasticsearch-as-a-service-on-rhel-linux/85969/3 "2017-05-16T20:55:05Z")

</div>

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"  
}

---

<div class="post-metadata">

**Author:** ![jovanmal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jovanmal/32/17330_2.png) [@jovanmal](https://discuss.elastic.co/u/jovanmal)\
**Post date:** [May 16, 2017, 8:58pm UTC](https://discuss.elastic.co/t/running-elasticsearch-as-a-service-on-rhel-linux/85969/4 "2017-05-16T20:58:08Z")

</div>

Try this:

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

---

<div class="post-metadata">

**Author:** ![Vitaly\_il](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vitaly_il/32/130964_2.png) [@Vitaly\_il](https://discuss.elastic.co/u/Vitaly_il)\
**Post date:** [May 17, 2017, 7:02am UTC](https://discuss.elastic.co/t/running-elasticsearch-as-a-service-on-rhel-linux/85969/5 "2017-05-17T07:02:42Z")

</div>

RHEL6.8 is still initd-based, AFAIK

---

<div class="post-metadata">

**Author:** ![jovanmal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jovanmal/32/17330_2.png) [@jovanmal](https://discuss.elastic.co/u/jovanmal)\
**Post date:** [May 17, 2017, 9:50am UTC](https://discuss.elastic.co/t/running-elasticsearch-as-a-service-on-rhel-linux/85969/6 "2017-05-17T09:50:57Z")

</div>

yes, I forgot it... sorry

---

<div class="post-metadata">

**Author:** ![hungl99](https://avatars.discourse-cdn.com/v4/letter/h/ed8c4c/32.png) [@hungl99](https://discuss.elastic.co/u/hungl99)\
**Post date:** [May 17, 2017, 6:39pm UTC](https://discuss.elastic.co/t/running-elasticsearch-as-a-service-on-rhel-linux/85969/7 "2017-05-17T18:39:12Z")

</div>

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

> **[How To Configure a Linux Service to Start Automatically After a Crash or Reboot...](https://www.digitalocean.com/community/tutorials/how-to-configure-a-linux-service-to-start-automatically-after-a-crash-or-reboot-part-1-practical-examples)**
>
> This tutorial shows you how to configure system services to automatically restart after a crash or a server reboot. We cover the three most common init systems in this tutorial: System V, Upstart, and systemd.

"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?

---

<div class="post-metadata">

**Author:** ![jovanmal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jovanmal/32/17330_2.png) [@jovanmal](https://discuss.elastic.co/u/jovanmal)\
**Post date:** [May 17, 2017, 8:14pm UTC](https://discuss.elastic.co/t/running-elasticsearch-as-a-service-on-rhel-linux/85969/8 "2017-05-17T20:14:00Z")

</div>

> [@jovanmal](#):
>
> sudo systemctl daemon-reload  
> sudo systemctl enable elasticsearch

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

Everything about installation and running Elasticsearch exists described here:

> **[Install Elasticsearch with RPM | Elasticsearch Guide \[8.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/rpm.html)**

look at section **Running Elasticsearch with systemd**

---

<div class="post-metadata">

**Author:** ![hungl99](https://avatars.discourse-cdn.com/v4/letter/h/ed8c4c/32.png) [@hungl99](https://discuss.elastic.co/u/hungl99)\
**Post date:** [May 18, 2017, 2:21pm UTC](https://discuss.elastic.co/t/running-elasticsearch-as-a-service-on-rhel-linux/85969/9 "2017-05-18T14:21:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hungl99](https://avatars.discourse-cdn.com/v4/letter/h/ed8c4c/32.png) [@hungl99](https://discuss.elastic.co/u/hungl99)\
**Post date:** [May 18, 2017, 4:38pm UTC](https://discuss.elastic.co/t/running-elasticsearch-as-a-service-on-rhel-linux/85969/10 "2017-05-18T16:38:15Z")

</div>

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?
```

---

<div class="post-metadata">

**Author:** ![jovanmal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jovanmal/32/17330_2.png) [@jovanmal](https://discuss.elastic.co/u/jovanmal)\
**Post date:** [May 19, 2017, 9:17am UTC](https://discuss.elastic.co/t/running-elasticsearch-as-a-service-on-rhel-linux/85969/11 "2017-05-19T09:17:25Z")

</div>

> [@hungl99](#):
>
> 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:

```auto
[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)

```

---

<div class="post-metadata">

**Author:** ![hungl99](https://avatars.discourse-cdn.com/v4/letter/h/ed8c4c/32.png) [@hungl99](https://discuss.elastic.co/u/hungl99)\
**Post date:** [May 19, 2017, 2:38pm UTC](https://discuss.elastic.co/t/running-elasticsearch-as-a-service-on-rhel-linux/85969/12 "2017-05-19T14:38:53Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jovanmal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jovanmal/32/17330_2.png) [@jovanmal](https://discuss.elastic.co/u/jovanmal)\
**Post date:** [May 19, 2017, 2:42pm UTC](https://discuss.elastic.co/t/running-elasticsearch-as-a-service-on-rhel-linux/85969/13 "2017-05-19T14:42:47Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jmahishi](https://avatars.discourse-cdn.com/v4/letter/j/8e8cbc/32.png) [@jmahishi](https://discuss.elastic.co/u/jmahishi)\
**Post date:** [May 23, 2017, 7:01am UTC](https://discuss.elastic.co/t/running-elasticsearch-as-a-service-on-rhel-linux/85969/14 "2017-05-23T07:01:55Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![Bryn\_Ellis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bryn_ellis/32/19041_2.png) [@Bryn\_Ellis](https://discuss.elastic.co/u/Bryn_Ellis)\
**Post date:** [June 14, 2017, 8:17am UTC](https://discuss.elastic.co/t/running-elasticsearch-as-a-service-on-rhel-linux/85969/15 "2017-06-14T08:17:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 12, 2017, 8:17am UTC](https://discuss.elastic.co/t/running-elasticsearch-as-a-service-on-rhel-linux/85969/16 "2017-07-12T08:17:54Z")

</div>

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