0
1

More than 1 year has passed since last update.

Windows11でVirtualBox+Vargrantの仮想環境構築

Posted at

作業環境

項目
OS Windows 11 Home
プロセッサ Core i7-1165G7
実装RAM 32.0 GB
Disk 475 GB

あると便利なもの

  • Gitbash
  • VScode

インストール対象

2023/3/31時点で最新のものを選択

作業内容

  • VirtualBoxのインストール
  • Vagrantのインストール
  • Vargrantの初期セットアップ
  • 仮想マシンの作成
  • 仮想マシンにSSH接続

作業開始

VirtualBoxのインストール

  1. リンクをクリックして、Virtualboxをダウンロードする。
  2. ダウンロードした.exeファイルを実行する。
  3. 起動したインストーラに従い、デフォルト設定でインストール完了まで進む。
  4. インストール後にVirtualboxを起動する。
  5. 拡張パックをリンクからダウンロードする。
  6. ダウンロードした拡張パックのファイルを実行してインストールする。

Vagrantのインストール

  1. リンクをクリックして、Vagrantをダウンロードする。
  2. ダウンロードした.msiファイルを実行する。
  3. 起動したインストーラに従い、デフォルト設定でインストール完了まで進む。
  4. インストール後に再起動を実施する。

Vargrantの初期セットアップ

  1. 作業フォルダを作成する。
    $ mkdir -p ~/Desktop/work/vagrant/AL2
    $ cd ~/Desktop/work/vagrant/AL2
    $ mkdir ../share
    
  2. vagrantの初期化
    $ vagrant init bento/amazonlinux-2
    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
    `vagrantup.com` for more information on using Vagrant.
    
  3. Vagrantfileの編集

パラメータは好みに合わせて変更

```
$ cat << EOF > Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "bento/amazonlinux-2"
  config.vm.network "private_network", ip: "192.168.10.10"
  config.vm.synced_folder "../share", "/tmp/share",owner: "root", group: "root"
  config.vm.provider "virtualbox" do |vb|
    vb.gui = false
    vb.name = "default"
    vb.memory = "2048"
    vb.cpus = 2
  end
end
EOF
```
  1. プラグインの確認
    $ vagrant plugin list
    vagrant-vbguest (0.31.0, global)
    
  2. 仮想マシンを起動する。
    $ vagrant up
    Bringing machine 'default' up with 'virtualbox' provider...
    ==> default: Importing base box 'bento/amazonlinux-2'...
    ==> default: Matching MAC address for NAT networking...
    ==> default: Checking if box 'bento/amazonlinux-2' version '1.2.1' is up to date...
    ==> default: A newer version of the box 'bento/amazonlinux-2' for provider 'virtualbox' is
    ==> default: available! You currently have version '1.2.1'. The latest is version
    ==> default: '1.3'. Run `vagrant box update` to update.
    … 以下略
    … 
    
    

Virtualboxから確認のポップアップがいっぱいでる。
誤ってキャンセルしたところVMが起動しなくなったので、すべて許可したほうが良いっぽい。

  1. 仮想マシンへのSSH接続
    $ vagrant ssh
    
           __|  __|_  )
           _|  (     /   Amazon Linux 2 AMI
          ___|\___|___|
    
    https://aws.amazon.com/amazon-linux-2/
    115 package(s) needed for security, out of 162 available
    Run "sudo yum update" to apply all updates.
    
    This system is built by the Bento project by Chef Software
    More information can be found at https://github.com/chef/bento
    
  2. 仮想マシン上での確認
    [vagrant@vagrant ~]$ date;uname -n;id
    Fri Mar 31 13:59:24 UTC 2023
    vagrant
    uid=1000(vagrant) gid=1000(vagrant) groups=1000(vagrant),4(adm),10(wheel),190(systemd-journal)
    [vagrant@vagrant ~]$ ls -l /tmp
    total 28
    drwxrwxrwx 1 root root     0 Mar 31 13:32 share
    drwx------ 3 root root    17 Mar 31 13:53 systemd-private-00a8f23b99374923b86362293f3d579e-chronyd.service-h2mQ0a
    -rw-r--r-- 1 root root 27718 Mar 31 13:54 vboxguest-Module.symvers
    [vagrant@vagrant ~]$
    
    

おしまい

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