zondag 21 maart 2010

Grails application hosting on a Linux VPS

After some time of development the Agile Tracking Tool is now live at www.agiletrackingtool.com. This blog shows an overview of virtual hosting providers for java web-applications and my configurations steps for the linux host.

Finding a host provider

Where to start when selecting a host provider for a java based web application? Some time ago I started doing some research on the topic. One of the options would be direct hosting of a grails web application by the cloudfoundry.com. A nice blog by Marcel Overdijk describes this. This is however a bit more expensive (roughtly $75 a month) than a vps (starting at $20+ a month). Another option would be google app engine. My impression is that this however will take some time to further mature.
At Grails.org there is a nice overview of hosting providers. This blog and comments showed valuable information. On the grails mailing list the following names kept popping up (initial impression in braces):
Starting at around $20-22 per month (250 Mb).

Finally I selected eapps.com. Reasons: it was recommended to me by a fellow enthusiast at a nlgug meetup, it was on my short list, good reviews, their support pages are helpful (mentioned grails), they are in business since 1996. The nice thing about a provider in the US that their office-hours are my evening hours. 

Tip: If you know a nice grails website just use whois to find out who-is hosting.

Creating the account
After experimenting with some home virtual linux servers (virtualbox.org) it was time to take the plunge. On Friday evening I registered for an account at www.eapps.com. I selected a Linux VPS with 432 Mb memory. Postings already mentioned that 250 Mb is the minimum for running Grails apps.

After 10 mins I already received a call to verify my account details: "I am looking for B....".  My acount would be live in 5 minutes... Now that's fast. It indeed popup up at the servers administration page. Using the experience from configuring Linux servers at home I had my first grails application live within 2 hours after the account request.

Installing applications 













