0
1

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.

Windows 10 に Vagrant VirtualBox CentOS7 インストール

Posted at

Windows 10 に Vagrant VirtualBox CentOS 7.8 をインストールしてみた。

はじめに

ずっとVirtualBox を単独で使用していたが、みんな Vagrant を使ったほうが便利と言ってる。
本当にそうなのかインストールして試してみた。

環境

  • Windows 10
  • Vagrant 2.2.7
  • VirtualBox 6.0.20 r137117 (Qt5.6.2)
  • CentOS Linux release 7.8.2003 (Core)

インストール

Vagrant

Windowsにインストールするだけなので、詳細は省略。
Vagrant本家サイトから環境に合わせてインストール

VirtualBox

以下同文。
VirtualBox本家サイトから環境に合わせてインストール

Vagrant Plugin

任意で以下の2つのプラグインを入れる。

  • 共有ディレクトリがマウントできなくて、エラー吐く対応
cmd
 vagrant plugin install vagrant-vbguest
  • DISK拡張したい対応
cmd
 vagrant plugin install vagrant-disksize  

※注:
・プロキシは使わないので、vagrant-proxyconf は使用しない。
・hostsを自動で書き換えるメリットは無いので、vagrant-hostmanager は使用しない。
・SnapShotはデフォルトで使用できる。( ※vagrant-vbox-snapshot は入れたら逆に動かない)


仮想マシン作成

 BOXのDLと追加

※BOXは(世界中の誰かが作った)VMテンプレートと同義と理解。

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

※VMテンプレートのDLなので、終わるまで待つ。
※確認は、vagrant box list で確認。

 仮想マシンの初期化。(フォルダにVagrantファイルを作成)

・作らなくても良いが、他のVMも管理したいならフォルダを作って、その配下にVagrantファイルを作成

cmd
 mkdir xxxx  ※ <- xxxx は任意
 cd xxxx

 Vagrantfile 作成

cmd
 vagrant init centos/7

 Vagrantfile 編集

Vagrantfile で変えたところ

### box の自動更新確認を無効
if Vagrant.has_plugin?("vagrant-vbguest")
    config.vbguest.auto_update = false
  end
### 共有フォルダ指定
  config.vm.synced_folder "C:/Users/user/Documents/vm_shared", "/vagrant", type: "virtualbox"
### VirtualBoxのGUI名指定
  config.vm.define :test01 do |node|
    node.vm.box = "centos/7"
### disk拡張
    node.disksize.size = '50GB'
### VM内のホスト名指定、cpu,memory指定, vm.define と同時指定すると v.name が優先
    node.vm.hostname = "test01"
    node.vm.network "private_network", ip: "192.168.33.11"
    node.vm.provider "virtualbox" do |v|
       v.name = "test01"
       v.cpus = 2
       v.memory = 2048
    end
  end

仮想マシン起動

cmd
vagrant up

仮想マシンlogin

cmd
vagrant ssh

※動確のため、一応上記コマンドでログインするが、後でsshの設定必須。

仮想マシン停止

cmd
vagrant halt

まとめ

私見ですが、現段階では「Vagrantが便利」という感覚は全くない。

  • VMテンプレートなので、OSパーティションは自由に切れない。※要件で、/optだけ50GB欲しい時など、無力。
  • cpu,memoryの増減、共有フォルダの使用、SnapShot、export/importって、VirtualBoxのGUIから全部できるし、そっちの方が早いしわかりやすい。

※「~やってみた」系で、目的なくただインストールしたというだけで、今のところ、メリットは感じられず。今後、使いこなしていくとメリットは実感できるのか、期待する。

参考にさせていただいたサイト

https://qiita.com/jonghyo/items/5bee0916d54a12862157
https://webbibouroku.com/Blog/Article/vagrant
https://qiita.com/oreo3@github/items/4054a4120ccc249676d9
https://qiita.com/esparrago_b/items/a919f985ca01de253820
https://pentan.info/server/vagrant/vagrant_vbguest_note.html
https://weblabo.oscasierra.net/vagrant-snapshot/

0
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?