cmdref.net - Cheat Sheet and Example

cmdref.net is command references/cheat sheets/examples for system engineers.

User Tools

Site Tools


Sidebar








Etc


Reference














.

software:vargant:index.html



PC Software

Vargant

Introduction

What is Vargant

Vagrant is a tool for building complete development environments.


Where do you search Box Files?

Vagrant Cloud

Vagrantbox.es

Install

Windows

  1. Install VirtualBox https://www.virtualbox.org/
C:\HashiCorp\Vagrant


Commands

How to check Vagrant Version

PS C:\Users\user01> vagrant -v
Vagrant 2.1.2

Box Commands

vagrant box add BOXNAME BOXFILE Download a Box File to local host
vagrant box remove BOXFILE delete box file
vagrant box list List BOX
vagrant init box Create Vagrantfile
vagrant package
vagrant package --base NAME
Create Box Files. (package.box)
vagrant box add IMPORT-NAME package.box
vagrant box add CentOS-6.6-minimal-ja package.box
Import box a file

VM Commands

vagrant up start VM from Vagrantfile
vagrant reload restart VM
vagrant status List VM with start
vagrant global-status List all VM status
vagrant halt stop VM
vagrant destroy delete VM initialized state
vagrant ssh login with ssh (If you using Linux or Mac OS)


How to use vagrant

Download box and Start Up VM

~]$ mkdir centos
~]$ cd centos
centos]$ vagrant init centos/7
  • Download to C:\Users\user01\.vagrant.d\boxes\
  • Created Vagrantfile in your directory.
~]$ cd centos
centos]$ vi Vagrantfile
~]$ cd centos
centos]$ vagrant up
centos]$ vagrant status
  • Copied VMDK files to C:\Users\user01\VirtualBox VMs\

How to Login GestOS

~]$ cd centos
centos]$ vagrant ssh
  • root password is 'vagrant'.
  • vagrant user's password is 'vagrant'.

Holt VM

~]$ cd centos
centos]$ vagrant status
centos]$ vagrant halt
centos]$ vagrant status

Delete VM

~]$ cd centos
centos]$ vagrant status
centos]$ vagrant destroy
centos]$ vagrant status

Delete Boxs

~]$ vagrant box list
~]$ vagrant box remove centos/7


Configuration of Vagrantfile

Sample1 : Adoptor1:NAT, Adoptor2: Bridge

  • public_network = Bridge Network
Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"

  #Adaptor2 :Bridged network with DHCP
  config.vm.network "public_network"

  config.vm.provider "virtualbox" do |v|
    v.memory = 512
    v.customize ["modifyvm", :id, "--cpus", "2"]
  end

end
config.vm.network "public_network", ip: "192.168.0.2"


Sample2 : Adoptor1:NAT, Adoptor2: Host Only

  • Default Network is NAT
  • private_network is host only network
Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"

  #Adaptor2 :host only network
  config.vm.network "private_network", type: "dhcp"


  config.vm.provider "virtualbox" do |v|
    v.memory = 512
    v.customize ["modifyvm", :id, "--cpus", "2"]
  end

end


Sample3 : Adoptor1:NAT with portfoward

Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"

  #Adaptor1 : NAT with portforward
  config.vm.network "forwarded_port", guest: 80, host: 8080
  config.vm.network "forwarded_port", guest: 22, host: 10022

  config.vm.provider "virtualbox" do |v|
    v.memory = 512
    v.customize ["modifyvm", :id, "--cpus", "2"]
  end

end


MULTI-MACHINE

Vagrant.configure("2") do |config|
  config.vm.provision "shell", inline: "echo Hello"

  config.vm.define "web" do |web|
    web.vm.box = "apache"
  end

  config.vm.define "db" do |db|
    db.vm.box = "mysql"
  end
end
Vagrant.configure(2) do |config|

  config.vm.box = "xxxxx"

  config.vm.define :test1 do |cfg|
    cfg.vm.hostname = "test1"
    cfg.vm.network "private_network", ip: "192.168.10.11", virtualbox__intnet: "intnet"
  end

  config.vm.define :test2 do |cfg|
    cfg.vm.hostname = "test2"
    cfg.vm.network "private_network", ip: "192.168.10.12", virtualbox__intnet: "intnet"
  end

end

Note

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
   config.vm.synced_folder "./data", "/vagrant_data"




How to Create box file

# ln -s -f /dev/null /etc/udev/rules.d/70-persistent-net.rules
# exit
centos]$ vagrant halt
centos]$ vagrant package

created package.box

Import my box file

~]$ mkdir centos7a
~]$ cd centos7a
centos7a]$ vagrant box add centos7a package.box
centos7a]$ vagrant box list
centos7a]$ vagrant init centos7a
centos7a]$ vagrant up
centos7a]$ vagrant ssh




Troubleshooting

Authentication failure. Retrying...

# vargrant up

    default: Warning: Authentication failure. Retrying...

Check Permission

/home/vagrant    700 or 755 or 711
/home/vagrant/ssh    700
/home/vagrant/ssh/authorized_keys  600    





PC Software




software/vargant/index.html.txt ยท Last modified: 2018/07/05 by admin