In the previous
article we have seen how we can configure vagrant boxes. In this article we
will see how we can configure vagrant box in details along with understating
the vagrant file.
1) The first thing
in creating a Vagrant virtual is to run the init command. Run the “vagrant
init” command which will place a Vagrantfile in the current directory. This is
the configuration file that will be used in configuring the vagrant virtual
box. This file contains the name , URL for the box that needs to be downloaded
from, Poft forwarding , sync folder details , networking etc.
[root@vx111a
CentOsVagrant]# vagrant init
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.
[root@vx111a
CentOsVagrant]# ll
total 4
-rw-r--r--. 1 root
root 3016 Dec 2 14:35 Vagrantfile
2) Once the file is
created, open the file and change the basic properties to create the vagrant
box. Clear the contents of the file and use the basic configuration steps
defined below as,
Vagrant.configure(2)
do |config|
config.vm.box = "CentOS"
config.vm.box_url = "https://saleseng.s3.amazonaws.com/boxfiles/CentOS-6.3-x86_64-minimal.box"
config.vm.host_name = "dev.puppetlabs.vm"
end
config.vm.box = "CentOS"
config.vm.box_url = "https://saleseng.s3.amazonaws.com/boxfiles/CentOS-6.3-x86_64-minimal.box"
config.vm.host_name = "dev.puppetlabs.vm"
end
The configuration
steps are,
1) Vagrant uses API
versions while defining the configuration Steps. This was set for the backward
compatibility. So we will start the configuration file by defining the vagrant
version. This current version is 2 so we define,
Vagrant.configure(2)
do |config|
*****
end
2) The next line
tells us about the type of the box we will use . We named the box as “CentOs”.
You can define your own if you need
config.vm.box =
"CentOS"
3) The next line to
define the Box URL from where we will download the Image file for the virtual
we are trying to build.
config.vm.box_url = "https://saleseng.s3.amazonaws.com/boxfiles/CentOS-6.3-x86_64-minimal.box"
config.vm.box_url = "https://saleseng.s3.amazonaws.com/boxfiles/CentOS-6.3-x86_64-minimal.box"
The above one says
that it is a CentOs box with minimal configuration.
4) The next step is
define the host name of the Virtual configured. This is some thing called as
provisioning since we are defining a box for the virtual that has yet to be
created.
config.vm.host_name = "dev.puppetlabs.vm"
5) Once the
Configuration is done, save it and run the “vagrant up” command “vagrant up”.
[root@vx111a
CentOsVagrant]# vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'CentOS'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: barhost
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Available bridged network interfaces:
1) em1
2) vmnet8
3) virbr0
4) vmnet1
==> default: When choosing an interface, it is usually the one that is
==> default: being used to connect to the internet.
default: Which interface should the network bridge to? 1
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: bridged
==> default: Forwarding ports...
default: 80 => 8084 (adapter 1)
default: 22 => 2200 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2200
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection timeout. Retrying...
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.1.18
default: VirtualBox Version: 5.0
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
default: /vagrant => /work/CentOsVagrant
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'CentOS'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: barhost
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Available bridged network interfaces:
1) em1
2) vmnet8
3) virbr0
4) vmnet1
==> default: When choosing an interface, it is usually the one that is
==> default: being used to connect to the internet.
default: Which interface should the network bridge to? 1
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: bridged
==> default: Forwarding ports...
default: 80 => 8084 (adapter 1)
default: 22 => 2200 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2200
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection timeout. Retrying...
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.1.18
default: VirtualBox Version: 5.0
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
default: /vagrant => /work/CentOsVagrant
6) Once the Virtaul
is up and running , check the “vagrant box list” command to make sure the box
is added and also check the Virtual box to see whether the newly created
virtuals is shown in Oracle Virtual box.
"Great blog created by you. I read your blog, its best and useful information. You have done a great work. Super blogging and keep it up.php jobs in hyderabad.
ReplyDelete"