From the web-application page I selected to install the following applications:
  • Apache (webserver)
  • Tomcat 6 + mod_jk plugin (webserver for java web applications).
  • Mysql 5
  • Groovy + Grails (didn't expect that one).
  • Subversion (get my code from the repository)

    Configuring
    Logging into the server is done via ssh. I use vim (or emacs) to edit files.





      I changed the MySql configuration to use InnoDB engine to support transactions. Adding the following line to /etc/my.cnf  in section [mysqld] does the trick:
      default_storage_engine = InnoDB

      More information can be found on the mysql support page.


      The eapps support page for tomcat and mod_jk were very useful.

      Adjust /opt/tomcat6/conf/tomcat-users.xml to change the default (so easy to guess) password.

      Accessing the Tomcat server via the Apache webserver is done by the mod_jk plugin as described over here. After some time I finally figured out that I just had to add one line to grails web-application accessible via www.agiletrackingtool.com/mysecret. (mysecret are other 'secret' characters known to those one joining for early testing).














      Once the mod_jk configuration is working you can disable tomcat listening to port 8080 so the tomcat server can not be accessed directly from the outside (/opt/tomcat6/conf/server.xml):

      <!-- commented out
      <Connector port="8080" protocol="HTTP/1.1"
                 connectionTimeout="20000"
                 redirectPort="8443" />
      -->


      Tomcat JNDI
      Update March 24: The issue seems to be fixed using this solution. No broken Mysql connections this morning. 
      Update March 23: The Mysql brokken connection issue is still present. Even after setting 'autoReconnect=true'. The next step will be checking out this advise. Any help or suggestions are welcome! Very unpleasant issue... 
      Update March 21: After the web site is not used for a longer time a mysql connection error is reported (see issue). I tried to resolve the issue by configuring jndi on tomcat. Adjust (/opt/tomcat6/conf/context.xml) and and the "Resource" section:
      <Context>
      ....
      ..
      <Resource name="jdbc/agiletracking"
                  auth="Container"
                  type="javax.sql.DataSource"
                  username="mysecret"
                  password="also"
                  driverClassName="com.mysql.jdbc.Driver"
                  url="jdbc:mysql://localhost/agiletracking?autoReconnect=true"
                  maxActive="100"
                  maxIdle="8"/>

      ..
      ...
      </Context>

      JNDI in your grails application is configured in your DataSource.groovy:
      production {
        dataSource {
         dbCreate = "update"
         jndiName = "java:comp/env/jdbc/agiletracking" 
        }
       }

      Also make sure that /opt/tomcat6/lib contains the mysql-connector-java.jar (already installed by eapps.com).
      Update Jan 2011: Interestig link on how to configure mysql timeout on Dzone using DataSource.groovy (see comment).

       Tomcat memory
      By default tomcat is configured to use 64 Mb. Performance however dramatically increased when setting it to the recommended maximum size of 192 Mb  in /etc/tomcat6/tomcat.conf):

      # Initial Java Heap Size (in MB)
      wrapper.java.initmemory=192
      # Maximum Java Heap Size (in MB)
      wrapper.java.maxmemory=192

      This gives a great performance boots. With 64 Mb my web application was much slower as compared to running it on my local machine. With 192 Mb the performance feels much snappier.

      When idle Tomcat says: 
      Free memory: 110.83 MB Total memory: 185.62 MB Max memory: 185.62 Mb. 

      The Linux memory use ('free -m') shows:
                    total      used       free
      Mem (Mb):      432        299        132  

      Deployment of your grails war file is simple done by copying your file (sftp) to '/opt/tomcat6/webappsand restarting tomcat.

      That's it. Configuring my web-application on a vps turned out to be quite smooth going. Over time more settings will be tuned (mysql database size), but this proved to be a nice start.

      33 opmerkingen:

      1. Updated with additional info on JNDI configuration.

        BeantwoordenVerwijderen
      2. Hi,

        Great post. Actually I'm starting a grails application and I followed all the steps successfully (it's not always that easy with internet posts), including purchasing a VPS at eapps!

        Did you definitely solve the "broken Mysql connections problem" with the march 24th update?

        Regards.

        BeantwoordenVerwijderen
      3. Hi OrÁCuLO,

        The broken mysql connection problem does no longer occur.

        Kind regards,
        Ben

        BeantwoordenVerwijderen
      4. Linux supported different platform. You can easy to handle the server. It's allocated space is very high compare to windows hosting. Windows hosting Cpanel access is very tough.website hosting

        web hosting

        BeantwoordenVerwijderen
      5. Linux hosting is really better then window hosting because Linux hosting has more feature comparing window hosting.Register Domain

        domain registration india

        BeantwoordenVerwijderen
      6. Hi,

        thanks for sharing your opinion. I would like to tell you that i am taking Linux hosting and Java hosting services from Net4 and I love the Linux hosting because it is more reliable and secure as compare to windows hosting.

        BeantwoordenVerwijderen
      7. Glad to visit this professional blog... I would love to learn more and more about technical and programming related things.. Great work! cheapest domain registration india

        BeantwoordenVerwijderen
      8. Your blog is brilliant here.As it explains more things about its topic.Really too knowledgeable content is presented.Thanks for this post.
        web designing company

        BeantwoordenVerwijderen
      9. Actually linux operating system supports different platforms. You can do web designing using linux and it is very easy to use Linux Web Hosting.

        BeantwoordenVerwijderen
      10. Hi ! this is nice article. i am always suggest you to choose Vps Server. Because this is best and gives maximum performance.
        Thanks

        BeantwoordenVerwijderen
      11. I want to say that this post is astonishing, nice written and comprise about all important info’s. I would like to see more posts like this.
        linux vps

        BeantwoordenVerwijderen
      12. The blog post is astounding for selecting a host provider which helps in improving website efficiency in all means like maximum uptime, bandwidth etc.

        BeantwoordenVerwijderen
      13. Your blogs and its stuff magnetize me to return again n again. Compila secure email providers

        BeantwoordenVerwijderen
      14. Whether you’re a beginning webmaster or a more experienced digital business owner, you need a dependable customer support. Things can and will go wrong on your website’s backend, but getting support when you need it can go a long way toward minimizing any potential damage to your business.
        Domain Registration Bangalore

        BeantwoordenVerwijderen
      15. Hi,
        I like your post very much as it contains very useful information that helps in one's real life situations.
        Cheap hosting

        BeantwoordenVerwijderen
      16. Heys i was looking for Linux web hosting in india , as well as low cost web hosting.

        any suggestions

        BeantwoordenVerwijderen
      17. Appreciate you guys you are doing a really terrific job.

        Learn More About Kinken Hikaku

        BeantwoordenVerwijderen
      18. Real Hosting Reviews is the best place to find top hosting companies reviews in India and enlist in front of you to make your decision easy.These companies can be considered being most dependable and the cheapest web site hosting organizations.
        hosting review | web host reviews

        BeantwoordenVerwijderen
      19. Wow! It is an excellent post. I was checking continuously this blog, and I am impressed! Here you discuss the Linux VPS it's a really very good information for me. Because I want to host my business, it helps of legal rights and permission, a website can become a unique. Some days before I found a site mywindowshosting.com is a best window hosting site, and It provides verity types of hosting. Thanks a lot.........................

        BeantwoordenVerwijderen
      20. Thanks for sharing this information here, Superb blog and informative post you have shared.. iPage review

        BeantwoordenVerwijderen
      21. Very nice post! I really appreciate your work. Good to know about the topic wish to know more about cloud servers. keep it up :-)

        BeantwoordenVerwijderen
      22. Deze reactie is verwijderd door de auteur.

        BeantwoordenVerwijderen
      23. Deze reactie is verwijderd door een blogbeheerder.

        BeantwoordenVerwijderen
      24. Amazing Blog! You share really very useful information about VPS hosting. Thanks for sharing such good information with us.

        BeantwoordenVerwijderen
      25. Thanks for sharing this incredible and unique content. This would help many like me in getting the Ipage hosting

        BeantwoordenVerwijderen
      26. Incredible post and very infiormative points you havee shared about this concept. free domain registration

        BeantwoordenVerwijderen
      27. Thank you for the helpful post. I found your blog with Google and I will start following. Hope to see new blogs soon
        linux vps hosting

        BeantwoordenVerwijderen
      28. I appreciate your effort for providing such useful and informative article, Thank you for updating. Snap our tags to know more about VPS server.

        Web Hosting companies in India | VPS Hosting India | VPS Hosting Plans | VPS Hosting companies India

        BeantwoordenVerwijderen
      29. Deze reactie is verwijderd door de auteur.

        BeantwoordenVerwijderen
      30. this post are enlightening in Classified Submission Site List India . An obligation of thankfulness is all together for sharing this outline, Actually I found on various domains and after that continued with this site so I discovered this is hugely improved and related.
        https://myseokhazana.com/

        BeantwoordenVerwijderen