Skip to main content

Checks Required Before Starting Installation

Important for InstallationFor the installation to be healthy, your servers must have access to the following addresses.For Elasticsearch installation:
ImportantWhen updating Ubuntu packages, it tries to pull from servers in Turkey location. However, there may be problems with tr.archive.ubuntu.com from time to time. In this case, the following change should be made.
sudo vi /etc/apt/sources.list
#Replace all addresses containing tr. with “Replace All”.#Example:Old: http://tr.archive.ubuntu.com/ubuntuNew: http://archive.ubuntu.com/ubuntu

Operating System Configurations

The following steps must be performed on all servers.
# Elasticsearch user is created and authorized
sudo adduser elasticsearch
sudo usermod -aG sudo elasticsearch

# Switch to the user to continue operations
sudo su - elasticsearch

# It is recommended that the following tools be installed on all servers
sudo apt update
sudo apt install -y curl wget net-tools gnupg2 software-properties-common apt-transport-https ca-certificates

# Firewall is disabled
sudo systemctl stop ufw
sudo systemctl disable ufw

# Swap is disabled and the swap line in /etc/fstab file is deleted to prevent it from restarting
sudo swapoff -a
sudo vi /etc/fstab
# Then close the vi file (:wq)

Elasticsearch Installation

Operating System Configurations and Elasticsearch Application Installation

The following steps must be performed on all Elasticsearch servers.
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
sudo sysctl -p
sudo sysctl vm.max_map_count

Elasticsearch Installation

The following steps must be performed on all Elasticsearch servers.
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, pay attention to where the appropriate disk is mounted or ask system administrators to add the disk to the following path
#The following commands can be used for this check
df -h
lsblk

sudo mkdir /mnt/elastic-data/
sudo mkdir /mnt/elastic-snapdata/
sudo chown -Rf elasticsearch:elasticsearch /mnt/elastic-*
sudo chmod -Rf 775 /mnt/elastic-*

Configuring Elasticsearch Parameters According to Environment

The following steps must be performed on all Elasticsearch servers.
The following parameters must be added by configuring them according to your own environment.
  • cluster.initial_master_nodes
  • network.host
  • node.name
sudo vi /opt/elasticsearch/elasticsearch-7.9.2/config/elasticsearch.yml
ImportantHere, path.data and path.repo addresses must be given as the address of the disk where your log file will be stored in the system, in accordance with the previous item.
cluster.name: ApinizerEsCluster
node.name: "<ELASTICSEARCH_IP_ADDRESS>"
node.master: true
node.data: true
network.host: <ELASTICSEARCH_IP_ADDRESS>
http.port: 9200
cluster.initial_master_nodes: ["<ELASTICSEARCH_IP_ADDRESS>"]
discovery.seed_hosts: []
path.data: /mnt/elastic-data/
path.repo: ["/mnt/elastic-snapdata"]
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
You can configure the JVM (Java Virtual Machine) values and other JVM parameters that Elasticsearch will use as follows.
sudo vi /opt/elasticsearch/elasticsearch-7.9.2/config/jvm.options
ImportantHere, you can go up to half of the RAM amount that the operating system has, and this value should not exceed 32GB
-Xms8g
-Xmx8g

Setting Elasticsearch as Linux Service

The following steps must be performed on all Elasticsearch servers.
sudo vi /opt/elasticsearch/elasticsearch-7.9.2/bin/elasticsearch-service.sh
#!/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
sudo chmod -Rf 775 /opt/elasticsearch/elasticsearch-7.9.2/*
sudo vi /etc/systemd/system/elasticsearch.service
[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
sudo systemctl daemon-reload
sudo systemctl start elasticsearch
sudo systemctl status elasticsearch
sudo systemctl enable elasticsearch
You can use the following link for the compatible Kibana version.
https://www.elastic.co/downloads/past-releases/kibana-oss-7-9-2