Vagrant 와 Virtualbox 를 이용한 Ubuntu 16.04 가상머신 설정
Virtualbox 설치
echo "deb http://download.virtualbox.org/virtualbox/debian xenial contrib" | sudo tee --append /etc/apt/sources.list
wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add -
sudo apt-get update
sudo apt-get install virtualbox-5.2
Virtualbox Extentension Pack 설치
LatestVirtualBoxVersion=$(wget -qO - http://download.virtualbox.org/virtualbox/LATEST.TXT) && wget "http://download.virtualbox.org/virtualbox/${LatestVirtualBoxVersion}/Oracle_VM_VirtualBox_Extension_Pack-${LatestVirtualBoxVersion}.vbox-extpack"
sudo VBoxManage extpack install --replace Oracle_VM_VirtualBox_Extension_Pack-${LatestVirtualBoxVersion}.vbox-extpack
Vagrant 설치
- deb 다운로드 : https://www.vagrantup.com/downloads.html
wget https://releases.hashicorp.com/vagrant/2.1.2/vagrant_2.1.2_x86_64.deb
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
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
config.vm.box = "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
# config.vm.network "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 127.0.0.1 to disable public access
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
config.vm.network "public_network", bridge: 'enp3s0', ip: "192.168.0.92"
# 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
end
#
# 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
# SHELL
end
Vagrant 파일에서 위에 표시된 라인을 추가하거나 수정했다. 40 라인의 192.168.0.92
는 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 시작 쉘 스크립트
#!/bin/sh
#
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 버전을 설치한다.
참고 : https://unix.stackexchange.com/a/289686
여기서 널 보게 되네,, 반가워,
ㅎㅎㅎ 나도 왠지 반갑다!