This article will
help in configuring the first box using vagrant. The first thing in creating a
Virtual box is to choose a Operating system that we want to run. Now for the
demo purpose we will choose the precise32 box from hashiCorp. This is a
standard Ubuntu 12.04 LTS 64-bit box.
1) Run the “vagrant
init” command along with the name of the box and location of the Box like this
[root@vx111a vagt]#
vagrant init precise32 http://files.vagrantup.com/precise32.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.
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.
2) Once the command
is run, a Vagrant file is created with the below contents.
Vagrant.configure(2)
do |config|
config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
end
config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
end
Though there are
many other commented lines, we can clean them to see the above contents. We got
the vm.box name and box.url from where we need to download the box.
3) Run the “vagrant
box list” to see the available boxes
[root@vx111a vagt]#
vagrant box list
CentOS (virtualbox, 0)
CentiOS (virtualbox, 0)
mynewBox (virtualbox, 0)
CentOS (virtualbox, 0)
CentiOS (virtualbox, 0)
mynewBox (virtualbox, 0)
We can see that the
recently added Precise32 is not available.
4) Now the next
step is to start the Precise32 box. We use the “vagrant up” command from the
same location as the vagrantfile exits
[root@vx111a vagt]#
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: vagt_default_1450767047168_69849
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 => 2222 (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: 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.2.0
default: VirtualBox Version: 5.0
==> default: Mounting shared folders...
default: /vagrant => /test/vagt
This will take some time in downloading the Precise32 copy to the local host and making the necessary configurations and starting that 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: vagt_default_1450767047168_69849
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 => 2222 (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: 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.2.0
default: VirtualBox Version: 5.0
==> default: Mounting shared folders...
default: /vagrant => /test/vagt
This will take some time in downloading the Precise32 copy to the local host and making the necessary configurations and starting that up.
5) Once the vagrant
up is done, we can run the “vagrant box list” to see the newly added box as
[root@vx111a vagt]#
vagrant box list
CentOS (virtualbox, 0)
CentiOS (virtualbox, 0)
mynewBox (virtualbox, 0)
precise32 (virtualbox, 0)
CentOS (virtualbox, 0)
CentiOS (virtualbox, 0)
mynewBox (virtualbox, 0)
precise32 (virtualbox, 0)
6) One command is available in vagrant “vagrant global-status” which will give you more details about the running virtuals like,
[root@vx111a vagt]#
vagrant global-status
id name provider state directory
-------------------------------------------------------------------------
468eb28 default virtualbox poweroff /work/hello
9ebdb6a default virtualbox running /work/CentOsVagrant
ddb41f9 default virtualbox running /work/vagrantTest
1af9161 default virtualbox running /test/vagt
id name provider state directory
-------------------------------------------------------------------------
468eb28 default virtualbox poweroff /work/hello
9ebdb6a default virtualbox running /work/CentOsVagrant
ddb41f9 default virtualbox running /work/vagrantTest
1af9161 default virtualbox running /test/vagt
We can see the last
line which is the newly created one. This also gives us the directory location
from where the virtual machine was running.
7) Checking the
newly created virtual. Vagrant does provide the ssh capabilities for the newly
created virtual box. We can use the “vagrant ssh” command to login to the newly
created machine as,
[root@vx111a vagt]#
vagrant ssh
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)
* Documentation: https://help.ubuntu.com/
New release '14.04.3 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
Welcome to your Vagrant-built virtual machine.
Last login: Tue Dec 22 07:05:22 2015 from 10.0.2.2
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)
* Documentation: https://help.ubuntu.com/
New release '14.04.3 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
Welcome to your Vagrant-built virtual machine.
Last login: Tue Dec 22 07:05:22 2015 from 10.0.2.2
Check the Release
version as,
vagrant@precise32:~$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04 LTS"
vagrant@precise32:~$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04 LTS"
Check the User
Logged in using,
vagrant@precise32:~$
id
uid=1000(vagrant) gid=1000(vagrant) groups=1000(vagrant),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),109(lpadmin),110(sambashare),999(admin)
Change the Root Password using,
uid=1000(vagrant) gid=1000(vagrant) groups=1000(vagrant),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),109(lpadmin),110(sambashare),999(admin)
Change the Root Password using,
vagrant@precise32:~$ sudo passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
vagrant@precise32:~$ su root
Password:
root@precise32:/home/vagrant# id
uid=0(root) gid=0(root) groups=0(root)
we can use the
“exit” command for getting out of the box.
8) Now if we open
the Oracle Virtual box we can see a New Virtual Box running. Right click on the
box and choose “show” to login to the GUI of the newly Creating Virtual Box
[root@vx111a vagt]#
vagrant box remove precise32
Removing box 'precise32' (v0) with provider 'virtualbox'...
Removing box 'precise32' (v0) with provider 'virtualbox'...
By this we complete
the basic configuration of the vagrant box. In the next articles we will see
more ways of using vagrant
No comments :
Post a Comment