Installing services under Linux

I had to setup thoses as part of my work. Here is a copy here as the method can apply to many services. Original article I wrote:

Install elasticsearch on CentOS

Install from repository

We use an Automated install. We could have used http://ondrej-kvasnovsky.blogspot.fr/2013/10/how-to-install-elasticsearch-as-service.html.

  • Add to repo
sudo rpm --import http://packages.elasticsearch.org/GPG-KEY-elasticsearch
cd /etc/yum.repos.d
sudo geany elasticsearch.repo
  • Put the following content in the file
elasticsearch-0.90
name=Elasticsearch repository for 0.90.x packages
baseurl=http://packages.elasticsearch.org/elasticsearch/0.90/centos
gpgcheck=1
gpgkey=http://packages.elasticsearch.org/GPG-KEY-elasticsearch
enabled=
  • Install java and elastic search
sudo yum install java-1.7.0-openjdk.x86_64
sudo yum install elasticsearch

This automatically set elasticsearch as a service. The service is configured at 2 different places

  • /etc/init.d/elasticsearch
  • /etc/systemd/system/elasticsearch.service (doesn't seem to be used? not sure)

The defaults seem to be in '/etc/sysconfig/elasticsearch':

  • Binaries ES_HOME = /usr/share/elasticsearch
  • Config directory CONF_DIR = /etc/elasticsearch/
  • Config file CONF_FILE = /etc/elasticsearch/elasticsearch.yml (of course you need to tweak the config there)
  • Data DATA_DIR = /var/lib/elasticsearch
  • Logs LOG_DIR = /var/log/elasticsearch
  • Work directory WORK_DIR = /tmp/elasticsearch (this is a temp folder)
  • Install Head plugin
cd /usr/share/elasticsearch/bin
sudo ./plugin -install mobz/elasticsearch-head
  • Install River plugin (source https://github.com/richardwilly98/elasticsearch-river-mongodb)
sudo ./plugin --install com.github.richardwilly98.elasticsearch/elasticsearch-river-mongodb/1.7.3
  • Install extended analyze plugin
sudo ./plugin -u https://github.com/johtani/elasticsearch-extended-analyze/releases/download/v0.6.0/v0.6.0.zip -i elasticsearch-extended-analyze

Sanity checks

Check if service is running (or start it)

sudo service elasticsearch status
sudo service elasticsearch start

Check service is set for automated start

sudo /sbin/chkconfig --list

Setup another instance

init.d

  • Copy existing service config file and allow execution
sudo cp /etc/init.d/elasticsearch /etc/init.d/elasticsearch2
sudo chmod +x /etc/init.d/elasticsearch2
  • Edit new service config file
sudo geany /etc/init.d/elasticsearch2
  • Change line 35 prog=elasticsearch to prog=elasticsearch2
  • Copy and edit elasticsearch sysconfig file
sudo cp /etc/sysconfig/elasticsearch /etc/sysconfig/elasticsearch2
sudo geany /etc/sysconfig/elasticsearch2
  • Change log, data, work and conf directories to */elasticsearch2 instead of */elasticsearch
  • Change CONF_FILE=/etc/elasticsearch/elasticsearch.yml to CONF_FILE=/etc/elasticsearch/elasticsearch2.yml it simply doesn't work
  • Copy and edit elasticsearch instance config file
sudo cp -r /etc/elasticsearch /etc/elasticsearch2
sudo geany /etc/elasticsearch2/elasticsearch.yml
  • Change at least the node.name
  • Create the folders and give permission to the elasticsearch user
sudo mkdir /var/log/elasticsearch2
sudo mkdir /var/lib/elasticsearch2
sudo chown elasticsearch:elasticsearch /var/log/elasticsearch2
sudo chown elasticsearch:elasticsearch /var/lib/elasticsearch2
  • The config is ready, now is time to register the new service
sudo chkconfig --add elasticsearch2
  • Last but not least start it. Hopefully it will say OK and no error message will be displayed!
sudo service elasticsearch2 start

system.d

(I did this also but I think it's simply not used in this version of CentOS/Cloudera!)

  • Copy existing service config file
sudo cp /etc/systemd/system/elasticsearch.service /etc/systemd/system/elasticsearch2.service
  • Change EnvironmentFile=/etc/sysconfig/elasticsearch to EnvironmentFile=/etc/sysconfig/elasticsearch2
  • Change PIDFile=/var/run/elasticsearch/elasticsearch.pid to PIDFile=/var/run/elasticsearch/elasticsearch2.pid
  • Change ExecStart line parameter -p to /var/run/elasticsearch/elasticsearch2.pid
  • The process is then the same as above, copy the yml, create new folders etc... (don't need to do it twice of course)

Page top