0. 베이그런트(Vagrant) 란?

: 포터블 가상화 소프트웨어 개발환경(Virtualbox, Hyper-X, Docker container, VMware, AWS 등)의 생성 및 유지보수를 위한 오픈 소스 소프트웨어 제품의 하나. 'HashiCorp' 회사의 제품이다. (베이그런트의 default 설치 디렉토리가 C:\HashiCorp\Vagrant\ 이므로 참고하자!)

베이그런트 파일은 Ruby 로 작성되어 있으나, PHP, Python, Java, C#, JS 와 같은 다른 프로그래밍 언어들로 작성된 프로젝트에서도 사용할 수 있다. 

 

프로비저닝(Provisioning) : 사용자의 요구에 맞게 시스템 자원을 할당, 배치, 배포해 두었다가 필요시 시스템을 즉시 사용할 수 있는 상태로 미리 준비해 두는 것을 말한다. 

서버 리소스 프로비저닝, OS 프로비저닝, 소프트웨어 프로비저닝, 스토리지 프로비저닝, 계정 프로비저닝 등이 있으며, 이를 수동으로 처리하는 '수동 프로비저닝'과 자동화 툴을 통해 처리하는 '자동 프로비저닝'으로 나뉜다.

 

Vagrant의 기초 명령어

  • vagrant init
    : 프로비저닝을 해주는 예제 스크립트 생성
  • vagrant up
    : Vagrant 파일을 읽어들여 프로비저닝을 진행
  • vagrant halt
    : 베이그런트에서 다루는 host 들을 종료
  • vagrant destroy
    : 베이그런트의 host 들을 삭제
  • vagrant ssh
    : 베이그런트의 host 에 ssh 로 접속
  • vagrant provision
    : 베이그런트의 host 의 설정 변경 적용

 

1. notepad++ 설치

노트패드란++ 란?

: 문서 편집기이자, 소스 코드 편집기이다. Windows 에서 기본으로 제공하는 문서 편집기인 메모장에 견주어, notepad++ 는 탭 편집을 제공하므로 여러 개의 파일을 동시에 열어서 편집할 수 있다. 50개 이상의 프로그래밍, 스크립트, 마크업 언어에 대한 문법 강조 및 코드 접기를 지원한다.

 

다른 문서 편집기가 편하다면 다른 걸 설치해도 상관 없다!

 

notepad++ 설치 링크

https://notepad-plus.en.softonic.com/download?utm_source=SEM&utm_medium=paid&utm_campaign=EN_UK_DSA&gclid=Cj0KCQjwy5maBhDdARIsAMxrkw2axoWUjmN-spAxl4-4mFVV3PpYu8T4pkKupFQJXXt5pGcZw874D4oaAp9ZEALw_wcB 

 

Notepad++

Free open-source text & code editor

notepad-plus.en.softonic.com


2. 베이그런트 설치 및 초기화

2.1. 베이그런트 설치

Vagrant 설치 링크

https://www.vagrantup.com/downloads

 

Vagrant by HashiCorp

Vagrant enables users to create and configure lightweight, reproducible, and portable development environments.

www.vagrantup.com

위 링크를 통해 베이그런트를 설치한 후, 정상적으로 설치되었는지 확인하기 위해, cmd 창을 열어서 'vagrant' 를 입력하면 아래와 같이 나타나게 된다.

Vagrant 정상 설치 이후 cmd

2.2. 베이그런트 초기화

[vagrant 설치 디렉토리 이동] - [베이그런트 초기화]

'vagrant init' 명령어를 통해 C:\HashiCorp 디렉토리에 'Vagrantfile' 이라는 샘플 코드를 만들게 되는데, 이 샘플 코드를 수정하여 앞으로의 베이그런트 원하는 동작을 수행하게 될 것이다.

'Vagrantfile' 샘플 코드


3. 베이그런트 파일 수정플러그인 설치

3.1. 'Vagrantfile' 수정

[config.vm.box] 수정하기

15번째 줄에 보면 'config.vm.box' 라는 부분의 값이 "base"로 되어 있는데, 이 값을 수정하여 Virtualbox 의 VM 이미지의 OS를 지정할 수 있다.

우리가 하려고 하는 CentOS 설정 방법은 위 코드 14번째 줄에 'https://vagrantcloud.com/search' 에서 찾을 수 있다!

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

CentOS로 설정하는 법은 위와 같으므로, 아래 그림처럼 코드를 수정해준다.

[config.vm.box] 값 수정 완료 후

3.2. 베이그런트 플러그인 설치 - Virtualbox 확장팩 위함

Virtualbox 의 경우, 각각의 VM들의 모든 기능을 사용하기 위해서는 Virtualbox 확장팩이 필수적이다. 

베이그런트에서는 Virtualbox 확장팩을 설치할 수 있도록 하는 명령어를 자체 제공하는데, 이는 다음과 같다.

vagrant plugin install vagrant-vbguest

베이그런트를 통한 Virtualbox 확장팩 설치 명령어 결과


4. 프로비저닝한 CentOS 이미지를 Virtualbox 에 설치하기

# 아직 VM을 생성하지 않았다면,
vagrant up

# VM을 생성했으나, 중간에 멈추거나 에러가 나와서 다시 가동시키려고 한다면,
vagrant reload

그런데 3.2에서 설치한 Virtualbox 확장팩 버전에 문제가 있는지, 아래와 같은 에러를 뿜으며 VM 생성이 제대로 되지 않았었다.

Error: Nothing to do
Unmounting Virtualbox Guest Additions ISO from: /mnt
umount: /mnt: not mounted
==> servernfs: Checking for guest additions in VM...
    servernfs: No guest additions were detected on the base box for this VM! Guest
    servernfs: additions are required for forwarded ports, shared folders, host only
    servernfs: networking, and more. If SSH fails on this machine, please install
    servernfs: the guest additions and repackage the box to continue.
    servernfs:
    servernfs: This is not an error message; everything may continue to work properly,
    servernfs: in which case you may ignore this message.
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

umount /mnt

Stdout from the command:



Stderr from the command:

umount: /mnt: not mounted

https://www.devopsroles.com/vagrant-no-virtualbox-guest-additions-installation-found-fixed/

 

Vagrant No VirtualBox Guest Additions installation found [Fixed] - DevopsRoles.com free 1

How to fix the error Vagrant No VirtualBox Guest Additions installation found....

www.devopsroles.com

구글링해본 결과 위 링크의 게시글을 발견했는데, Virtualbox 확장팩의 버전을 '0.21' 로 재설치하면 된다고 하여 시도해봤더니, 베이그런트를 통한 Virtualbox에 CentOS 이미지 설치가 잘 되었다! 재설치 명령어는 아래와 같다.

# 기존의 Virtualbox 확장팩 삭제
vagrant plugin uninstall vagarnt-vbguest

# '0.21' 버전의 Virtualbox 확장팩 설치
vagrant plugin install vagrant-vbguest --plugin-version 0.21

# 확장팩 재설치후, vagrant 다시 프로비저닝
vagrant reload

5. 베이그런트 ssh로 접속하여 상태 확인

'vagrant ssh' 명령어를 입력하여 생성한 VM에 접속하면 아래와 같이 성공한 것을 볼 수 있다.

vagrant ssh 접속 성공 화면


참고

인프런 강의 - [기초-응용] 다양한 환경을 앤서블(Ansible)로 관리하기 with 베이그런트(Vagrant) (조훈 님 강의)

https://www.inflearn.com/course/ansible-%EC%9D%91%EC%9A%A9/unit/10185

 

학습 페이지

 

www.inflearn.com

 

 

  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기