Wednesday, November 4, 2015

Setup Vagrant with VirtualBox

this is the most minimalist install/config i could come up with.

download/install vagrant from https://atlas.hashicorp.com

download/install virtual box hypervisor from https://www.virtualbox.org/wiki/Downloads

search for desired box from https://atlas.hashicorp.com/boxes/search
* for this example i have chosen an oracle enterprise version of linux 6.5 x86/64. 
stoilis/oel65-64 Oracle Linux 6.5 x86_64

$ cd ~
$ mkdir vagrants  -this will be your vagrant root home, all files placed here are shared among your boxes.
$ cd vagrants

$ vagrant init stoilis/oel65-64;   -this will download box and create your Vagrantfile for managing boxes.

add box definition to Vagrantfile and save.
* do not remove this file, edit to add and removed machines.
  
* add this config to Vagrantfile
  config.vm.define "oraclelinux1" do |oralinux|
    oralinux.vm.box = "stoilis/oel65-64"
  end

$ vagrant status
Current machine states:

oraclelinux1              not created (virtualbox)

$ vagrant up
Bringing machine 'oraclelinux1' up with 'virtualbox' provider...
==> oraclelinux1: Importing base box 'stoilis/oel65-64'...
==> oraclelinux1: Matching MAC address for NAT networking...
==> oraclelinux1: Checking if box 'stoilis/oel65-64' is up to date...
==> oraclelinux1: Setting the name of the VM: vagrants_oraclelinux1_1446680168757_20990
==> oraclelinux1: Clearing any previously set forwarded ports...
==> oraclelinux1: Clearing any previously set network interfaces...
==> oraclelinux1: Preparing network interfaces based on configuration...
    oraclelinux1: Adapter 1: nat
    oraclelinux1: Adapter 2: hostonly
==> oraclelinux1: Forwarding ports...
    oraclelinux1: 22 => 2222 (adapter 1)
==> oraclelinux1: Booting VM...
==> oraclelinux1: Waiting for machine to boot. This may take a few minutes...
    oraclelinux1: SSH address: 127.0.0.1:2222
    oraclelinux1: SSH username: vagrant
    oraclelinux1: SSH auth method: private key
    oraclelinux1: Warning: Connection timeout. Retrying...
    oraclelinux1: Warning: Connection timeout. Retrying...
    oraclelinux1: 
    oraclelinux1: Vagrant insecure key detected. Vagrant will automatically replace
    oraclelinux1: this with a newly generated keypair for better security.
    oraclelinux1: 
    oraclelinux1: Inserting generated public key within guest...
    oraclelinux1: Removing insecure key from the guest if it's present...
    oraclelinux1: Key inserted! Disconnecting and reconnecting using new SSH key...
==> oraclelinux1: Machine booted and ready!
==> oraclelinux1: Checking for guest additions in VM...
    oraclelinux1: The guest additions on this VM do not match the installed version of
    oraclelinux1: VirtualBox! In most cases this is fine, but in rare cases it can
    oraclelinux1: prevent things such as shared folders from working properly. If you see
    oraclelinux1: shared folder errors, please make sure the guest additions within the
    oraclelinux1: virtual machine match the version of VirtualBox you have installed on
    oraclelinux1: your host and reload your VM.
    oraclelinux1: 
    oraclelinux1: Guest Additions Version: 4.3.12
    oraclelinux1: VirtualBox Version: 5.0
==> oraclelinux1: Configuring and enabling network interfaces...
==> oraclelinux1: Mounting shared folders...


vagrant status
Current machine states:

oraclelinux1              running (virtualbox)

connect via ssh

$ vagrant ssh oraclelinux1
Welcome to Veewee built Vagrant Base Box.

[vagrant@oracle ~]$ su -
Password: 
[root@oracle ~]# uname -a
Linux oracle.vagrantup.com 3.8.13-16.2.1.el6uek.x86_64 #1 SMP Thu Nov 7 17:01:44 PST 2013 x86_64 x86_64 x86_64 GNU/Linux

[root@oracle ~]# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 6.5 (Santiago)
[root@oracle ~]# ifconfig -a
eth0      Link encap:Ethernet  HWaddr 08:00:27:71:CD:31  
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe71:cd31/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:899 errors:0 dropped:0 overruns:0 frame:0
          TX packets:549 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:91751 (89.6 KiB)  TX bytes:74069 (72.3 KiB)

eth1      Link encap:Ethernet  HWaddr 08:00:27:F7:BC:43  
          inet addr:172.28.128.3  Bcast:172.28.128.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fef7:bc43/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1180 (1.1 KiB)  TX bytes:1272 (1.2 KiB)

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)

[root@oracle ~]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root  8.3G  1.4G  6.5G  18% /
tmpfs                         230M     0  230M   0% /dev/shm
/dev/sda1                     477M   55M  398M  12% /boot
vagrant                       465G  181G  285G  39% /vagrant      <---shared vagrant root home

[root@oracle ~]# exit
logout
[vagrant@oracle ~]$ exit
logout
Connection to 127.0.0.1 closed.

test your box's ip address
$ ping 172.28.128.3 
PING 172.28.128.3 (172.28.128.3): 56 data bytes
64 bytes from 172.28.128.3: icmp_seq=0 ttl=64 time=0.755 ms
64 bytes from 172.28.128.3: icmp_seq=1 ttl=64 time=0.323 ms
64 bytes from 172.28.128.3: icmp_seq=2 ttl=64 time=0.308 ms

$ vagrant halt oraclelinux1   -shutdown your box
$ vagrant destroy oraclelinux1  -delete your box if desired

 --enjoy

No comments:

Post a Comment