Xen Virtualization: Work with MySQL Server, Ruby on Rails, and Subversion

6 min read

Base Appliance Image

We will use an Ubuntu Feisty domain image as the base image for creating these appliances. This image should be made as sparse and small as possible, and free of any cruft. A completely stripped down version of Linux with only the bare necessities would be a great start. In this case, we will not need any graphical desktop environments, so we can completely eliminate software packages like the X11 and any window manager like Gnome or KDE. Once we have a base image, we can back it up and then start using it for creating Xen appliances. In this article we will use an Ubuntu Feisty domain as the base image. Once this domain image is ready we are going to update it and clean it up a little bit so it can be our base.

  1. Edit the sources list for apt and add in other repositories that we will need to get software packages we will need when creating these appliances.
  1. Update your list of software. This will connect to the apt repositories and get the latest list of packages. We will do the actual update in the next step.

  1. Upgrade the distribution to ensure that you have the latest versions of all the packages.

  1. Automatically clean the image so all unused packages are removed. This will ensure that the image stays free of cruft.

Now we have the base appliance image ready, we will use it to create some Xen appliances. You can make a backup of the original base image and every time you create an appliance you can use a copy as the starting point or template. The images are nothing but domU images, which are customized for running only specific applications. You start them up and run them like ay other Xen guest domains.

MySQL Database Server

MySQL is one of the most popular open-source databases in the world. It is a key component of the LAMP architecture – (Linux Apache MySQL and PHP). It is also very easy to get started with MySQL and is one of the key factors driving its adoption across the enterprise. In this section we will create a Xen appliance that will run a MySQL database server and also provide the ability to automatically backup the database on a given schedule.

Time for Action – Create our first Xen appliance

We will use our base Ubuntu Feisty domain image, and add MySQL and other needed software to it. Please ensure that you have updated your base image to the latest versions of the repositories and software packages before creating this appliance.

  1. Install mysql-server using apt.

  1. Once it is installed, Ubuntu will automatically start the database server. So before we make our other changes, stop MySQL.
  1. Edit the /etc/mysql/my.cnf and comment out the line for the bind-address parameter. This will ensure that MySQL will accept connections from external machines and not just the localhost.
  1. Start a mysql console session to test that everything is installed and working correctly.

  1. Next we will install the utility for doing the automated backups. In order to do that we will first need to install the wget utility for transferring files. This is not a part of the base Ubuntu Feisty installation.

  1. Download the automysqlbackup script from the website.

  1. Copy this script to wherever you like, maybe /opt. Create a link to this location so it’s easy to do future updates.
    # cp automysqlbackup.sh.2.5 /opt
    # ln -s automysqlbackup.sh.2.5 automysqlbackup.sh
  1. Edit the script and modify the parameters at the top of the script to match your environment. Here are the changes to be made in our case.

    # Username to access the MySQL server e.g. dbuser
    USERNAME=pchaganti
    # Username to access the MySQL server e.g. password
    PASSWORD=password
    # Host name (or IP address) of MySQL server e.g localhost
    DBHOST=localhost
    # List of DBNAMES for Daily/Weekly Backup e.g. “DB1 DB2 DB3”
    DBNAMES=”all”
    # Backup directory location e.g /backups
    BACKUPDIR=”/var/backup/mysql”
    # Mail setup
    MAILCONTENT=”quiet”

  1. Schedule this backup script to be run daily by creating a crontab entry for it, in the following format.
45 5 * * * root  /opt/automysqlbackup.sh >/dev/null 2>&1

Now we have a MySQL database server with automatic daily backups as a nice reusable Xen appliance.

What just happened?

We created our first Xen appliance! It is running the open-source MySQL database server along with an automated backup of the database as per the given schedule. This image is essentially a domU image and it can be uploaded along with its configuration file to a repository somewhere, and can be used by anyone in the enterprise or elsewhere with their Xen server. You can either start up the domain manually as and when you need it or set it up to boot automatically when your xend server starts.

Ruby on Rails Appliance

Ruby on Rails is one of the hottest web development frameworks around. It is simple to use and you can use all the expressive power of the Ruby language. It provides a great feature set and has really put the Ruby language on the map. Ruby on Rails is gaining rapid adoption across the IT landscape and for a wide variety of web applications. In this section, we are going to create a Rails appliance that contains Ruby, Rails, and the Mongrel cluster for serving the Rails application and nginx web server for the static content. This appliance gives you a great starting point for your explorations into the world of Ruby on Rails and can be an excellent learning resource.

Time for Action – Rails on Xen

We will use our base Ubuntu Feisty domain image and add Rails and other needed software to it. Please ensure that you have updated your base image to the latest versions of the repositories and software packages before creating this appliance.

  1. Install the packages required for compiling software on an Ubuntu system. This is required as we will be compiling some native extensions. Once the image is done, you can always remove this package if you want to save space.

  1. Install Ruby and other packages that are needed for it.

  1. Download the RubyGems package from RubyForge. We will use this to install any Ruby libraries or packages that we will need, including Rails.

  1. Now install Rails. The first time when you run this command on a clean Ubuntu Feisty system, you will get the following error. Ignore this error and just run the command once again and it will work fine.

  1. This will install Rails and all of its dependencies.

  1. Create a new Rails application. This will create everything needed in a directory named xenbook.

$ rails xenbook 
  1. Change into the directory of the application that we created in the previous step and start the server up. This will start Ruby’s built-in web server, webrick by default.

  1. Launch a web browser and navigate to the web page for our xenbook application.

We have everything working for a simple Rails install. However, we are using webrick, which is a bit slow. So let’s install the Mongrel server and use it with Rails. We will actually install mongrel_cluster that will let us use a cluster of Mongrel processes for serving up our Rails application.

Packt

Share
Published by
Packt

Recent Posts

Top life hacks for prepping for your IT certification exam

I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…

3 years ago

Learn Transformers for Natural Language Processing with Denis Rothman

Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…

3 years ago

Learning Essential Linux Commands for Navigating the Shell Effectively

Once we learn how to deploy an Ubuntu server, how to manage users, and how…

3 years ago

Clean Coding in Python with Mariano Anaya

Key-takeaways:   Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…

3 years ago

Exploring Forms in Angular – types, benefits and differences   

While developing a web application, or setting dynamic pages and meta tags we need to deal with…

3 years ago

Gain Practical Expertise with the Latest Edition of Software Architecture with C# 9 and .NET 5

Software architecture is one of the most discussed topics in the software industry today, and…

3 years ago