In the previous post, I described how to use the vmc command-line tools to deploy a Ruby application to VMware’s cloud. In this post I will describe the steps I took to create and use a private cloud (based on the instructions found on github). If you have an account with Cloud Foundry, you can download a pre-built Micro Cloud Foundry, but by following these instructions you will have an environment similar to what I used in this project.
Creating a Micro Cloud Foundry
On a clean MacBook Pro running Snow Leopard (10.6.8), I downloaded an ISO to install 64-bit Ubuntu Server 10.4.3, then I installed VMware Fusion 4.1.1. I launched Fusion and started the process to create a new virtual machine:
- Introduction: I clicked the “continue without disk” button.
- Installation Media: I chose the disk image for Ubuntu Server.
- Operating System: I left the defaults of Linux and Ubuntu 64-bit.
- Linux Easy Install: I accepted the default user and specified a password (‘swordfish’).
- Tools Download: I downloaded the tools.
- Finish: I accepted the defaults (1 GB RAM, 20 GB hard disk, NAT networking).
- Save As: I named the virtual machine ‘My Cloud’.
- A few minutes later the server started and gave a login prompt.
It seems that Fusion’s easy install of Ubuntu does not get the keyboard properly mapped, so I entered the following command:
sudo dpkg-reconfigure console-setup
I selected the ‘Dell 101-key PC’ keyboard (pressing the <D> key repeatedly since the arrow keys didn’t work), and accepted the other default settings. I then entered the following commands (based in part on the instructions here) to update and install a few needed packages:
sudo apt-get update sudo apt-get upgrade sudo apt-get install vim sudo apt-get install openssh-server sudo apt-get install curl
Next, I entered the command to setup this Ubuntu server as a VMware Cloud Application Platform (VCAP):
bash < <(curl -s -k -B \ https://raw.github.com/cloudfoundry/vcap/master/dev_setup/bin/vcap_dev_setup)
This process took some time (an hour?) and when it finished it showed a message describing how to start Cloud Foundry:
We now have the confusion of dealing with two machines (one real and one virtual) and so need to be careful to identify which one we mean in the subsequent instructions:
- Client: A MacBook Pro is my development machine, and a “client” with respect to “the cloud.” For this project, I interact with the client primarily using Terminal (using “a shell on the client”), but also using a web browser (Safari, Firefox, or Chrome) and the Finder.
- Server: VMware Cloud Application Platform (VCAP) runs on 64-bit Ubuntu in a Fusion virtual machine on the Mac, and provides “the cloud services” on a “Micro Cloud.” I interact with the server primarily using ssh in a Terminal session (“a shell on the server”), but occasionally using the console visible in Fusion. This micro cloud offers the same developer experience that a public cloud (such as appfog.com) should provide, so you can practice your deployment without making your application public.
In order to interact with the server using ssh in a Terminal session, we need to know the server’s IP address. On the server console, I entered the following command:
ifconfig eth0 | grep inet
The first line gives the IPv4 address (in my case, 192.168.10.128). On the client, I then entered the following command:
sudo vim /etc/hosts
to edit the client’s hosts file and add the following line:
You should, of course, use the IP address you got from the server. Then, from a client shell, I entered the following to get a shell on the server:
I entered ‘yes’ to add the RSA key and then entered the password I defined when I built the server (‘swordfish’). To simplify my server commands, I added an alias using the following commands on the server:
echo "alias vcap='~/cloudfoundry/vcap/dev_setup/bin/vcap_dev'" >> ~/.bashrc source ~/.bashrc
On the server, I entered the following command:
This gave me some debugging information, and ended with a list of services that all show as “RUNNING.”
Targeting the Micro Cloud
From the client we interact with a cloud using vmc, the command-line interface in a client shell. When we were using the public cloud, the “target” was api.cloudfoundry.com; with the micro cloud we use api.vcap.me as the target. VMware has registered the domain vcap.me and configured the DNS servers to map that domain (and all its subdomains) to 127.0.0.1 (or localhost). Of course, the micro cloud is not at 127.0.0.1 from the perspective of the client, so we need to establish a tunnel from port 80 on the client to port 80 on the server. First, we need to ensure that port 80 is not in use. On my Mac, I opened System Preferences, selected Sharing, and then made sure that ‘Web Sharing’ is unchecked. With port 80 available, I entered the following command in a client shell (replacing USER with the Ubuntu user defined during the initial setup):
sudo ssh -L 80:mycloud:80 USER@mycloud -N
This command establishes a tunnel from port 80 on the client to port 80 on the server, and the shell hangs until the tunnel is terminated (e.g., with <Ctrl>+<C>). To show that the cloud is there and responding, I entered http://api.vcap.me/info in a client web browser and observed the JSON data returned. In another client shell, I entered the following vmc commands (you should provide your own email!):
vmc target api.vcap.me vmc info vmc add-user --email firstname.lastname@example.org --passwd swordfish vmc info
With the micro cloud up and running, I tried deploying my trivial Ruby application (described here) using the following client commands:
cd ~/env vmc push
In response to the questions, I named the application ‘jfoster-env’ and asked for 2 instances; otherwise I accepted the defaults. At this point (see notes below) I was able to see the application in a web browser at http://jfoster-env.vcap.me/ and http://jfoster-env.vcap.me/env and I tried the various vmc commands at the end of this post. The behavior was generally consistent with the public cloud.
Note 1: The first time I tried a push the response was “Error: Application [jfoster-env] failed to start, logs information below. Error 306: Error retrieving file ‘/logs/err.log.” I believe that this means that the application failed to start in time, and that when the system went to look for an error log, there wasn’t one. The application actually was running and responded to HTTP requests. Also, ‘vmc apps’ and ‘vmc stats jfoster-env’ showed the application running and ‘vmc restart jfoster-env’ reported success.
Note 2: The response to ‘vmc logs jfoster-env’ included “Error 306: Error retrieving file ‘logs/startup.log.” I found someone who said, “The file ‘logs/startup.log’ isn’t always generated, so the error returned by vmc can be a red herring.”
We have built an Ubuntu server and configured it as a private micro cloud. We used it as a target for our application and were able to use it in place of the public cloud. Next we will investigate adding a new runtime and framework to Cloud Foundry.