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. Good post and informative. Thank you very much for sharing this good article, it was so good to read and useful to improve my knowledge as updated, keep blogging. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
    oracle training in chennai

    oracle training institute in chennai

    oracle training in bangalore

    oracle training in hyderabad

    oracle training

    oracle online training

    hadoop training in chennai

    hadoop training in bangalore

  2. Great knowledge, do anyone mind merely reference back to it alkomprar tienda on line

  3. 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!!!!!! 먹튀검증

  4. You there, this is really good post here. Thanks for taking the time to post such valuable information. Quality content is what always gets the visitors coming. 대전1인샵

  5. Great post, you have pointed out some fantastic points , I likewise think this s a very wonderful website. test bank nursing

  6. I have read all the comments and suggestions posted by the visitors for this article are very fine,We will wait for your next article so only.Thanks! 먹튀검증

  7. I havent any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us. common core math workbook

  8. Great article with excellent idea!Thank you for such a valuable article. I really appreciate for this great information.. check this site


Please do not enter spam links


More Services