Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Installing ElasticSearch on Ubuntu 14.04
#!/bin/bash
### USAGE
###
### ./ElasticSearch.sh 1.7 will install Elasticsearch 1.7
### ./ElasticSearch.sh will fail because no version was specified (exit code 1)
###
### CLI options Contributed by @janpieper
### Check http://www.elasticsearch.org/download/ for latest version of ElasticSearch
### ElasticSearch version
if [ -z "$1" ]; then
echo ""
echo " Please specify the Elasticsearch version you want to install!"
echo ""
echo " $ $0 1.7"
echo ""
exit 1
fi
ELASTICSEARCH_VERSION=$1
if [[ ! "${ELASTICSEARCH_VERSION}" =~ ^[0-9]+\.[0-9]+ ]]; then
echo ""
echo " The specified Elasticsearch version isn't valid!"
echo ""
echo " $ $0 1.7"
echo ""
exit 2
fi
### Install Java 8
cd ~
sudo apt-get install python-software-properties -y
sleep 1
sudo add-apt-repository ppa:webupd8team/java -y
sleep 1
sudo apt-get update
sleep 1
sudo apt-get install oracle-java8-installer -y
### Download and install the Public Signing Key
wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
### Setup Repository
echo "deb http://packages.elastic.co/elasticsearch/${ELASTICSEARCH_VERSION}/debian stable main" | sudo tee -a /etc/apt/sources.list.d/elk.list
### Install Elasticsearch
sudo apt-get update && sudo apt-get install elasticsearch -y
### Start ElasticSearch
sudo service elasticsearch start
### Lets wait a little while ElasticSearch starts
sleep 5
### Make sure service is running
curl http://localhost:9200
### Should return something like this:
# {
# "status" : 200,
# "name" : "Storm",
# "version" : {
# "number" : "1.3.1",
# "build_hash" : "2de6dc5268c32fb49b205233c138d93aaf772015",
# "build_timestamp" : "2014-07-28T14:45:15Z",
# "build_snapshot" : false,
# "lucene_version" : "4.9"
# },
# "tagline" : "You Know, for Search"
# }
@trkrameshkumar

This comment has been minimized.

Copy link

@trkrameshkumar trkrameshkumar commented Dec 15, 2014

@ricardo-rossi Thank you.

@alexey

This comment has been minimized.

Copy link

@alexey alexey commented Dec 17, 2014

well done! thank you

@biskalero

This comment has been minimized.

Copy link

@biskalero biskalero commented Dec 30, 2014

@ricardo-rossi thank you very much that worked perfectly.

@janpieper

This comment has been minimized.

Copy link

@janpieper janpieper commented Jan 7, 2015

I've forked your script and added a CLI argument to specify the Elasticsearch version so you don't need to edit the file to install another version.

,/ElasticSearch.sh 1.3.0 will install Elasticsearch 1.3.0
,/ElasticSearch.sh 1.4.2 will install Elasticsearch 1.4.2
,/ElasticSearch.sh will fail because no version was specified (exit code 1)
,/ElasticSearch.sh 1.3. will fail because no valid version was specified (exit code 2)

https://gist.github.com/janpieper/2c96fb12d9b566a679a5

@naglalakk

This comment has been minimized.

Copy link

@naglalakk naglalakk commented Jan 13, 2015

Very good stuff. Thank you :)

@gourneau

This comment has been minimized.

Copy link

@gourneau gourneau commented Jan 14, 2015

Thanks, here is my update for ElasticSearch 1.4.2 with the Oracle 8 JDK https://gist.github.com/gourneau/66e0bd90c92ad829590b

@ricardo-rossi

This comment has been minimized.

Copy link
Owner Author

@ricardo-rossi ricardo-rossi commented Jan 15, 2015

@janpieper: Good stuff your CLI addition!

@ricardo-rossi

This comment has been minimized.

Copy link
Owner Author

@ricardo-rossi ricardo-rossi commented Jan 15, 2015

@gourneau Great!

@cakephpcebu

This comment has been minimized.

Copy link

@cakephpcebu cakephpcebu commented Jan 30, 2015

It Works! thanks.

@marlonmantilla

This comment has been minimized.

Copy link

@marlonmantilla marlonmantilla commented Feb 19, 2015

Niceeeeeee thanks a lot!

@imkarthikk

This comment has been minimized.

Copy link

@imkarthikk imkarthikk commented Feb 23, 2015

This is awesome. Here's the updated Gist for 1.4.4: https://gist.github.com/imkarthikk/9af58ae9a29eb8320ea1

@rosskevin

This comment has been minimized.

Copy link

@rosskevin rosskevin commented Feb 24, 2015

@pbassut

This comment has been minimized.

Copy link

@pbassut pbassut commented Mar 24, 2015

