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

0
63
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.
    Xen Virtualization: Work with MySQL Server, Ruby on Rails, and Subversion
  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.
    Xen Virtualization: Work with MySQL Server, Ruby on Rails, and Subversion

  1. Upgrade the distribution to ensure that you have the latest versions of all the packages.
    Xen Virtualization: Work with MySQL Server, Ruby on Rails, and Subversion

  1. Automatically clean the image so all unused packages are removed. This will ensure that the image stays free of cruft.
 Xen Virtualization: Work with MySQL Server, Ruby on Rails, and Subversion

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.
    Xen Virtualization: Work with MySQL Server, Ruby on Rails, and Subversion

  1. Once it is installed, Ubuntu will automatically start the database server. So before we make our other changes, stop MySQL.
    Xen Virtualization: Work with MySQL Server, Ruby on Rails, and Subversion
  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.
    Xen Virtualization: Work with MySQL Server, Ruby on Rails, and Subversion
  1. Start a mysql console session to test that everything is installed and working correctly.
    Xen Virtualization: Work with MySQL Server, Ruby on Rails, and Subversion

  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.
    Xen Virtualization: Work with MySQL Server, Ruby on Rails, and Subversion

  1. Download the automysqlbackup script from the website.
    Xen Virtualization: Work with MySQL Server, Ruby on Rails, and Subversion

  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.
    Xen Virtualization: Work with MySQL Server, Ruby on Rails, and Subversion

  1. Install Ruby and other packages that are needed for it.
    Xen Virtualization: Work with MySQL Server, Ruby on Rails, and Subversion

  1. Download the RubyGems package from RubyForge. We will use this to install any Ruby libraries or packages that we will need, including Rails.
    Xen Virtualization: Work with MySQL Server, Ruby on Rails, and Subversion

  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.
    Xen Virtualization: Work with MySQL Server, Ruby on Rails, and Subversion

  1. This will install Rails and all of its dependencies.
    Xen Virtualization: Work with MySQL Server, Ruby on Rails, and Subversion

  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.
    Xen Virtualization: Work with MySQL Server, Ruby on Rails, and Subversion

  1. Launch a web browser and navigate to the web page for our xenbook application.
    Xen Virtualization: Work with MySQL Server, Ruby on Rails, and Subversion

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.

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

LEAVE A REPLY

Please enter your comment!
Please enter your name here