Vagrant를 이용한 ZeroAOS 시험환경구축

1.
문제.

“Virtualization(가상화)와 Hypervisor란?”

IBM이 내놓은 Hypervisors, virtualization, and the cloud: Learn about hypervisors, system virtualization, and how it works in a cloud environment은 가상화와 하이퍼바이저를 다음과 같이 정의합니다. 가상화는 전산자원 대체재(substitues)의 생성이고 대체재를 생성하는 소프트웨어로 정의할 수 있습니다.

Virtualization is the creation of flexible substitutes for actual resources — substitutes that have the same functions and external interfaces as their actual counterparts but that differ in attributes such as size, performance, and cost. These substitutes are called virtual resources; their users are typically unaware of the substitution.

Hypervisors are software or firmware components that can virtualize system resources

hypervisor1 hypervisor2

LXC나 Docker와 같은 기술이 각광을 받기 전에 가상화하면 Hypervisor 기반의 가상화를 말했습니다. Bare Metal방식이든 Hosted 방식이든 하드웨어를 기반으로 한 가상화였습니다. 그런데 컨테이너가 등장하면서 또다른 가상화 방법이 나왔습니다. Hypervisor 기상화가 아닌 container 가상화(Virtualization)입니다. 그러면 다시 질문.

Virtual Machine. Hypervisor, Container, Virtual Environment. 이상의 차이점은 무엇일까요?

먼저 아래의 그림을 보면 Hpervisor와 Container의 차이를 직관적으로 이해할 수 있습니다. Container는 하드웨어가 아닌 소프트웨어(OS)를 기반으로 한 가상화입니다.

Each container(well call it guest operating system) shares the same kernel of the base system. As the container is sharing the kernel with the base system, you can see the processes that are running inside the container from the base system. However when you are inside the container, you will only be able to see its own processes.
Difference between Hypervisor Virtualization and Container Virtualization중에서

HypervisorVScontainer

정리하면 Virtualbox나 VMware는 Hypervisor입니다. Hypervisor에 운용하는 CentOS나 Windows 등의 OS이나 Docker 혹은 LXC와 같은 컨테이너에서 실행하는 어플리케이션(Image)은 Virtual Machine라고 할 수 있습니다.

2.
이제 오늘의 주제인 Vagrant입니다. 한동안 가상화에 관심을 두지 않아서 무엇에 쓰는 물건인지 이해하기 힘들었습니다. 이런저런 글을 읽어보면서 Virtual Machine Manager로 이해하면 좋을 듯 하지만 긴 설명으로 하면 아래가 잘 정리했습니다.

Vagrant is an automation tool for building and deploying virtualized environment. It can easily spin up headless and configured VM in a local machine or cloud platform, helping developers to avoid setting up VM manually. Vagrant can support most of configuration management tools, such as Chef, Puppet and Ansible. Under the hood, Vagrant add a thin wrapper written by Ruby to automate initialization, launching and configuration of virtual machines.
Docker vs. Vagrant중에서

Vagrant는 Hypervisor뿐 아니라 Docker도 지원합니다. Docker와 Vagrant가 서로 대체하는 관계가 아니라 보완하는 관계입니다. 두 제품을 결합하여 사용하는 예제입니다

what-is-docker

Multiple containers in VirtualBox-Vagrant

이제 Vagrant를 이용하여 윈도우7에 Elementary OS를 설치하도록 하겠습니다. ElementaryOS는 최근에 나온 리눅스중 데스크탑으로 괜찮은 제품이라서 MINT계열인 하모니카를 대신하여 사용하고 있습니다.

설치의 1단계는 Vagrant를 설치합니다. 먼저 설치하고자 OS에 맞는 파일을 Vagrant는 Download vagrant에서 받습니다. 저는 Windows 64bit를 설치하였습니다. 이제 설치하려고 하는 OS의 Box(Image)를 구합니다.

Discover vagrant boxes

Elecmentary OS를 검색하면 ElementarOS Box처럼 여럿의 결과를 확인할 수 있습니다. 이중 하나를 선택하였습니다. 처음 저는 다운받는 줄 알았습니다. 그런데 웹 화면을 보고 당황했습니다. 파일을 받을 수 있는 안내가 보이지 않았기때문입니다.

