Total Pageviews

Sunday, 5 March 2017

Installation of Vagrant in Windows, VMware and Virtualbox !!!

Many of us are familiar with two leading virtualization providers VMware (Workstation) and Oracle (Virtualbox). Generally we create Virtual Machine (VMs), allocate resources to them and install OS. Vagrant is an open-source software, using which we can create virtual environment within seconds. It was started by Mitchelle Hashimoto.

We can use it to initiate a instance within Windows PC, VMware Workstation, Oracle Virtualbox and in AWS cloud environment. In real time, Vagrant is highly used for building development and test environments in Software Industry.

We can download the software from,

https://www.vagrantup.com/

Useful and related information like what and when, from:

https://en.wikipedia.org/wiki/Vagrant_(software)

Let me show how to use it in Windows, how we can initiate a simple instance to work with Unix environment in our Computer/Laptop.

Click on the Download....

Select the platform, to download the installer...


Vagrant_1.9.msi for Windows...


Vagrant_1.9.rpm for CentOS...


Installation procedure is normal .exe installer...


Now lets move on to our Command Line....


C:\Users\lokes>vagrant --version

Vagrant 1.9.1
C:\Users\lokes>

To initiate the Vagrant instance, we need the Vagrant box url....


Now click on the desired Vagrant box,


Use this url to initiate and download the Vagrant box template...


Go to desired directory location,


F:\Workspace_local>cd vagrant
F:\Workspace_local\vagrant>

F:\Workspace_local\vagrant>dir

Volume in drive F is ENTERTAINMENT
 Volume Serial Number is 42C5-DACA
 Directory of F:\Workspace_local\vagrant
03/04/2017  06:32 PM    <DIR>          .
03/04/2017  06:32 PM    <DIR>          ..
               0 File(s)              0 bytes
               2 Dir(s)  221,537,452,032 bytes free
F:\Workspace_local\vagrant>

F:\Workspace_local\vagrant>vagrant init ubuntu/trusty64 https://atlas.hashicorp.com/ubuntu/boxes/trusty64 box
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.
F:\Workspace_local\vagrant>


Once initiated, we need to use "vagrant up". It initiates the Vagrant box with defaults as per the "Vagrantfile".

F:\Workspace_local\vagrant>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'ubuntu/trusty64' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'https://atlas.hashicorp.com/ubuntu/boxes/trusty64'
    default: URL: https://atlas.hashicorp.com/ubuntu/boxes/trusty64
==> default: Adding box 'ubuntu/trusty64' (v20170222.0.1) for provider: virtualbox
    default: Downloading: https://atlas.hashicorp.com/ubuntu/boxes/trusty64/versions/20170222.0.1/providers/virtualbox.box
    default: Progress: 100% (Rate: 4633k/s, Estimated time remaining: --:--:--)
==> default: Successfully added box 'ubuntu/trusty64' (v20170222.0.1) for 'virtualbox'!
==> default: Importing base box 'ubuntu/trusty64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/trusty64' is up to date...
==> default: Setting the name of the VM: vagrant_default_1488670674498_57274
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default:
    default: Guest Additions Version: 4.3.36
    default: VirtualBox Version: 5.0
==> default: Mounting shared folders...
    default: /vagrant => F:/Workspace_local/vagrant

F:\Workspace_local\vagrant>


Command to check list of boxes available,


F:\Workspace_local\vagrant>vagrant box list

           ubuntu/trusty64 (virtualbox, 20170222.0.1)
F:\Workspace_local\vagrant>

Command to login to our Vagrant instance,

F:\Workspace_local\vagrant>vagrant ssh
`ssh` executable not found in any directories in the %PATH% variable. Is an
SSH client installed? Try installing Cygwin, MinGW or Git, all of which
contain an SSH client. Or use your favorite SSH client with the following
authentication information shown below:

Host: 127.0.0.1
Port: 2222
Username: vagrant
Private key: F:/Workspace_local/vagrant/.vagrant/machines/default/virtualbox/private_key
F:\Workspace_local\vagrant>

