ant-in-giant Memoris

sogaoh の日々のあれこれ(2024〜)was: 勉強会などへの参加速報中心

Windows 7 で Vagrant (1)

目的

  • Vagrant に 慣れる

  • OSインストールに慣れる

  • 開発環境構築に慣れる

参考

手順

  1. (Oracle VM) Virtual Box をインストール

    • 通常は最新版を → Downloads – Oracle VM VirtualBox
    • Vagrantとの組み合わせで過去バージョンのほうが安全そうであれば → Download_Old_Builds – Oracle VM VirtualBox

      • インストールは Wizard に従ってデフォルトで進んだ。  
      • 途中、ネットワーク関係のドライバをどうする?と聞かれるが、そのまま Next した。
  2. Vagrant をインストール

    • 通常は最新版を → Download Vagrant - Vagrant
    • 場合によっては過去版を → Vagrant - Download Archives

      • インストールは Wizard に従ってほぼデフォルトで進んだ。インストール先だけちょっと変えた。( C:\Vagrant にした)  
      • 完了後、OS再起動を求められるので、おとなしく再起動した
      • その後コマンドプロンプトで vagrant -v すればバージョンが確認できる
  3. box ファイルの add

  4. box ファイルの init 、up

    • コマンドプロンプトで以下のようなコマンドを実行して VM 用ディレクトリを作成、移動する

      C:> mkdir c:\VirtualBoxVMs\centos64_01 C:> cd c:\VirtualBoxVMs\centos64_01

    • vagrant init する

      C:\VirtualBoxVMs\centos64_01>vagrant init centos64_01
      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.

      • この時点で(?あるいは up 時)、C:\Users\hisashi.soga\VirtualBox VMs\ 配下にVM実体が配置される。
    • vagrant up する

      C:\VirtualBoxVMs\centos64_01>vagrant up
      Bringing machine 'default' up with 'virtualbox' provider...
      [default] Importing base box 'centos64_01'...
      [default] Matching MAC address for NAT networking...
      [default] Setting the name of the VM...
      [default] Clearing any previously set forwarded ports...
      [default] Clearing any previously set network interfaces...
      [default] Preparing network interfaces based on configuration...
      [default] Forwarding ports...
      [default] -- 22 => 2222 (adapter 1)
      [default] Booting VM...
      [default] Waiting for machine to boot. This may take a few minutes...
      DL is deprecated, please use Fiddle
      [default] Machine booted and ready!
      [default] Mounting shared folders...
      [default] -- /vagrant

      • /vagrant は共有ディレクトリになっている。パーミッション 777 なので Windows 側から好きにファイルを置けそう。
  5. VM に ssh アクセスしてみる

    • 試しに vagrant ssh

      C:\VirtualBoxVMs\centos64_01>vagrant ssh
      ssh executable not found in any directories in the %PATH% variable. Is an
      SSH client installed? Try installing Cygwin, MinGW or Git, all of which
      contain an SSH client. Or use the PuTTY SSH client with the following
      authentication information shown below:

      Host: 127.0.0.1
      Port: 2222
      Username: vagrant
      Private key: C:/Users/hisashi.soga/.vagrant.d/insecure_private_key

  6. 今宵はここまで。VM をおとす

    • vagrant halt

      C:\VirtualBoxVMs\centos64_01>vagrant halt
      [default] Attempting graceful shutdown of VM...
      DL is deprecated, please use Fiddle

おまけ:心配