saasbook/courseware — pull request #6 by abarghouti (2014-03-11 09:26:10+00:00)
Title: README_VAGRANT_LINUX_INSTALL.md

Introduction

Vagrant designed to run through multiple platforms including currently Mac OS X, Microsoft Windows, Debian, Ubuntu, CentOS, RedHat and Fedora, in this document we will handle how to configure and run virtual development environment through Vagrant from scratch to up and running, on Ubuntu and Windows environments.

Ubuntu Environment

To configure Vagrant inside Ubuntu environment, we should to follow the following sections

Installing Vagrant

Create Vagrant Machine Folders

Installing Precise32 Box

Creating New Virtual Machine

Downliading Virtual Machine

Configuration Script Shell

Configuring Permissions for Virtual Machine Configuration Script Shell

Installing Vagrant

First thing, you need to install vagrant packages from advanced packaging tool apt-get.

This will require you to enter your password, enter it and confirm to download.

administrator@host01:~$sudo apt-get install vagrant

[sudo] password for administrator:

Reading package lists... Done

Building dependency tree

Reading state information... Done

The following extra packages will be installed:

bsdtar curl dkms libgsoap3 libruby1.9.1 libsdl1.2debian libyaml-0-2 ruby

ruby-childprocess ruby-erubis ruby-ffi ruby-i18n ruby-log4r ruby-net-scp

ruby-net-ssh ruby1.9.1 virtualbox virtualbox-dkms virtualbox-qt

Suggested packages:

bsdcpio debhelper ri ruby-dev ruby1.9.1-examples ri1.9.1 graphviz

ruby1.9.1-dev ruby-switch virtualbox-guest-additions-iso vde2

The following NEW packages will be installed:

bsdtar curl dkms libgsoap3 libruby1.9.1 libsdl1.2debian libyaml-0-2 ruby

ruby-childprocess ruby-erubis ruby-ffi ruby-i18n ruby-log4r ruby-net-scp

ruby-net-ssh ruby1.9.1 vagrant virtualbox virtualbox-dkms virtualbox-qt

0 upgraded, 20 newly installed, 0 to remove and 11 not upgraded.

Need to get 25.2 MB of archives.

After this operation, 94.8 MB of additional disk space will be used.

Do you want to continue [Y/n]? Y

Create Vagrant Machine Folders

Folders could be created based on your choice; in our case, we will create the following folder in the home folder:

Vagrant -> Projects -> VM_169.x

administrator@host01:~$mkdir Vagrant

administrator@host01:~$mkdir Vagrant/Projects

administrator@host01:~$mkdir Vagrant/Projects/VM_169.x

administrator@host01:~$cd ~/Vagrant/Projects/VM_169.x

administrator@host01:~/Vagrant/Projects/VM_169.x$

Installing Precise32 Box

Vagrant provides many ready-made boxes, in our case; we will use the ready-made box called precise32, we need to download and install precise32 box in our vagrant installation.

administrator@host01:~/Vagrant/Projects/VM_169.x$ vagrant box add precise32 http://files.vagrantup.com/precise32.box --provider virtualbox

Downloading or copying the box...

Extracting box...te: 5410k/s, Estimated time remaining: --:--:--)

Successfully added box 'precise32' with provider 'virtualbox'!

To validate our installation, we should to check the list of installed boxes.

administrator@host01:~/Vagrant/Projects/VM_169.x$ vagrant box list

precise32 (virtualbox)

Creating New Virtual Machine

We should initialize new virtual machine for our usage based on the precise32 box we installed earlier, from the folder already created for this virtual machine VM_169.x, we should initialize the virtual machine there.

administrator@host01:~/Vagrant/Projects/VM_169.x$ vagrant init precise32

A `Vagrantfile` has been placed in this directory. You are now

ready to `vagrant up` your first virtual environment! Please read

the comments in the Vagrantfile as well as documentation on

`vagrantup.com` for more information on using Vagrant.

administrator@host01:~/Vagrant/Projects/VM_169.x$ ls

Vagrantfile

Initializing virtual machine here means vagrant will create new vagrant file in this folder called Vagrantfile, this file will contain any custom settings you want to add on the virtual machine like amount of memory, networking, shared folders, settings … Anything specified here will override the defaults.

Downloading Virtual Machine Configuration Script Shell

We need to download this file to execute it inside the newly created virtual machine, currently we have file version configure-image-0.10.3.sh, and we will download it directly inside the virtual machine folder in the host so it will be already shared inside our guest virtual machine.

administrator@host01:~/Vagrant/Projects/VM_169.x$ wget https://raw.github.com/saasbook/courseware/master/vm-setup/configure-image-0.10.3.sh

Configuring Permissions for Virtual Machine Configuration Script Shell

Before executing the configuration script shell, it requires giving it proper permissions; else, we will face many errors during script execution, we need specifically the permission to execute or run the file as a program, this permission will be given through the following command.

administrator@host01:~/Vagrant/Projects/VM_169.x$ chmod +x configure-image-0.10.3.sh

Running the Virtual Machine

Now is the time to run the created virtual machine for first time.

administrator@host01:~/Vagrant/Projects/VM_169.x$ vagrant up

Bringing machine 'default' up with 'virtualbox' provider...

[default] Importing base box 'precise32'...

[default] Matching MAC address for NAT networking...

[default] Setting the name of the VM...

[default] Clearing any previously set forwarded ports...

[default] Creating shared folders metadata...

[default] Clearing any previously set network interfaces...

[default] Preparing network interfaces based on configuration...

[default] Forwarding ports...

[default] -- 22 => 2222 (adapter 1)

[default] Booting VM...

[default] Waiting for VM to boot. This can take a few minutes.

[default] VM booted and ready for use!

[default] Configuring and enabling network interfaces...

[default] Mounting shared folders...

[default] -- /vagrant

By default it forward the port 22 (ssh) to port 2222 and mounts the shared folder where the virtual machine located VM_169.x to /vagrant in the virtual machine.

Connecting to the Virtual Machine

Let’s start to use our new virtual machine, first we need to connect through ssh, it will open a ssh console to the virtual.

administrator@host01:~/Vagrant/Projects/VM_169.x$ vagrant ssh

Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)

* Documentation: https://help.ubuntu.com/

Welcome to your Vagrant-built virtual machine.

Last login: Fri Sep 14 06:22:31 2012 from 10.0.2.2

vagrant@precise32:~$

To close ssh just type exit as below, you might to type it twice

vagrant@precise32:~$ exit

logout

There are stopped jobs.

vagrant@precise32:~$ exit

logout

Connection to 127.0.0.1 closed.

administrator@host01:~/Vagrant/Projects/VM_169.x$

Running the Virtual Machine Configuration Script Shell

We need to configure virtual machine to make it ready for course work; this will be through running the configuration script inside the newly created virtual machine, it will just ask you about your account’s password to be used during configuration and just wait to finish, it will take some time to finish.

vagrant@precise32:~$ /vagrant/configure-image-0.10.3.sh

Enter password to be used for sudo commands:vagrant

Suspending and Shutting Down Virtual Machine

After you finish your working, you need either to suspend and resume your virtual machine or turn it off; you can use one of the following commands upon your choice.

administrator@host01:~/Vagrant/Projects/VM_169.x$ vagrant suspend

administrator@host01:~/Vagrant/Projects/VM_169.x$ vagrant resume

administrator@host01:~/Vagrant/Projects/VM_169.x$ vagrant halt