LoginSignup
3
1

More than 5 years have passed since last update.

Windows10にVagrantでCentos7環境構築する

Posted at

環境

  • VirtualBox 5.1.24
  • Vagrant 2.0.4

手順

Boxのリスト表示

ほしいBoxがリストに表示されていないことを確認します。

powershell
> vagrant box list

Boxのダウンロード

今回はVagrantCloudのリストで上位にあったものをDLします。
VagrantCloudのBoxリスト
https://app.vagrantup.com/boxes/search
今回使用するCentOS7
https://app.vagrantup.com/centos/boxes/7

以下のコマンドでBoxを追加します。
https://...のパスにあるイメージを基に、centos/7という名前でBoxを追加するよ」という意味だと思ってます。

powershell
> vagrant box add centos/7 https://app.vagrantup.com/centos/boxes/7

ちなみにこのイメージをダウンロードする場合、引数addに続くBox名をcentos/7以外を指定するとエラーになってしまいました。
というわけでcentos/7というBox名にしています。

ダウンロードが始まると、プロバイダの選択肢が表示されます。
今回はVirtualBoxを選択します。

powershell
1) hyperv
2) libvirt
3) virtualbox
4) vmware_desktop

Enter your choice: 3

ダウンロードが終わったら、下記コマンドでBoxが追加されていることを確認します。

powershell
> vagrant box list
centos/7  (virtualbox, 1901.01)

仮想マシンの作成

以下コマンドで仮想マシン用のディレクトリを作成して移動します。
パスはほかのマシンと被ってなければどこでもいい、はず。

powershell
> mkdir centos7
> cd centos7

次に、VagrantFIleを作成します。
vagrant initコマンドを実行し、カレントディレクトリにVagrantFIle(仮想マシンごとの設定ファイル)を作成します。
引数に先ほどダウンロードしたボックス名centos/7を指定することで、作成されるVagrantFIleにcentos/7の名前が自動で反映されます。

powershell
> vagrant init centos/7

Vagrantfileの編集

いろいろやることはあるかと思いますが、ひとまずSSHでつなげるようにhost-onlyネットワークのIPアドレスをアンコメントアウト→編集しておきます。
今回は192.168.33.30としています。

変更前のVagrantfile
  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # config.vm.network "private_network", ip: "192.168.33.10"
変更後のVagrantfile
  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  config.vm.network "private_network", ip: "192.168.33.30"

そのほかの設定についてはVagrantfile 覚書が詳しいようです。

仮想マシンの起動

以下コマンドで、仮想マシンを起動します。

powershell
> vagrant up
3
1
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
3
1