3 avr. 2014

Virtualize your servers

Introduction

Virtualizing a server has many advantages over installing real servers. First, you can have many installments for testing or replicating existing ones. Second, it helps you develop installation scripts which will help you on your next projects.

OSX optional installations

OSX comes with no package manager except the AppStore. Though, it does the required common uses for casual users, it fall short when you need hundreds of tools. Thankfully, Brew is up to the task... if you are not too reluctant using the command line. Its installation is really simple:
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
You have now access to almost every free and open source available packages.

Now, you can install an access to some already build packages as well as some proprietary software using Cask:
brew tap phinze/cask
brew install brew-cask
Here, you are. No more search attempts for finding a software. Almost every installations are available in a single command. If you don't know the name of the package, you simply search it on the command line. Here's an example for Firefox:
brew cask search firefox
==> Exact match
firefox
==> Partial matches
multifirefox

Installing VirtualBox

VirtualBox is a free and well maintained virtual machine, sometimes called hypervisor. You install it using the following command:
brew cask install virtualbox
Stay alert your password is required. Done! Nice.

Installing Vagrant

Vagrant is an helper installation program that will create for you a complete configured virtualized server. It uses a simple Ruby file as its configuration in order to produce reproducible images of your server. When you want to send a server to your coworkers, you only send this file. When you want to create a new server with some preinstalled tools, you just edit the configuration file. The same step as before is required:
brew cask install vagrant
After a required password, you got it now as an available new command.

Now your system is almost a Cloud controller (well, almost) :)

Installing and running your server OS of choice

With your new artillery, you are able to install every virtual machine image. Here, I depict the details for installing an Ubuntu server. Sure, you can choose every other OSes you may like (just Googles it :) ).
mkdir ~/VirtualBoxes
cd ~/VirtualBoxes
vagrant init UbuntuServer
This step create a simple configuration file named Vagrantfile that we will edit. Choose your favorite editor. Mine is Vim and you can turn on the syntax using the nice vim-vagrant plugin (which comes with a supercharge Vagrant command). As the Vagrantfile is a simple Ruby file, you should be able to activate the appropriate syntax highlighting.

Ready? Just edit the Vagrantfile and replace the line that starts with # config.vm.bow_url = "... with:
  config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-i386-vagrant-disk1.box"
That's all. Your server is running. Note that the installation is only done once :)

Check you virtual server

Launch VirtualBox in your Launcher and you can see it running.
My screenshot is in french but you should see where we get.

Turning off the server

Still in your command line? Vagrant helps you out also in this field:
vagrant halt

Aucun commentaire:

Enregistrer un commentaire