ElementaryOS

사실 답은 화면안에 있습니다. Virtaul Box용 밑에 다음과 같은 글이 있습니다.

agrant init alexgleason/elementaryos-freya64; vagrant up –provider virtualbox

위의 표현은 명령어입니다. 명령어 대로 shell이나 cmd.exe에서 입력을 하면 자동으로 설치합니다. 윈도우7의 명령어창에서 위의 명령어를 실행하면 어떤 결과가 나올까요? Virtualbox를 먼저 설치하라고 나옵니다. 앞서 Hyeprvisor와 Container 및 VM 그리고 VE를 길게 설명한 이유입니다. 처음 Vagrant를 Hypervisor로 이해를 했었습니다. 그런데 vagrant 는 virualbox로 ElementaryOS를 설치한 때 만나는 불편을 없애고 손 쉽게 OS나 어플리케이션을 설치할 수 있도록 도구였습니다. Virtualbox를 설치한 다음 앞서 명령을 실행하였습니다.

먼저 Vagrant 용 환경파일을 저장할 폴더를 생성합니다. 저는 Work밑에 생성하였습니다. 이제 설치명령어를 입력합니다.

vagrant1

vagrant2

특별히 할 일이 없습니다. 이제 Virtualbox로 OS가 정상적으로 설치되었는지를 확인합니다. ElementaryOS의 첫화면입니다. OS X와 비슷합니다.

vagrant3

Vagrant를 사용하는 대부분의 이유는 개발환경입니다. 개발환경별로 Hypervisor를 이용하여 VM을 설치하고 관리하려면 무척이나 불편합니다. 윈도우와 리눅스를 짝으로 사용할 경우 리눅스의 Xwindosw를 사용할 일이 거의 없습니다. 주로 SSH를 이용한 터미날환경이 필요합니다. 때문에 vagratn를 기본으로 SSH접속이 가능하도록 합니다. NAT를 이용하여 네트워크환경을 설정하였고 기본으로

주소:127.0.0.1
포트 : 2222
사용자이름 : vagrant
암호 : vagrant

와 같이 설정합니다. 설치화면 두번째를 보시면 나와 있습니다. 그런데 Virtualbox를 OS를 설치할 때 처럼 NAT 접속이 되지 않더군요. 방법이 여러가지라고 인터넷에 나와 있지만 저는 불편한 방식을 택하였습니다. vagrantfile를 수정하였습니다. 앞서 만든 폴더 밑을 확인하면 vagrantfile을 다음과 같이 편집하였습니다.

# 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.
# config.vm.network “forwarded_port”, guest: 80, host: 8080

# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network “private_network”, ip: “192.168.1.21”

# 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: ‘eth1’, ip: “192.168.1.196”

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

다시 vagrant up을 하였습니다. 위의 화면과 비교하면 네트워크 환경이 달라졌음을 알 수 있습니다.

vagrant6

SSH를 이용하여 접속한 결과입니다.

vagrant5

vagrant4

vagrant를 이용하여 vm을 관리하면 무척 편합니다. 아래를 참고로 하시면 쉽게 이해하실 수 있습니다.

How to Setup Vagrant on Linux to Create Virtual Dev Environment

3.
긴 시간 vagrant를 정리하였습니다. 정리한 이유는 ZeroAOS 2.0를 윈도우환경에서 쉽게 시험하시고자 하는 트레이더에게 길잡이를 제공하기 위함입니다. 오래전 virtualbox를 이용하여 ZeroAOS 전략개발을 위한 환경설정 1을 구축하는 방법을 소개한 적이 있었습니다. 익숙하면 쉽지만 그렇지 않을 경우 노력이 들어갑니다.

이에 비하면 vagrant는 시간과 노력을 절약할 수 있는 도구입니다. 아울러 vagratn와 docker를 이용한 zeroaos box와 image를 시험판으로 공개하려고 합니다. 관심을 바랍니다.

Leave a Comment

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.