Installing ElasticSearch on Webfaction

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.

  1. Install JRE7
    1. cd ~/share/  (I use share; use whatever folder makes sense for you)
    2. 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
    3. Extract into ~/share/java7 so you end up with ~/share/java7/bin, ~/share/java7/jre, etc.
    4. Edit ~/.bash_profile, add JAVA_HOME and java bin directory. Here’s an example:
    5. source ~/.bash_profile
    6. java -version  (should show 1.7x)
  2. Setup new app in my.webfaction.com
    1. Name: elasticsearch
    2. Type: Custom app (listening on port)
    3. Check the box to open firewall port
    4. Save
    5. Find new app in the list and see which port WF chose
    6. Copy the port number
  3. Download ElasticSearch
    1. Browse to ~/webapps/elasticsearch
    2. wget https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.0.0/elasticsearch-2.0.0.tar.gz
    3. Extract into ~/webapps/elasticsearch so you end up with ~/webapps/elasticsearch/bin~/webapps/elasticsearch/config, etc.
  4. Configure ElasticSearch
    1. vim ~/webapps/elasticsearch/config/elasticsearch.yml
    2. Set http.port to the port Webfaction chose when you setup the app
    3. Set http.host to 127.0.0.1 (if app accessing ElasticSearch is on same server)
    4. Set network.host to 127.0.0.1 (if app accessing ElasticSearch is on same server)
  5. Run elasticsearch
    1. ~/webapps/elasticsearch/bin/elasticsearch

Running Automatically

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.

  1. vim ~/bin/elasticsearch_autostart.sh
  2. chmod +x ~/bin/elasticsearch_autostart.sh
  3. crontab -e
  4. Example: (notice we redefine JAVA_HOME and PATH (without using $HOME or $PATH))
     
Tagged with:
Posted in Tech Tips
5 comments on “Installing ElasticSearch on Webfaction
  1. Eduardo says:

    Thank you very much Adam! I struggled with this a lot. I got it running now!

  2. Thanks for the tips. Did you have any trouble with a tmp directory when trying to start elasticsearch?

    I’m getting an error like this.

    unable to load JNA native support library, native methods will be disabled.
    java.lang.UnsatisfiedLinkError: /tmp/jna-1971603474/jna7540736777577824257.tmp: /tmp/jna-1971603474/jna7540736777577824257.tmp: failed to map segment from shared object: Operation not permitted

    And I have tried

    ~/webapps/elasticsearch/bin/elasticsearch -Djna.tmpdir=~/tmp

    from elasticsearch docs but to no avail.

    Any thought on this would be helpful. Thanks

  3. Brad Buran says:

    FYI, one of my sites got moved to a new Webfaction server with many more CPU cores. Eleasticsearch determins how many threads to generate based on the number of cores the serve has. As a result, Elasticsearch was spawning way too many threads (exceeding the maximum limit of 600 per user on the server). To get around this, add the following line to your configuration.yml file:

    processors: 4

    Elasticsearch will then limit the number of threads it creates to a number that’s more reasonable for the shared hosting plan.

  4. Jesse Hodges says:

    Thanks so much for this! It’s very useful.
    I think, however, that creating a webfaction app and opening a port is not necessary if you’re accessing locally.

Leave a Reply

Your email address will not be published. Required fields are marked *

*