I have Git bash already installed, we can even install openSSH for ssh service....

USER@USER-PC MINGW64 ~ $ cd F:
USER@USER-PC MINGW64 /f $ cd Workspace_local/vagrant/
USER@USER-PC MINGW64 /f/Workspace_local/vagrant $
USER@USER-PC MINGW64 /f/Workspace_local/vagrant $ git --version
git version 2.11.0.windows.3
USER@USER-PC MINGW64 /f/Workspace_local/vagrant $

USER@USER-PC MINGW64 /f/Workspace_local/vagrant $ vagrant status
Current machine states:

default                   running (virtualbox)

The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine. In either case, to restart it again,
simply run `vagrant up`.

USER@USER-PC MINGW64 /f/Workspace_local/vagrant $ 

Now we can "ssh" to the vagrant box....

USER@USER-PC MINGW64 /f/Workspace_local/vagrant $ vagrant ssh
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 3.13.0-110-generic x86_64)
 * Documentation:  https://help.ubuntu.com/
  System information as of Sun Mar  5 16:26:29 UTC 2017

  System load:  0.58              Processes:           82
  Usage of /:   3.6% of 39.34GB   Users logged in:     0
  Memory usage: 27%               IP address for eth0: 10.0.2.15
  Swap usage:   0%

  Graph this data and manage this system at:
    https://landscape.canonical.com/
  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

0 packages can be updated.
0 updates are security updates.

New release '16.04.2 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

vagrant@vagrant-ubuntu-trusty-64:~$


vagrant@vagrant-ubuntu-trusty-64:~$ uname -a
Linux vagrant-ubuntu-trusty-64 3.13.0-110-generic #157-Ubuntu SMP Mon Feb 20 11:54:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
vagrant@vagrant-ubuntu-trusty-64:~$

Now we are inside our vagrant instance, we can run any Linux/Ubuntu commands,

vagrant@vagrant-ubuntu-trusty-64:~$ df -kh
Filesystem      Size  Used Avail Use% Mounted on
udev            241M   12K  241M   1% /dev
tmpfs            49M  352K   49M   1% /run
/dev/sda1        40G  1.5G   37G   4% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            5.0M     0  5.0M   0% /run/lock
none            245M     0  245M   0% /run/shm
none            100M     0  100M   0% /run/user
none            450G  251G  200G  56% /vagrant
vagrant@vagrant-ubuntu-trusty-64:~$

vagrant@vagrant-ubuntu-trusty-64:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:41:9a:fb
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe41:9afb/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:510 errors:0 dropped:0 overruns:0 frame:0
          TX packets:365 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:50359 (50.3 KB)  TX bytes:43637 (43.6 KB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)


vagrant@vagrant-ubuntu-trusty-64:~$ exit
logout
Connection to 127.0.0.1 closed.
USER@USER-PC MINGW64 /f/Workspace_local/vagrant $

Now let us see how to initiate vagrant in VMware and Virtualbox....

To install Vagrant in VMware or Virtualbox we need OVF (Open Virtualization Format) file of the downloaded template file of the Vagrant box.

It will be found in .vagrant.d directory....


VMware

Using this OVF template, we can initiate vagrant...


Select the OVF file,


Give the desired location for the VM,


Vagrant is booting up....


Login Credentials:
            user: vagrant                passwd: vagrant


We can run normal Ubuntu commands,


VirtualBox:

In Virtualbox also it is the same procedure to deploy the OVF in Oracle Virtualbox.
Click on "Import Appliance"...



Browse the OVF file location...




Login Credentials:
            user: vagrant                passwd: vagrant

We can run normal Ubuntu commands,



In my next post, I will discuss about working with Vagrant and different commands used in Administration of Vagrant boxes. 

We can build development environment so easily with the help of Vagrant, we can automate the tasks by editing "Vagrantfile" as per the requirement of our infrastructure.

################################################################################

1 comment:

  1. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. Great work Aluminium ramen

    ReplyDelete