Vagrant
Vagrant
What is a Vagrant?
Backend에 virtualbox를 사용(변경 가능) 하고, virtualbox를 이용해 VM을 생성하여 그 VM 내 원하는 환경(특정 OS부터 특정 library까지) 을 구성함.
예전에 fd.io에서 빌드하는 vpp 개발 환경이 vagrant로 되어 있었는데 왜 그런가 싶었는데 이제 생각해 보니 vpp 동작에 필요한 OS, kernel module, DPDK SDK 와 패치 들 그리고 vpp code 까지 모든 걸 제어할 수 있도록 VagrantFile을 만들어서 개발 환경을 표준화하려는 것 이었다는.
Container와 달리 독립된 OS환경을 가질 수 있으므로 OS버전이 다르거나 , 커널 모듈 수정 등을 필요로 한 경우에 유용할 듯
Virtualbox가 생각보다 가벼워서 유용한 듯 하다.
VagrantFile을 이용해서 vagrant up
한 후 vagrant box list
로 생성된 VM instance 들을 확인한 후 vagrant ssh VM_NAME
하면 해당 VM으로 접속. 그러므로 미리 VagrantFile을 통해 지정한 환경이 모두 구성되어 있다는.
Docker와 유사하게 host와 volume을 공유할 수 있음.(이건 그냥 virtualbox가 지원하는 shared folder 기능을 활용하는 듯)
그 외 사용 측면에서는 docker나 virsh 명령어 사용하는 것과 유사.
Install Vagrant on OS X
mbpr15:~ cychong$ brew cask install vagrant
==> Satisfying dependencies
==> Downloading https://releases.hashicorp.com/vagrant/2.0.1/vagrant_2.0.1_x86_64.dmg
######################################################################## 100.0%
==> Verifying checksum for Cask vagrant
==> Installing Cask vagrant
==> Running installer for vagrant; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are ignored.
Password:
==> installer: Package name is Vagrant
==> installer: Installing at base path /
==> installer: The install was successful.
🍺 vagrant was successfully installed!
Install vagrant-manager
additionally
mbpr15:~ cychong$ brew cask install vagrant-manager
==> Satisfying dependencies
==> Downloading https://github.com/lanayotech/vagrant-manager/releases/download/2.6.0/vagrant-manager-2.6.0.dmg
######################################################################## 100.0%
==> Verifying checksum for Cask vagrant-manager
==> Installing Cask vagrant-manager
==> Moving App 'Vagrant Manager.app' to '/Applications/Vagrant Manager.app'.
🍺 vagrant-manager was successfully installed!
Install Vagrant Box
Virtualbox is already installed
Add Vagrant box which can be found from Vagrant Cloud
mbpr15:~ cychong$ vagrant box add ubuntu/xenial64 https://app.vagrantup.com/ubuntu/boxes/xenial64
==> box: Loading metadata for box 'https://app.vagrantup.com/ubuntu/boxes/xenial64'
==> box: Adding box 'ubuntu/xenial64' (v20171122.0.0) for provider: virtualbox
box: Downloading: https://vagrantcloud.com/ubuntu/boxes/xenial64/versions/20171122.0.0/providers/virtualbox.box
==> box: Successfully added box 'ubuntu/xenial64' (v20171122.0.0) for 'virtualbox'!
Initialize Vagrant
mbpr15:~ cychong$ cd /Users/cychong/Public/working
mbpr15:working cychong$ vagrant init ubuntu/xenial64
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.
Start Vagrant
It takes some time
mbpr15:working cychong$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/xenial64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/xenial64' is up to date...
==> default: Setting the name of the VM: working_default_1511385943610_77718
==> 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: Running 'pre-boot' VM customizations...
==> 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: ubuntu
default: SSH auth method: password
default: Warning: Connection reset. Retrying...
default: Warning: Remote connection disconnect. Retrying...
default: Warning: Connection reset. Retrying...
default: Warning: Remote connection disconnect. Retrying...
default: Warning: Connection reset. Retrying...
default: Warning: Remote connection disconnect. Retrying...
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: 5.0.40
default: VirtualBox Version: 5.2
==> default: Mounting shared folders...
default: /vagrant => /Users/cychong/Public/working
Login to Vagrant VM
mbpr15:working cychong$ vagrant ssh
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-101-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
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.
_____________________________________________________________________
WARNING! Your environment specifies an invalid locale.
The unknown environment variables are:
LC_CTYPE=UTF-8 LC_ALL=
This can affect your user experience significantly, including the
ability to manage packages. You may install the locales by running:
sudo apt-get install language-pack-UTF-8
or
sudo locale-gen UTF-8
To see all available language packs, run:
apt-cache search "^language-pack-[a-z][a-z]$"
To disable this message for all users, run:
sudo touch /var/lib/cloud/instance/locale-check.skip
_____________________________________________________________________
ubuntu@ubuntu-xenial:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 490M 0 490M 0% /dev
tmpfs 100M 3.1M 97M 4% /run
/dev/sda1 9.7G 858M 8.8G 9% /
tmpfs 497M 0 497M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 497M 0 497M 0% /sys/fs/cgroup
vagrant 466G 269G 197G 58% /vagrant
tmpfs 100M 0 100M 0% /run/user/1000
/vagrant
directory
This directory is used to shared files between the host and VM and the size of this partition is same to the storage of host machine
mbpr15:working cychong$ df -h .
Filesystem Size Used Avail Capacity iused ifree %iused Mounted on
/dev/disk1s1 466Gi 265Gi 197Gi 58% 1137732 9223372036853638075 0% /
install tools as usual linux box
ubuntu@ubuntu-xenial:/vagrant$ sudo apt install gcc
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
binutils cpp cpp-5 gcc-5 libasan2 libatomic1 libc-dev-bin libc6-dev libcc1-0 libcilkrts5 libgcc-5-dev libgomp1 libisl15 libitm1 liblsan0 libmpc3 libmpx0 libquadmath0 libtsan0
libubsan0 linux-libc-dev manpages-dev
Suggested packages:
binutils-doc cpp-doc gcc-5-locales gcc-multilib make autoconf automake libtool flex bison gdb gcc-doc gcc-5-multilib gcc-5-doc libgcc1-dbg libgomp1-dbg libitm1-dbg libatomic1-dbg
libasan2-dbg liblsan0-dbg libtsan0-dbg libubsan0-dbg libcilkrts5-dbg libmpx0-dbg libquadmath0-dbg glibc-doc
The following NEW packages will be installed:
binutils cpp cpp-5 gcc gcc-5 libasan2 libatomic1 libc-dev-bin libc6-dev libcc1-0 libcilkrts5 libgcc-5-dev libgomp1 libisl15 libitm1 liblsan0 libmpc3 libmpx0 libquadmath0 libtsan0
libubsan0 linux-libc-dev manpages-dev
0 upgraded, 23 newly installed, 0 to remove and 0 not upgraded.
Need to get 27.6 MB of archives.
After this operation, 99.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu xenial/main amd64 libmpc3 amd64 1.0.3-1 [39.7 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 binutils amd64 2.26.1-1ubuntu1~16.04.5 [2311 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial/main amd64 libisl15 amd64 0.16.1-1 [524 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 cpp-5 amd64 5.4.0-6ubuntu1~16.04.5 [7786 kB]
...
Processing triggers for libc-bin (2.23-0ubuntu9) ...
ubuntu@ubuntu-xenial:/vagrant$
No need to install Linux manually
The Ubuntu
is installed manually and the second working_default_xfasfa
is installed with Vagrant.
In summary
brew cask install vagrant
brew cask install vagrant-manager
vagrant box add ubuntu/xenial64 https://app.vagrantup.com/ubuntu/boxes/xenial64
cd /Users/cychong/Public/working
vagrant init ubuntu/xenial64
vagrant up
vagrant ssh
reference
- Vagrant | Mac OS X Setup Guide
- VirtualBox와 Vagrant의 기본 사용법 - 나만모르는 이야기
- RORLAB | rBlog : Vagrant를 이용한 손쉬운 개발환경 구축
#vagrant #TIL