Creating Prebundled Machine Images for the Cloud

by Kiran C. Nair

Learn how to create a custom virtual machine image prebundled with Oracle WebLogic Server 11g and Oracle Database XE, as well as the basics of creating init scripts and configuring services to run at user-defined runlevels

Platform virtualization is used by cloud service providers such as Amazon Web Services (AWS) to provide remote access to software running on shared hardware infrastructure. Platform virtualization uses the concept of machine images, which can be hosted virtually on remote platforms, allowing users unrestricted access to the underlying infrastructure.

In this tutorial, you will see how to create a custom virtual machine image prebundled with Oracle WebLogic Server 11g and Oracle Database 10g Express Edition (XE). You will also learn the basics of creating init scripts and configuring services to run at user-defined runlevels. This will enable the created images to fully utilize the on-demand scalability of cloud computing; prebundled applications or services will be able to start servicing requests as soon as the instance starts up.

The process followed in this tutorial is a generic one. The prebundled applications and utilities may be customized according to user preferences or demands. It should also be noted that the created images are not restricted to AWS but are fully compatible with any cloud that uses Xen as the hypervisor layer (for example, Eucalyptus Open Cloud).

(Note: Oracle certifies/supports and licenses many of its products on AWS and also supplies free, prebuilt virtual machine templates for several Oracle products on Oracle Enterprise Linux; see the Cloud Computing Center for a full list.)

Before You Start

This tutorial provides a step-by-step guide to the creation of custom images—including installing applications, configuring the images, writing startup scripts, and configuring services to run at specified runlevels—so that these images are ready to be deployed onto a cloud infrastructure. In this tutorial, we will:

Mounting the Base Image Using Loopback

Resize the image file

The base image file may not have sufficient storage space for accommodating custom applications, so we may need to resize it. We can resize it to suit our own requirements. Here we will resize a 1GB image to 4GB:

Mount the image file through loopback

The resized image file can now be mounted into a local mount-point so that it can be modified and configured according to our requirements. We will also mount the local processor into the ./mount-point/proc folder so that it functions as the temporary processor for the duration of our exercise.

Install additional packages

The mounted base image will contain the minimal set of packages needed to support a root file system (Centos 5.2 in our case). Additional packages can be added to provide extra functionalities. Here we will install three sets of additional packages: vsftpd Server (a popular FTP server for UNIX like systems), vi (the popular command line text editor), and dependencies required for Oracle Database XE.

Working Inside chroot jail

Installation of Oracle Database XE and Oracle WebLogic Server will be done from inside the image mount-point. Before doing so, these installers and necessary files need to be moved into the necessary folder inside the image mount-point. We will create a folder (./centos/root/install) inside the image mount-point.

Change root to mount-point

The image mount-point (./centos) that has been created contains all the files and directory structure needed for a fully functioning base Linux system. We can now reroot into this directory using the chroot command. This directory is called "chroot jail."

Installing and Configuring Oracle Database XE

Install Oracle Database XE RPM

We will now install Oracle Database XE from the installer present in /root/install in the jail.

bash-3.2# rpm -Uvh /root/install/oracle-xe-univ-10.2.0.1-1.0.i386.rpm
Preparing... ########################################### [100%]
1:oracle-xe-univ ########################################### [100%]
Executing Post-install steps...
You must run '/etc/init.d/oracle-xe configure' as the root user to
configure the database.
bash-3.2# rm -rf /root/install/oracle-xe-univ-10.2.0.1-1.0.i386.rpm
5.2 Configure Oracle Database Express Edition by running /etc/init.d/
oracle-xe configure
Run /etc/init.d/oracle-xe configure to open the command-line Oracle
configuration wizard.
Remember to enter "y" for the question "Do you want Oracle
Database 10g Express Edition to be started
on boot (y/n) [y]:" if you want the Oracle Database Express Edition
service to be started at instance boot.
#Configure Oracle XE
bash-3.2# /etc/init.d/oracle-xe configure
Oracle Database 10g Express Edition Configuration
-------------------------------------------------
This will configure on-boot properties of Oracle Database 10g Express
Edition. The following questions will determine whether the database should
be starting upon system boot, the ports it will use, and the passwords that
will be used for database accounts. Press <enter> to accept the defaults.
Ctrl-C will abort.
Specify the HTTP port that will be used for Oracle Application Express [8080]:8080
Specify a port that will be used for the database listener [1521]:1521
Specify a password to be used for database accounts. Note that the same
password will be used for SYS and SYSTEM. Oracle recommends the use of
different passwords for each database account. This can be done after
initial configuration:
Confirm the password:
Do you want Oracle Database 10g Express Edition to be started on boot (y/n) [y]:y
Starting Oracle Net Listener...Done
Configuring Database...Done
Starting Oracle Database 10g Express Edition Instance...Done
Installation Completed Successfully.
To access the Database Home Page go to http://127.0.0.1:8080/apex

Add required environment variables accessible at startup

Scriptlets that are run at instance startup are contained in rc.local. Necessary environment variables like ORACLE_BASE and ORACLE_HOME need to be present for Oracle Database XE to access these at runtime.

Oracle WebLogic Server will now be present under /root/Oracle/Middleware/.

Unpack the pre-created domain into /user_projects/domains/

We will be using a domain created on a local machine instead of manually creating one. A domain can also be manually created by using the script /root/Oracle/Middleware/wlserver_10.3/common/bin/config.sh.

This domain is now ready to be started using the script /root/Oracle/Middleware/user_projects/domains/CloudDomain/bin/startWebLogic.sh.

Create init Script for Starting Domain at Instance Startup

On-demand scalability provided by the cloud necessitates application startup during instance boot, with minimal user interaction. Once a new instance is booted up on the cloud, it should immediately be able to start servicing requests coming to it. For custom applications to fully utilize this capability, they need to be set as services, initialized and running at system boot-up.

Let us create an init script for starting our Oracle WebLogic Server Domain at instance startup. In the init script shown below, I have taken /root/Oracle/Middleware/user_projects/domains/CloudDomain/bin/startWebLogic.sh as the script to start the domain and /root/Oracle/Middleware/user_projects/domains/CloudDomain/bin/stopWebLogic.sh as the script to stop the domain. The script created is named as initWeblogic and is put into the /etc/init.d/ directory.

This will enable the services initWeblogic, oracle-xe, and vsftpd to start at boot-up and be ready for servicing requests as soon as a new instance of this particular image is created on the cloud.

Stopping Services and Unmounting the Image

Stop the services that were started during image creation, and exit from chroot jail

Services started inside the chroot jail and accessing resources from inside the rerouted folder will make the umount command used to unmount these files back to the image throw a "device busy: error. So let?s stop all the services that were started inside the chroot jail:

Register image

Once the image has been registered in AWS, it becomes an Amazon Machine Image (AMI). We can start an instance of this AMI on EC2. Once this instance boots up, it will automatically start all the services that we have configured to run during startup. Thus, once this instance is running, we will be able to directly access Oracle Database XE and Oracle WebLogic Server hosted on the newly created domain.

Screenshots

Conclusion

In this tutorial, we saw how to create a custom virtual machine image prebundled with Oracle WebLogic Server 11g and Oracle Database XE. We also learned the basics of creating init scripts and configuring services to run at user-defined runlevels. The approach taken here, being generic, can be used to create custom prebundled images or to modify existing AMIs to provide additional functionalities or to better utilize the on-demand scalability of PaaS clouds.