1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Windows10でVirtualBox+Vagrantを利用してLinux環境構築のメモ

Posted at

Windows10でVirtualBox+Vagrantを利用してLinux環境を構築したため、メモとして残ります。

目次

・VirtualBoxのインストール
・Vagrantのインストール
・Linux環境の構築

VirtualBoxのインストール

VirtualBox公式サイトから「Windows hosts」をクリックし、ソフトをダウンロードします。現時点の最新バージョンは、VirtualBox 6.1.4 です。
1.png

・ダウンロードしたインストーラを起動し、手順に従ってインストールします。特に必要な設定とかがないです。
・インストールができたら、以下のような画面が表示されます。
2.png

これでVirtualBoxのインストールが完了です。

Vagrantのインストール

Vagrant公式サイトからWindows 64bitのバージョンを選択し、ダウンロードします。
3.png

・ダウンロードしたインストーラを起動し、手順に従ってインストールします。特に必要な設定とかがないです。
・インストールができたら、PCを再起動します。

これでVagrantのインストールが完了です。

Linux環境の構築

Vagrantを実行するための環境を準備

Vagrantでは、フォルダ単位で仮想マシンを作成するので、ここで「test1」の実行用フォルダを作成する

例:
C:\tool\vagant\test1

Vagrantfileを作成する

Windowsのコマンドプロンプトを開いて、以下のコマンドを実行する

㏅ C:\tool\vagant\test1

次、Vagrantfileを作成する

vagrant init

4.png

これで、test1のフォルダ下に、Vagrantfileというファイルが生成されます。

Vagrantfileを設定する

Vagrantfileファイルを開いて、以下の2か所を修正する

修正箇所1
修正前:
 config.vm.box = "base"
修正後:
  config.vm.box = "centos/7"  //Centos7をインストール
  config.vm.hostname= "192.168.33.10"  //仮想マシンのIPを設定
修正箇所2(コメントアウトを外すだけ)
修正前:
 # config.vm.network "private_network", ip: "192.168.33.10"
修正後:
  config.vm.network "private_network", ip: "192.168.33.10" 

Vagrantfile で設定できるネットーワークについて、以下の記事を参考ください。
Vagrant 事始め 04 - Vagrant のネットワーク設定

仮想マシンを起動する

Windowsのコマンドプロンプトで以下のコマンドを実行して、仮想マシンを初期起動します。

vagrant up

初期起動する際、以下のエラーが出る可能性があります。

エラーメッセージ:
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

その対策:
・管理者ユーザーから、cmdを実行してコマンドプロンプトを開く
・「dism.exe /Online /Disable-Feature:Microsoft-Hyper-V」のコマンドを実行して、Microsoft-Hyper-Vを閉じる

仮想マシンの操作コマンド

仮想マシンを起動できたら、以下のコマンドで操作可能です。

仮想マシンにログイン: vagrant ssh
仮想マシンからログアウト:  exit
仮想マシンを停止: vagrant halt
仮想マシンの削除: vagrant destroy
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?