You read everywhere that setting up and running elasticsearch is very simple. In fact, it is. There are some hurdles to clear when you’re setting it up on Webfaction, however. These instructions will hopefully provide some guidance.
- Install JRE7
- cd ~/share/ (I use share; use whatever folder makes sense for you)
- wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u55-b13/jdk-7u55-linux-x64.tar.gz
- Extract into ~/share/java7 so you end up with ~/share/java7/bin, ~/share/java7/jre, etc.
- Edit ~/.bash_profile, add JAVA_HOME and java bin directory. Here’s an example:
123export JAVA_HOME=$HOME/share/java7PATH=$JAVA_HOME/bin:$PATH:$HOME/binexport PATH
- source ~/.bash_profile
- java -version (should show 1.7x)
- Setup new app in my.webfaction.com
- Name: elasticsearch
- Type: Custom app (listening on port)
- Check the box to open firewall port
- Find new app in the list and see which port WF chose
- Copy the port number
- Download ElasticSearch
- Browse to ~/webapps/elasticsearch
- wget https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.0.0/elasticsearch-2.0.0.tar.gz
- Extract into ~/webapps/elasticsearch so you end up with ~/webapps/elasticsearch/bin, ~/webapps/elasticsearch/config, etc.
- Configure ElasticSearch
- vim ~/webapps/elasticsearch/config/elasticsearch.yml
- Set http.port to the port Webfaction chose when you setup the app
- Set http.host to 127.0.0.1 (if app accessing ElasticSearch is on same server)
- Set network.host to 127.0.0.1 (if app accessing ElasticSearch is on same server)
- Run elasticsearch
If you have a working elasticsearch, you may be wondering how to keep it running all the time, even after you log out.
One solution is to create a simple bash script that starts a process if it’s not already running, and then execute this script regularly via a cronjob.
elasticsearch creates many processes that appear to ps as “java”. This is not helpful. Using -eLf we can see which processes are related to elasticsearch AND java. If there is less than 1 such process, we start elasticsearch, otherwise we do nothing.
- vim ~/bin/elasticsearch_autostart.sh
12345678# This should be executed regularly via a cronjobif [ `ps -u YOURUSERNAME -eLf | grep -i elasticsearch | grep -i java | wc -l` -lt 1 ]thenecho "Starting elasticsearch."/home/YOURUSERNAME/webapps/elasticsearch/bin/elasticsearchelseecho "elasticsearch is running."fi
- chmod +x ~/bin/elasticsearch_autostart.sh
- crontab -e
- Example: (notice we redefine JAVA_HOME and PATH (without using $HOME or $PATH))
12345JAVA_HOME=/home/YOURUSERNAME/share/java7PATH=/home/YOURUSERNAME/share/java7/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/YOURUSERNAME/bin# Make sure elasticsearch is running (every minute)* * * * * /home/YOURUSERNAME/bin/elasticsearch_autostart.sh