Vagrant & VirtualBoxでCentOS7の仮想マシンを作成する


Vagrant & VirtualBoxを利用して、CentOS7の仮想マシンを構築する手順をメモ。


VagrantとVirtualBoxで仮想環境を構築する① 準備編
VagrantとVirtualBoxで仮想環境を構築する② 初期化&起動編



Vagrant Cloudサイト、CentOS7のboxページより

ページに表示されている内容が少し分かりづらかったのですが、”centos/7″ の部分を抜粋して、
vagrant box add コマンドで実行すればOKです。

vagrant box add centos/7


$ vagrant box add centos/7
==> box: Loading metadata for box 'centos/7'
    box: URL:
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) hyperv
2) libvirt
3) virtualbox
4) vmware_desktop

Enter your choice: 3
==> box: Adding box 'centos/7' (v1905.1) for provider: virtualbox
    box: Downloading:
    box: Download redirected to host:
==> box: Successfully added box 'centos/7' (v1905.1) for 'virtualbox'!


vagrant box list コマンドを実行
(centos/7 の追加に成功している)

$ vagrant box list
centos/7            (virtualbox, 1905.1)
hashicorp/precise64 (virtualbox, 1.1.0)
mycentos6           (virtualbox, 0)


$ ls .vagrant.d/boxes
centos-VAGRANTSLASH-7			hashicorp-VAGRANTSLASH-precise64	mycentos6



$ mkdir vagrant_machines/centos7_lamp

コマンド vagrant init でマシンの初期化を行います。

vagrant init centos/7


$ vagrant init centos/7
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
`` for more information on using Vagrant.

設定ファイルのあるディレクトリのまま、コマンド vagrant up を実行し、初期化した仮想マシンを起動します。

KENnoMacBook-ea:centos7_lamp ken$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos/7'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'centos/7' is up to date...
==> default: Setting the name of the VM: centos7_lamp_default_1562493687656_54049
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2200 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address:
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    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: 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/ken/vagrant_machines/centos7_lamp/ => /vagrant


VagrantとVirtualBoxで仮想環境を構築する② 初期化&起動編

Follow me!