Mac環境にVagrantでCentOS7をインストールする

Mac環境にCentOS7をインストールする。
最終的な目的はGitLabをローカルで使いたいため。

環境
Mac Sierra
Vagrant 2.2.4
VirtualBox 6.0.4

手順
VagrantとVirtualBoxはインストールしておく。
Vagrant:https://www.vagrantup.com/downloads.html
VirtualBox:https://www.virtualbox.org/wiki/Downloads

Vagrantでboxになにもないことを確認する。

$ vagrant box list
There are no installed boxes! Use `vagrant box add` to add some.

CentOS7をBoxに追加する。リストが表示されるのでvirtualboxの3を選択する。

$ vagrant box add centos/7
==> box: Loading metadata for box 'centos/7'
    box: URL: https://vagrantcloud.com/centos/7
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: Successfully added box ‘centos/7’ (v1902.01) for ‘virtualbox’!」メッセージが表示されたらBox追加が完了する。
Boxが追加されていることを確認する。

$ vagrant box list
centos/7 (virtualbox, 1902.01)

CentOS7用のディレクトリを作成する。今回は/User/user_nameディレクトリ以下に作成した。

$ mkdir centos7
$ cd centos7

CentOS7の環境用のVagrantfileを作るために初期化コマンドを実行する。
実行後、Vagrantfileファイルができているかを確認する。

$ vagrant init centos/7
$ ls -la

Vagrantfileファイルの中身をみるとCentOS7が指定されているのがわかる。

config.vm.box = "centos/7"

VagrantのコマンドでCentOS7を起動する。

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...

起動の確認をする。

$ vagrant status
Current machine states:

default                   running (virtualbox)

VirtualBoxを立ち上げると実行中と出力されている。
VirtualBox

CentOS7にSSH接続をしてCentOSのバージョンを出してみる。

$ vagrant ssh
[vagrant@localhost ~]$ cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core) 

CentOS7を停止する。

$ vagrant halt
==> default: Attempting graceful shutdown of VM...

停止の確認をする。

$ vagrant status
Current machine states:

default                   poweroff (virtualbox)

以上でMacの環境にVagrant+VirtualBoxを使ってCentOS7の環境が作れた。

コメント

タイトルとURLをコピーしました