Installation of Elastic-search on ubuntu

How To Install Java with Apt-Get on Ubuntu 16.04

1. Installing Oracle Java

- Go to root shell
sudo -i

- Run these commands in this order (

  1. apt-get install python-software-properties
  2. add-apt-repository ppa:webupd8team/java
  3. apt-get update
  4. apt-get install oracle-java8-installer
  5. vim /etc/environment
  6. Add this line - JAVA_HOME="/usr/lib/jvm/java-8-oracle/"
  7. source /etc/environment
  8. echo $JAVA_HOME

2. Install Elasticsearch with Debian package: 

Installing Elastic Search (

1. Download and install the Public Signing Key:
wget -qO - | sudo apt-key add -

2. Install the apt-transport-https package on Debian
sudo apt-get install apt-transport-https

3. Save the repository definition to /etc/apt/sources.list.d/elasticsearch-{branch}.list:
echo "deb stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-5.x.list

4. Run apt-get update and the repository is ready for use. You can install it with:
sudo apt-get update && sudo apt-get install elasticsearch

3. Update the configuration as per requirements.
vim /etc/elasticsearch/elasticsearch.yml
- Change cluster name
- Change node name
- Change node type (master/data)
- Change Conf path
- Change Data path
- Change Log path
- Enable bootstrap.mlockall to true (Use with Caution. Elastic 5.1.1 this causes the service to crash)
- Change to allow binding from all IPs and DNS.
- Change Unicast Host IPs

3.1 Changes for ElasticSearch 5.X
Do these changes when installing Elastic 5.X with Memory Lock

The systemd service file (/usr/lib/systemd/system/elasticsearch.service) contains the limits that are applied by default.

To override these, add a file called /etc/systemd/system/elasticsearch.service.d/elasticsearch.conf and specify any changes in that file, such as:


- Create a directory /etc/systemd/system/elasticsearch.service.d
- Add File elasticsearch.conf
- Add the line

4. Update JVM Options to increase Heap Size
1. vim /etc/elasticsearch/jvm.options
2. Change -Xms2g to -Xms15g
3. Change -Xmx2g to -Xmx15g

5. Increase number of file descriptors and Threads
1. Open /etc/security/limits.conf and add these lines

*                soft    nofile          100000
*                hard    nofile          200000
root             soft    nofile          100000
root             hard    nofile          200000
*                soft    nproc           2048
*                hard    nproc           2048
root             soft    nproc           2048
root             hard    nproc           2048

2. Add in permissions file /etc/pam.d/common-session

session required

6. Update the auto start script
vim /etc/init.d/elasticsearch
- Change ES_USER=maelasticuserdev (or any other admin user)
- Change ES_GROUP=adm (ensure user in admin group)
- Allocate Heap Size (ES_HEAP_SIZE)
- Change MAX_LOCKED_MEMORY=unlimited (check if mlockall is true)
- Change LOG_DIR
- Change DATA_DIR
- Change WORK_DIR
- Add these lines after startup to source the global variables
#Source the environment variables
#Post restart the variables are not initialized
echo "Sourcing Environemnt variables for $ES_MIN_MEM and $ES_MAX_MEM"
. /etc/environment
echo $ES_MIN_MEM
echo $ES_MAX_MEM

- comment the line
start-stop-daemon --start -b --user "$ES_USER" -c "$ES_USER" --pidfile "$PID_FILE" --exec $DAEMON -- $DAEMON_OPTS
- also comment the retry section
- Add this startup script
echo "Sleeping for 10 seconds till process starts"
sleep 10
- comment stop code
#               start-stop-daemon --stop --pidfile "$PID_FILE" \
#                       --user "$ES_USER" \
#                       --quiet \
#                       --retry forever/TERM/20 > /dev/null
#               if [ $? -eq 1 ]; then
#                       log_progress_msg "$DESC is not running but pid file exists, cleaning up"
#               elif [ $? -eq 3 ]; then
#                       PID="`cat $PID_FILE`"
#                       log_failure_msg "Failed to stop $DESC (pid $PID)"
#                       exit 1
#               fi
- Add this stop script
 pid=`cat $PID_FILE`
             echo "Process Id: $pid"
             kill $pid

7. Configure Elasticsearch to automatically start during bootup.

For systemd

sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service

Starting and Stopping
sudo systemctl start elasticsearch.service
sudo systemctl stop elasticsearch.service

For sysV init

sudo update-rc.d elasticsearch defaults 95 10

sudo -i service elasticsearch start
sudo -i service elasticsearch stop

8. For Replicated / VM Snapshot Machines

Make sure to delete all data folders for the new created VM from a snapshot.
Elastic stores the node id in the data folder which is not cleared unless the data files are deleted.

Author: Mohammed Adil

Write comments
  1. Yes i am totally agreed with this article and i just want say that this article is very nice and very informative article.I will make sure to be reading your blog more. You made a good point but I can't help but wonder, what about the other side? !!!!!!THANKS!!!!!! 먹튀검증

  2. This is a fine article. Everyone should read things. thanks for sharing this valuable knowledge.
    aws online training

  3. I exploit solely premium quality products -- you will observe these individuals on: folding doors dubai

  4. Facebook games have shown a lot of popularity during the past year. As Facebook adds more games to its already huge entertainment menu you may be wondering which games are the best and most fun to play. This article will give separate game reviews for each of the twenty five top Facebook games for 2010.

  5. Many games have emerged during the last decade with the words "Lord of the Rings" in their name, from traditional board games to Monopoly: The Lord of the Rings Trilogy Edition and Risk: The Lord of the Rings. The Lord of the Rings: The Card Game is a Living Card Game (LGG). Let's see if it stands out from the crowd.

  6. Thanks for writing such a good article, I stumbled onto your blog and read a few post. I like your style of writing... privacy friendly cloud storage

  7. Making a living by playing video games would have been considered to be a ridiculous and unrealistic career option just a few decades ago. However, the popularity of video games across the globe has made video game testing a viable career option. In fact, there are already a lot of people in the world who are making tons of cash doing what they know best and love the most; playing video games.

  8. LASIK is one of the best types of corrective eye surgery. LASIK stands for Laser-Assisted In Situ Keratomileusis. This procedure can permanently reshape the cornea, which is the clear covering of the front of the eye with the help of a laser. LASIK is performed on millions of people every year.


Please do not enter spam links

Meet US


More Services