Introduction
This article describes how to deploy your applications in the HP Public Cloud. This article does not stress much on how you develop your application, all you need at the end is a WAR file to upload to the Cloud.
Background
This article does not expect readers to have any prior knowledge on Cloud computing, a basic knowledge on developing/deploying Java web services would be beneficial, but not mandatory. I have covered some basic Linux commands to install packages and configure the application.
Develop your Java Web Service/Application
You can use any of your favorite ways to develop your Java web Service or any application, using Spring, Plain JSP/Servlet, etc. We have used Guice and Jersey framework to develop a lightweight RESTful web service in our case. Once the application is developed, you can deploy the WAR file in HP Cloud.
HP Cloud Console
Step 1: Set up your cloud account from HP Cloud Sign-Up Page (currently, it is https://account.hpcloud.com/signup)
- Provide your personal details
- You will get an e-mail and activate your account with the link in your e-mail
- Link your account with a credit card (don’t worry, they will not charge, it is free for 3 months!!!)
Step 2: Log in to the cloud console (currently it is https://account.hpcloud.com/services, this may change in the future)
Step 3: Create Security Group: HP Uses public key cryptography, you need to create a security group and assign to the server
By default, Region: US West AZ 1 would be activated, if not, click on “Activate” button, if yes, click “Manage” button.
The protocols to configure are TCP, UDP and ICMP. Click on “Security Groups”, click “ New Security Group”, provide name (I prefer to use suffix sg
for security group, sg_<project />_
<dev>) and Description, now click “Edit” button of the Group, select protocol “tcp” and From Port/ICMP Type as 0 and To Port/ICMP Code as 65535, leave CIDR IPs as the default value: 0.0.0.0/0, Click “Add”, same way add UDP as well for 0 to 65535. ICMP is used for ping and ICMP uses no port, so enter from Port: -1 and to Port: -1
Step 4: Create Key Pair
Enter Key Name, I prefer to suffix key pair with kp. Click ‘Create Key’ button , your key pair will be created and a page will show the private key, download the private key and keep the pem file in a secure place in your local machine, we need this later on to connect using SSH.
Step 5: Create a Linux instance
Click on “Servers” tab, click “Create a new server from an image”, provide server name say ws_dev01_sample
, source image as Linux, Ubuntu Lucid 64 bit, assign the security group and key pair you created in Step 3 & 4and provide a tag , say “tag_dev_sample
”, click “Create” button and your server will be created shortly and note the public IP.
Step 6: Connect to the Linux instance using SSH
I prefer Bitwise tunnelier (http://www.bitvise.com/tunnelier), download and install the Tunnelier. Open “Bitwise SSH Client” from your desktop, select “Login tab”, provide host as the public IP of the Linux instance you created in Step 4 and leave port as 22. Provide username as “ubuntu”, click “Use Key Pair Manager” button, click on Import button and select the pem file you obtained from Step#4. Select initial method in Login TAB as “public Key Slot -1” and click “Login”. Tunnelier will load your private key and open a linux command prompt and filezilla to transfer files between your Linux machine and your local machine.
Step 7: Deploy your WAR file
Type sudo –s
to obtain root privileges
- Install and Configure Oracle or Open JDK, Open JDK will be present by default.
- sudo apt-get update (which will update the system with latest packages)
- apt-get install openjdk-6-jdk
- export JRE_HOME=/usr/lib/jvm/java-6-openjdk/jre
- Verify java –version & javac –version
- Install Tomcat web server
- mkdir /usr/tomcat
- cd /usr/tomcat
- wget http://mirror.sdunix.com/apache/tomcat/tomcat-7/v7.0.42/bin/apache-tomcat-7.0.42.tar.gz
- tar xvzf apache-tomcat-7.0.42.tar.gz ( to extract the tar file)
- apache-tomcat-7.0.42/bin/startup.sh(to start the Tomcat)
- Verify by typing <public>:8080 from your local machine’s web browser, if the Tomcat home page appears, we are on track, else check your
JRE_HOME
is set correctly, it should point to jre folder, which you can find out by the command: find / -name jre
, if still does not work, check the tomcat log at apache-tomcat-7.0.42/log folder, there might be JDK and Tomcat versions mismatch.
- Deploy your WAR file
- Upload your war file to /home/ubuntu folder using Filezilla
- Shutdown the Tomcat instance, type /usr/tomcat/ apache-tomcat-7.0.42/bin/shutdown.sh
- Copy the war file to webapps directory cp /home/ubuntu/sample.war /usr/tomcat/apache-tomcat-7.0.42/webapps
- Start tomcat, apache-tomcat-7.0.42/bin/startup.sh
Now your application is deployed in HP Cloud!!!
Step 8: Create your Image or Snapshot (optional)
Now your application is up and running in a single instance, you can create an Image/Snapshot and can spawn multiple instances on the fly from an image. You don’t have to do all the tedious configurations any more.
- Click on “Images” TAB
- Provide Image Name
- Select from Server as your current instance
- Provide Description and press Create, your image will be created.
Step 9: Create a new instance from an Image (optional)
- Click “Servers” TAB
- Click “Create new Server from an Image”
- Provide Server name and select Source Image as snapshot you created in Step#7
- Use same or different Flavor/Security Group/Key Pair
- Press Create and your new instance is ready, which is an exact replica of the first instance
- Refer to Step #5 and Log in to the new instance using SSH and you will notice all packages like JDK, Tomcat, My SQL, etc. are already there and your application is present in webapps directory, start the tomcat server
- Your new instance is ready!!!
Step 10: Create Load Balancer (optional)
Since you have many instances, it needs to be stacked behind a load balancer. Enable Load Balancer if not already done and create new one with ROUND ROBIN or LEAST CONNECTIONS algorithm
- Click Add Node, enter public IP address of instance 1 and port as 8080, Click Create Node
- Repeat the same step for other instances
- Access the application using http://<load>/<application>
Points of Interest
HP also provides many other Cloud Services, I found Database as a Service (DBaaS) interesting. You can activate this service and they will provide a REST based mechanism to create database. Once you create the database, you can connect using My SQL Workbench or any similar tool and create tables, SPs, etc. HP Cloud is an Openstack implementation. Open, web-based standards ensure portability and prevent vendor lock-in. Open source-based architecture and OpenStack APIs mean you’re free to choose your development platform and language. Only pay for your allocated instances on an hourly basis. There are no minimum charges or lock-in periods, and setting up your account is free. We were using Amazon Cloud (AWS) earlier and migrated to HP Cloud and it worked out much cheaper.