Can someone confirm is the version used in this gist makes CVE-2015-1427, possible? If so, I think this gist should be removed or it shouldn't "suggest" a version to install. Instead use "elasticsearch-x.x.x.deb" notation.

@gobert

This comment has been minimized.

Copy link

@gobert gobert commented Mar 26, 2015

Top! Thanks you :)

@Bayakissa

This comment has been minimized.

Copy link

@Bayakissa Bayakissa commented Mar 26, 2015

Awesome, thanks !

@ricardo-rossi

This comment has been minimized.

Copy link
Owner Author

@ricardo-rossi ricardo-rossi commented Mar 31, 2015

Just updated the script to use CLI options.
Thanks @janpieper for the addition!

@davidbono

This comment has been minimized.

Copy link

@davidbono davidbono commented Apr 7, 2015

Thanks

@larsvoigt

This comment has been minimized.

Copy link

@larsvoigt larsvoigt commented Apr 8, 2015

Thank you! ElasticSearch service is now running on my server :).

@nurikabe

This comment has been minimized.

Copy link

@nurikabe nurikabe commented Apr 12, 2015

Note that the wrapper has been deprecated.

@heyalexej

This comment has been minimized.

Copy link

@heyalexej heyalexej commented Apr 23, 2015

Please consider a sleep cycle of a couple seconds between sudo service elasticsearch start and curl http://localhost:9200 as it can take a bit until the server responds.

@bgrand

This comment has been minimized.

Copy link

@bgrand bgrand commented Apr 29, 2015

Thanks Ricardo, installer and deamon work well! ElasticSearch is now installed and running on my Ubuntu 14.04.1 LTS server

@duykhoa

This comment has been minimized.

Copy link

@duykhoa duykhoa commented May 4, 2015

Sorry, but I can't call curl "localhost:9200", and get an error: "curl: (7) Failed to connect to 127.0.0.1 port 9200: Connection refused". How to fix that.

@rastkojokic

This comment has been minimized.

Copy link

@rastkojokic rastkojokic commented May 4, 2015

I am getting the same response as @duykhoa

@LukasMac

This comment has been minimized.

Copy link

@LukasMac LukasMac commented May 6, 2015

@duykhoa @raskojokic after running script just wait couple seconds and try calling curl http://localhost:9200

I think sleep 5 is needed after service start command

@ranjeet692

This comment has been minimized.

Copy link

@ranjeet692 ranjeet692 commented May 13, 2015

@LukasMac I am getting the curl: (7) Failed to connect to localhost port 9200: Connection refused error when try to call curl http://localhost:9200

@snsn

This comment has been minimized.

Copy link

@snsn snsn commented May 16, 2015

Thank you!

@adriendumont

This comment has been minimized.

Copy link

@adriendumont adriendumont commented May 25, 2015

It throws an error

yeti@Elastico:~$ ./ElasticSearch.sh 1.5.2
-bash: ./ElasticSearch.sh: No such file or directory

but when ran line by line works w/o a glitch. Thanks!

@alfchee

This comment has been minimized.

Copy link

@alfchee alfchee commented Jun 18, 2015

Works very well!! Thanks!!

@gfouvry

This comment has been minimized.

Copy link

@gfouvry gfouvry commented Jun 27, 2015

Well done Mr. Rossi.

@BARJ

This comment has been minimized.

Copy link

@BARJ BARJ commented Jul 7, 2015

Worked fine, but after a restart I get the following error when I run 'sudo service elasticsearch start':

* Starting Elasticsearch Server

touch: cannot touch ´/var/run/elasticsearch/elasticsearch.pid´: No such file or directory

Does anyone has a suggestion to fix this? I already imported elasticsearch data, so reinstalling isn’t an option.

@wprl

This comment has been minimized.

Copy link

@wprl wprl commented Jul 15, 2015

👍

@jjdelc

This comment has been minimized.

Copy link

@jjdelc jjdelc commented Aug 10, 2015

Would suggest adding the bash sha bang on the first line so the script can be ran from other shells.

#!/bin/bash
@BeanMr

This comment has been minimized.

Copy link

@BeanMr BeanMr commented Aug 20, 2015

Great!Thx~~~

@ricardo-rossi

This comment has been minimized.

Copy link
Owner Author

@ricardo-rossi ricardo-rossi commented Aug 28, 2015

@jjdelc: Good idea. done!

@ricardo-rossi

This comment has been minimized.

Copy link
Owner Author

@ricardo-rossi ricardo-rossi commented Aug 29, 2015

Added ElasticSearch 1.7 as default version and Java 8 as default.

@xaniasd

This comment has been minimized.

Copy link

@xaniasd xaniasd commented Aug 31, 2015

thanks! we need to install the package software-properties-common as well (required for add-apt-repository)

@Aldekein

This comment has been minimized.

