Vagrant 와 Virtualbox 를 이용한 Ubuntu 16.04 가상머신 설정

Virtualbox 설치

echo "deb xenial contrib" | sudo tee --append /etc/apt/sources.list
wget -q -O- | sudo apt-key add -
wget -q -O- | sudo apt-key add -
sudo apt-get update
sudo apt-get install virtualbox-5.2

Virtualbox Extentension Pack 설치

LatestVirtualBoxVersion=$(wget -qO - && wget "${LatestVirtualBoxVersion}/Oracle_VM_VirtualBox_Extension_Pack-${LatestVirtualBoxVersion}.vbox-extpack"
sudo VBoxManage extpack install --replace Oracle_VM_VirtualBox_Extension_Pack-${LatestVirtualBoxVersion}.vbox-extpack

Vagrant 설치

sudo dpkg -i vagrant_2.1.2_x86_64.deb

Ubuntu 16.04 box 설정

mkdir ubuntu-box
cd ubuntu-box
vagrant init ubuntu/xenial64

box 설정은 Vagrantfile 파일을 수정한다. 개인 PC에서 box 에 ssh 로 접속할 수 있도록 public_network 로 설정하고 bridge 모드로 설정한다. ip는 고정 ip 로 설정한다. cpu 개수와 메모리 용량을 지정한다.

# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at

  # Every Vagrant development environment requires a box. You can search for
  # boxes at = "ubuntu/xenial64"

  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # NOTE: This will enable public access to the opened port
  # "forwarded_port", guest: 80, host: 8080

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine and only allow access
  # via to disable public access
  # "forwarded_port", guest: 80, host: 8080, host_ip: ""

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # "private_network", ip: ""

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network. "public_network", bridge: 'enp3s0', ip: ""

  # 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"

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
    vb.gui = false
  #   # Customize the amount of memory on the VM:
    vb.memory = 1024
    vb.cpus = 1
  # View the documentation for the provider you are using for more
  # information on available options.

  # Enable provisioning with a shell script. Additional provisioners such as
  # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   apt-get update
  #   apt-get install -y apache2

Vagrant 파일에서 위에 표시된 라인을 추가하거나 수정했다. 40 라인의 는 box의 ip 이며 enp3s0 는 box 의 host 이더넷 장치이다. 장치 확인 후 변경해야 한다. cpu와 메모리 설정은 57, 58 라인이다.

box 의 sshd 설정

vagrant up 명령을 통해 box 를 시작한 후 개인 PC에서 box 로 ssh 접속을 하기 위해 sshd 설정을 변경한다.

vagrant ssh
sudo su -
vim /etc/ssh/sshd_config

sshd_config 파일에서 PermitRootLogin 설정을 yes 로 변경하고 PasswordAuthentication 설정 역시 yes 로 변경한다. ssh 서버를 재시작한다.

Vagrant box 시작 쉘 스크립트


DIRECTORY=$(cd `dirname $0` && pwd)

cd "${DIRECTORY}"/ubuntu-box && vagrant up

exit 0

Vagrant VirtualBox Guest Additions 업데이트

vagrant plugin install vagrant-vbguest

또는 아래 명령을 실행한다.

vagrant vbguest --do install

위 과정에서 오류가 발생한다면 이 포스트에 나온 방법대로 vagrant 2.0.3 버전을 설치한다.

참고 :

2 Replies to “Vagrant 와 Virtualbox 를 이용한 Ubuntu 16.04 가상머신 설정”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.