24년 11월 이전/ETC

Mac에서 Vagrant 설치하기

Gurumee 2022. 1. 5. 19:30
반응형

개요

이 문서는 Mac에서 vagrant를 설치하는 방법을 다룬다. 나의 개발 환경은 다음과 같다.

  • desktop: macbook pro 13 2020
  • cpu: Intel Core i7 4core
  • memory: 32GB
  • virtualbox 6.1.30

vagrant는 가상 머신을 손쉽게 프로비저닝할 수 있게 도와주는 도구이다. 따라서 가상 머신을 실행시킬 소프트웨어가 필요한데, 필자는 가장 대중적인 virtualbox를 쓴다. 만약 설치되지 않았다면 다음 문서를 참고하라.

 

Mac에서 Virtualbox 설치하기

개요 이 문서는 Mac 에서 virtualbox 를 설치하는 방법을 다룬다. 나의 개발 환경은 다음과 같다. desktop: macbook pro 13 2020 cpu: Intel Core i7 4core memory: 32GB Virtualbox 설치 만약 Homebrew 패키지..

gurumee92.tistory.com

Vagrant 설치

만약 Homebrew 패키지 매니저를 설치했다면 다음 명령어로 손쉽게 설치할 수있다.

$ brew install vagrant
Running `brew update --preinstall`...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/cask).
==> Updated Casks
Updated 1 cask.

==> Downloading https://releases.hashicorp.com/vagrant/2.2.19/vagrant_2.2.19_x86_64.dmg
######################################################################## 100.0%
==> 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!

 

Homebrew 패키지 매니저가 설치되지 않았다면 다음 문서를 참고하라.

 

주니어 엔지니어의 개발 환경 구축하기 (1) 기본 소프트웨어

개요 이 문서는 필자의 맥북에 개발 환경, 특히 개발 시 필요한 소프트웨어 혹은 기본 소프트웨어를 대체하여 유틸리티를 높이는 소프트웨어들을 설치하는 방법에 대해 다룬다. 이 문서에서 다

gurumee92.tistory.com

설치 확인

먼저 터미널에 다음을 입력하면 설치된 버전을 확인할 수 있다.

$  vagrant --version                                                                                              
Vagrant 2.2.19

 

포스팅 작성일 기준 vagrant 공식 문서에서 지원하는 최신 버전인 v2.2.19가 설치된다.

Vagrant 초간단 튜토리얼

이제 적당한 디렉토리에서 터미널을 열어 다음을 입력해보자.

$ vagrant box add centos/8 --insecure
==> box: Loading metadata for box 'centos/8'
    box: URL: https://vagrantcloud.com/centos/8
This box can work with multiple providers! The providers that it
can work with are listed below. Please review the list and choose
the provider you will be working with.

1) libvirt
2) virtualbox

Enter your choice:

 

여기서는 2번 virtualbox를 입력해준다.

...
Enter your choice: 2
==> box: Adding box 'centos/8' (v2011.0) for provider: virtualbox
    box: Downloading: https://vagrantcloud.com/centos/boxes/8/versions/2011.0/providers/virtualbox.box
Download redirected to host: cloud.centos.org
    box: Calculating and comparing box checksum...
==> box: Successfully added box 'centos/8' (v2011.0) for 'virtualbox'!

 

이미지를 다운받기 때문에 시간이 좀 걸린다. 필자의 컴퓨터 기준 3-5분 정도 기다리니까 설치가 완료되었다. 이제 터미널에 다음을 입력한다.

$ vagrant init centos/8
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.

 

vagrant init 명령어를 실행하면, 디렉토리에 Vagrantfile이 생성된다.

$ ls -al
drwxr-xr-x  3 gurumee92  staff    96  1  3 10:09 .
drwxr-xr-x  5 gurumee92  staff   160  1  3 10:09 ..
-rw-r--r--  1 gurumee92  staff  3024  1  3 10:09 Vagrantfile

 

Vagrantfile의 작성된 설정을 토대로 가상 머신을 생성한다. 터미널에 다음을 입력해보자

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos/8'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'centos/8' version '2011.0' is up to date...
==> default: Setting the name of the VM: vagrant-tutorial_default_1641176997244_9609
==> 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: 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: vagrant
    default: SSH auth method: private key
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    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: No guest additions were detected on the base box for this VM! Guest
    default: additions are required for forwarded ports, shared folders, host only
    default: networking, and more. If SSH fails on this machine, please install
    default: the guest additions and repackage the box to continue.
    default:
    default: This is not an error message; everything may continue to work properly,
    default: in which case you may ignore this message.
==> default: Rsyncing folder: /Users/gurumee92/Studies/vagrant-tutorial/ => /vagrant

 

그 다음 virtualbox를 켜보면 운영체제가 CentOS인 가상 머신이 실행됨을 확인할 수 있다.

 

터미널에 다음 명령어를 입력하면 가상 머신 종료 및 삭제까지 할 수 있다.

$ vagrant destroy                                                         
    default: Are you sure you want to destroy the 'default' VM? [y/N] y
==> default: Forcing shutdown of VM...
==> default: Destroying VM and associated drives...

참고

728x90
반응형