Tech Tips

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"
    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
    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
    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 to (if app accessing ElasticSearch is on same server)
    4. Set to (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/
  2. chmod +x ~/bin/
  3. crontab -e
  4. Example: (notice we redefine JAVA_HOME and PATH (without using $HOME or $PATH))


  • John Henry Donovan

    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

  • Brad Buran

    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.

Leave a Reply

Your email address will not be published.