Before Installation;

To follow this guide, you need the following:

  • One or more machines running a deb/rpm compatible Linux operating system; eg: Ubuntu or CentOS.
  • The minimum recommended system requirements are 8GB of RAM, 4 Core CPUs, and 200GB of Hard Disk space.


Elasticsearch installation is the same in Centos and Ubuntu environments. The following steps apply to both operating systems.

Installation Steps

1. Operating system configurations

Disable firewall

## Centos 
sudo systemctl stop firewalld
sudo systemctl disable firewalld

## Ubuntu
sudo systemctl stop ufw
sudo systemctl disable ufw
POWERSHELL

Disable Selinux

If the servers operating system is CentOS, disable SELinux to avoid communication problems on all servers.

sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config
POWERSHELL

Deactivate Swap

Let's disable swap to avoid communication problems on nodes. For this, the following steps are done and the swap line in the /etc/fstab file is deleted.

sudo swapoff -a

sudo vi /etc/fstab              
POWERSHELL

2. System configuration for Elasticsearch

sudo adduser elasticsearch 
sudo passwd elasticsearch

### Centos
sudo usermod -aG wheel elasticsearch

### Ubuntu
sudo usermod -aG sudo elasticsearch

### Centos 
sudo ulimit -n 65535
 
sudo vi /etc/security/limits.conf
elasticsearch  -  nofile  65535
elasticsearch soft memlock unlimited
elasticsearch hard memlock unlimited
 
sudo sysctl -w vm.swappiness=1 
sudo sysctl -w vm.max_map_count=262144
 
sudo vi /etc/sysctl.conf
vm.max_map_count=262144 elasticsearch
  
sudo sysctl -p 
sudo sysctl vm.max_map_count
BASH

3. Elasticsearch Installation

su elasticsearch
sudo mkdir /opt/elasticsearch
cd /opt/elasticsearch
sudo wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.2-linux-x86_64.tar.gz
sudo tar -xzf elasticsearch-7.9.2-linux-x86_64.tar.gz

sudo chown -Rf elasticsearch:elasticsearch /opt/elasticsearch 
sudo chmod -Rf 775 /opt/elasticsearch

##At this point, be sure where the correct disk is mounted, or ask the system administrations to mount the disk to location below
sudo mkdir /mnt/elastic-data/ 
sudo chown -Rf elasticsearch:elasticsearch /mnt/elastic-data/ 
sudo chmod -Rf 775 /mnt/elastic-data/ 
BASH

4. Adjust Elasticsearch parameters to suit your environment

Follow the steps below to start elasticsearch automatically when the operation is restarted.

You need to set the following parameters according to your environment.

  • cluster.initial_master_nodes
  • network.host
  • node.name


sudo vi /opt/elasticsearch/elasticsearch-7.9.2/config/elasticsearch.yml 
BASH
cluster.name: ApinizerEsCluster
#give your node a name (the same as your hostname)
node.name: "YOURIP"
node.master: true
node.data: true
#enter the private IP and port of your node (the same ip as your machine)
network.host: YOURHOSTIP
http.port: 9200
#detail the private IPs of your nodes:
#to avoid split brain ([Master Eligible Node) / 2 + 1])
 
cluster.initial_master_nodes: ["YOURIP"]
 
discovery.seed_hosts: []
path.data: /mnt/elastic-data/
 
bootstrap.memory_lock: true
 
http.cors.enabled : true
http.cors.allow-origin : "*"
http.cors.allow-methods : OPTIONS, HEAD, GET, POST, PUT, DELETE
http.cors.allow-headers : X-Requested-With,X-Auth-Token,Content-Type, Content-Length
BASH

5. Elasticsearch JVM parameter settings

You can set the JVM (Java Virtual Machine) values and other JVM parameters that Elasticseach will use as follows.

To set the JVM values

ELASTIC_HOME/config/jvm.options

6. Setting Elasticsearch as Linux Service

sudo vi /opt/elasticsearch/elasticsearch-7.9.2/bin/elasticsearch-service.sh
BASH
#!/bin/sh
SERVICE_NAME=elasticsearch
PATH_TO_APP="/opt/elasticsearch/elasticsearch-7.9.2/bin/$SERVICE_NAME"
PID_PATH_NAME="/opt/elasticsearch/elasticsearch-7.9.2/bin/$SERVICE_NAME.pid"
SCRIPTNAME=elasticsearch-service.sh
ES_USER=$SERVICE_NAME
ES_GROUP=$SERVICE_NAME
 
case $1 in
    start)
        echo "Starting $SERVICE_NAME ..."
        if [ ! -f $PID_PATH_NAME ]; then
        mkdir $(dirname $PID_PATH_NAME) > /dev/null 2>&1 || true
            chown $ES_USER $(dirname $PID_PATH_NAME)
            $SUDO $PATH_TO_APP -d -p $PID_PATH_NAME
        echo "Return code: $?"
            echo "$SERVICE_NAME started ..."
        else
            echo "$SERVICE_NAME is already running ..."
        fi
    ;;
    stop)
        if [ -f $PID_PATH_NAME ]; then
            PID=$(cat $PID_PATH_NAME);
            echo "$SERVICE_NAME stopping ..."
            kill -15 $PID;
            echo "$SERVICE_NAME stopped ..."
            rm $PID_PATH_NAME
        else
            echo "$SERVICE_NAME is not running ..."
        fi
    ;;
    restart)
        if [ -f $PID_PATH_NAME ]; then
            PID=$(cat $PID_PATH_NAME);
            echo "$SERVICE_NAME stopping ...";
            kill -15 $PID;
        sleep 1;
            echo "$SERVICE_NAME stopped ...";
            rm -rf $PID_PATH_NAME
            echo "$SERVICE_NAME starting ..."
            mkdir $(dirname $PID_PATH_NAME) > /dev/null 2>&1 || true
            chown $ES_USER $(dirname $PID_PATH_NAME)
            $SUDO $PATH_TO_APP -d -p $PID_PATH_NAME
            echo "$SERVICE_NAME started ..."
         else
            echo "$SERVICE_NAME is not running ..."
        fi
    ;;
  *)
    echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2
    exit 3
    ;;
esac

BASH
sudo chmod -Rf 775 /opt/elasticsearch/elasticsearch-7.9.2/*

sudo vi /etc/systemd/system/elasticsearch.service
BASH
[Unit]
Description=ElasticSearch Server
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
Type=forking
ExecStart=/opt/elasticsearch/elasticsearch-7.9.2/bin/elasticsearch-service.sh start
ExecStop=/opt/elasticsearch/elasticsearch-7.9.2/bin/elasticsearch-service.sh stop
ExecReload=/opt/elasticsearch/elasticsearch-7.9.2/bin/elasticsearch-service.sh restart
LimitNOFILE=65536
LimitMEMLOCK=infinity
User=elasticsearch
POWERSHELL
sudo systemctl daemon-reload

sudo systemctl start elasticsearch
sudo systemctl status elasticsearch
sudo systemctl enable elasticsearch
POWERSHELL

If necessary, compatible Kibana version can be found on link below.

https://www.elastic.co/downloads/past-releases/kibana-oss-7-9-2
POWERSHELL