Powered By Blogger

Wednesday, April 30, 2014

DEPLOYING YOUR FIRST WEBAPP ON A CLOUD SERVER USING JOYENT CLOUD

Remote tools needed: WINSCP Remote Login Client, Putty Public/private Key generator, Putty Remote Client,
Cloud Environment: Joyent Cloud
Applications needed on the Cloud environment: Joyent Smart OS, Apache Http Server, Tomcat Application Server (calling out only the applications that I used).
Deployment Duration: 5Mins
Application Language: Java EE
Programming level: Easy - Medium

First time cloud app developers will find this article very direct; describing exactly and only what is needed to deploy your app using the tools/ in the cloud environment described above. For programmers deploying a small test cloud app that needs to go to test production environment quickly and do not have the luxury of hiring a specialized server administrator or not willing to invest in all the server deployment learning curve this article would be a step by step guide to have your app running accessible to the world in 5Mins.
More than anything else this post serves to remind me of how I deployed my first cloud application.

With all the formalities out of the way let’s delve into a little background.
Early in 2012, a friend called me up with a software idea He had planned. An App he was sure would change the way people bought and sold in the world at the time. Happily; like most software programmers, filled with the rush of what my new baby application would do the world, I jumped right into it.
From when I got the call till when I finally deployed the test App took close to 3 months.  Most of this time was spent trying to figure out where my server files were on the cloud servers and how they would all connect to serve my files. The cloud environment “to me” was a different part of town from coding with Netbeans and deploying automatically on glassfish or apache. Maybe it is the same for you too; or not.
  1. To begin, you will need to get access to some cloud resource – disk space, OS, server application etc. I used Joyent (www.joyent.com). Signin, setup your personal information and information for billing.
  2. From the list of “instances”, select Java. This particular “instance” had all the applications I needed for my deployment – SmartOS (operating system), Apache Http Server (web server) and Apache Tomcat (Java Application Server).
    • NB:
      • Joyent has different instances pre-setup and ready to accept your application.
      • Look through the different instances to see the one that best suits your application need.
      • An instance is a combination of applications (e.g Apache Tomcat, Hadoop, Apache Cassandra etc), Operating System, disk space, available on a particular cloud segment. An instance is usually available for a fee. If your application is designed for scalability, you can increase instances to hold different parts of your application to increase throughput and availability. Your on will run on one or several instances each having a unique IP address.
3.  Download and install PuTTY and PuTTYgen. PuTTYgen will help you create public and private keys needed to login to your cloud environment securely. PuTTY will be used to install and manage third party applications installed on your cloud. Both are available for download at www.putty.org.


4.  Click on the link below from Joyent Wiki to show you how to generate Public and Private Keys using PuTTYgen and also to upload this Key to your Joyent Cloud. http://wiki.joyent.com/wiki/display/jpc2/Manually+Generating+Your+SSH+Key+in+Windows#ManuallyGeneratingYourSSHKeyinWindows-GeneratinganSSHKey.

5.  Using the private key you generated, login to your machine using WINSCP. WINSCP gives you the same windows feel of the folders on your cloud.

6.  On the cloud folder system, navigate to where your Httpd.conf file is located. This is usually at “/opt/local/etc/httpd/httpd.conf”. this file contains the configuration of your Apache Http Server. Include the following lines of codes at the last line:


NameVirtualHost *:80

LoadModule proxy_module /opt/local/lib/httpd/mod_proxy.so
#Addmodule mod_proxy.c #Uncomment this line by removing the first Hash if you are using Apache Server less than version 2.2

ProxyPass / appName http://localhost:8081/ appName
ProxyPassReverse /appName http://localhost:8081/appName
    • NB:
      • appName is the name of your application. In Java EE, you would know this as the name of your distributed application or the name you have set to trigger the welcome page when you deployed your application locally on your system.
      • The directives above will ensure that your Webserver (Apache Http) receives all requests coming in from the internet and directs the requests to your application server (Tomcat). The Webserver will also serve all responses from your application server.
7.  Configure your application server to receive and respond to responses from the webserver by including the directives below in your tomcat server.xml file. The Server.xml file should be located at “/opt/local/share/tomcat/conf/server.xml

Connector port="8081" proxyName="www.appName.com" proxyPort="80" /

NB: (remember to put the connector directive between <>)

8.  With this done. Restart your application server and webserver. To do this, login using PuTTY. Issue the following command at the command prompt

“svcadm restart svc:/pkgsrc/apache”
“svcadm restart svc:/pkgsrc/tomcat”


  • NB: Issue both lines one at a time.

This concludes your application deployment. You can confirm that your application has been successfully deployed by visiting your page using your external IP address forward slash your application Name e.g.

72.2.119.100/appName

Feel free to comment below; questions related to this post or to general enterprise application development using Java.


No comments:

Post a Comment

Thanks for leaving your comment.