{"id":1443,"date":"2015-11-20T07:01:45","date_gmt":"2015-11-20T11:01:45","guid":{"rendered":"http:\/\/agileadam.com\/?p=1443"},"modified":"2015-11-20T08:34:21","modified_gmt":"2015-11-20T12:34:21","slug":"installing-elasticsearch-on-webfaction","status":"publish","type":"post","link":"https:\/\/agileadam.com\/2015\/11\/installing-elasticsearch-on-webfaction\/","title":{"rendered":"Installing ElasticSearch on Webfaction"},"content":{"rendered":"

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.<\/p>\n

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

              Running Automatically<\/h3>\n

              If you have a working elasticsearch, you may be wondering how to keep it running all the time, even after you log out.<\/p>\n

              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.<\/p>\n

              elasticsearch creates many processes that appear to ps<\/span>\u00a0 as “java”. This is not helpful. Using -eLf<\/span>\u00a0 we can see which processes are related to elasticsearch AND java. If there is\u00a0less than 1\u00a0such process, we start elasticsearch, otherwise we do nothing.<\/p>\n

                \n
              1. vim ~\/bin\/elasticsearch_autostart.sh<\/span><\/li>\n
              2. \n
                # This should be executed regularly via a cronjob\r\nif [ `ps -u YOURUSERNAME -eLf | grep -i elasticsearch | grep -i java | wc -l` -lt 1 ]\r\nthen\r\n    echo \"Starting elasticsearch.\"\r\n    \/home\/YOURUSERNAME\/webapps\/elasticsearch\/bin\/elasticsearch\r\nelse\r\n    echo \"elasticsearch is running.\"\r\nfi\r\n<\/pre>\n<\/li>\n
              3. chmod +x ~\/bin\/elasticsearch_autostart.sh<\/span><\/li>\n
              4. crontab -e<\/span><\/li>\n
              5. Example: (notice we redefine JAVA_HOME and PATH (without using $HOME or $PATH))\n
                JAVA_HOME=\/home\/YOURUSERNAME\/share\/java7\r\nPATH=\/home\/YOURUSERNAME\/share\/java7\/bin:\/usr\/local\/bin:\/usr\/bin:\/usr\/local\/sbin:\/usr\/sbin:\/home\/YOURUSERNAME\/bin\r\n\r\n# Make sure elasticsearch is running (every minute)\r\n* * * * * \/home\/YOURUSERNAME\/bin\/elasticsearch_autostart.sh<\/pre>\n

                 <\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"

                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.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[76],"tags":[271],"_links":{"self":[{"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/posts\/1443"}],"collection":[{"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/comments?post=1443"}],"version-history":[{"count":13,"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/posts\/1443\/revisions"}],"predecessor-version":[{"id":1457,"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/posts\/1443\/revisions\/1457"}],"wp:attachment":[{"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/media?parent=1443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/categories?post=1443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/agileadam.com\/wp-json\/wp\/v2\/tags?post=1443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}