Copy link

@Aldekein Aldekein commented Sep 14, 2015

Err http://packages.elastic.co stable/main amd64 Packages
404 Not Found [IP: 23.23.106.153 80]

:(

@cesarbarone

This comment has been minimized.

Copy link

@cesarbarone cesarbarone commented Sep 15, 2015

Awesome. Thanks.

@igr

This comment has been minimized.

Copy link

@igr igr commented Sep 27, 2015

404 error

@elchudi

This comment has been minimized.

Copy link

@elchudi elchudi commented Sep 30, 2015

I had to add
sudo apt-get update
before
sudo apt-get install python-software-properties -y

@montyhall

This comment has been minimized.

Copy link

@montyhall montyhall commented Oct 1, 2015

@Aldekein i had the same problem -- managed to work around it by changing

echo "deb http://packages.elastic.co/elasticsearch/${ELASTICSEARCH_VERSION}/debian stable main" | sudo tee -a /etc/apt/sources.list.d/elk.list

to

echo "deb http://packages.elasticsearch.org/elasticsearch/1.7/debian stable main" | sudo tee -a /etc/apt/sources.list.d/elasticsearch-1.7.list

@ddimitrioglo

This comment has been minimized.

Copy link

@ddimitrioglo ddimitrioglo commented Oct 26, 2015

Thanks a lot!

@danny-andrews

This comment has been minimized.

Copy link

@danny-andrews danny-andrews commented Nov 11, 2015

❤️ 💋

@DZielke

This comment has been minimized.

Copy link

@DZielke DZielke commented Nov 16, 2015

I would like to upgrade my ES 0.20.2 and I get an:
couldn't connect to host if I run the Shell-Script.

@lhwparis

This comment has been minimized.

Copy link

@lhwparis lhwparis commented Dec 19, 2015

thanks for the script. what about adding nginx + proxy settings too and maybe optional authentication settings for POST,PUT?

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Jan 4, 2016

Thanks a lot for the complete script

@Paprikas

This comment has been minimized.

Copy link

@Paprikas Paprikas commented Jan 9, 2016

You need to remove or edit regexp for numeric version if you want to install Elasticsearch > 2.
Elasticsearch.sh 2.x will work.

@thoroc

This comment has been minimized.

Copy link

@thoroc thoroc commented Jan 22, 2016

Modified regex as per comment above but I am getting 404 with version 2.x

Failed to fetch http://packages.elastic.co/elasticsearch/2.1.1/debian/dists/stable/main/binary-amd64/Packages  404
Failed to fetch http://packages.elastic.co/elasticsearch/2.1.1/debian/dists/stable/main/binary-i386/Packages  404
@cknoxrun

This comment has been minimized.

Copy link

@cknoxrun cknoxrun commented Jan 26, 2016

Based on this site, the correct repo url is this:

http://packages.elastic.co/elasticsearch/2.x/debian

So your line to add the repo config would be:

echo "deb http://packages.elastic.co/elasticsearch/2.x/debian stable main" | sudo tee -a /etc/apt/sources.list.d/elk.list

@cenan

This comment has been minimized.

Copy link

@cenan cenan commented Feb 26, 2016

Thank you, worked like a charm 👏

@errakeshpd

This comment has been minimized.

Copy link

@errakeshpd errakeshpd commented May 11, 2016

Thank you, worked like a charm

@sentechno

This comment has been minimized.

Copy link

@sentechno sentechno commented May 13, 2016

for 2.x version of elasticsearch
change the line 23 :
if [[ ! "${ELASTICSEARCH_VERSION}" =~ ^[0-9]+.[0-9]+ ]]; then
to if [[ ! "${ELASTICSEARCH_VERSION}" =~ ^[0-9]+.[0-9|x]+ ]]; then

@ulkoart

This comment has been minimized.

Copy link

@ulkoart ulkoart commented Jun 17, 2016

on 16.04 - work, thanks!

@soundaryathiagarajan

This comment has been minimized.

Copy link

@soundaryathiagarajan soundaryathiagarajan commented Dec 30, 2016

Not working for me. Getting this error :

  • Starting Elasticsearch Server sysctl: setting key "vm.max_map_count": Read-only file system

                                                                      [fail]
    

curl: (7) Failed to connect to localhost port 9200: Connection refused

can anyone help here. i am using this shell script mentioned above:

#download and install the Public Signing Key
wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | apt-key add -

Setup Repository

echo "deb http://packages.elastic.co/elasticsearch/5.x/debian stable main" | tee -a /etc/apt/sources.list.d/elk.list

Install Elasticsearch

apt-get update && apt-get install elasticsearch -y

Start ElasticSearch

service elasticsearch start

Lets wait a little while ElasticSearch starts

sleep 5

Make sure service is running

curl http://localhost:9200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment