前提
今回の手順を検証した環境は以下の通り。
- Windows 10 Pro 20H2
- VirtualBox 6.1.18
- Vagrant 2.2.15
手順
仮想マシン起動
-
VirtualBox と Vagrant をインストールする。
Windows のスタートボタンを右クリックし, コマンドプロンプトをクリックする。
-
vagrant ディレクトリーを作成する。
> mkdir vagrant
-
作業ディレクトリーを移動して, CentOS 用のディレクトリーを作成する。
> cd vagrant > mkdir centos
-
作業ディレクトリーを移動して, Vagrant の設定ファイルを生成する。
> cd centos > vagrant init
-
メモ帳で設定ファイルを開き, Box を
base
からcentos/stream8
変更する。> notepad Vagrantfile
Vagrantfile--- Vagrantfile.org 2021-04-02 20:40:20.328164000 +0900 +++ Vagrantfile 2021-04-02 20:41:36.510341300 +0900 @@ -12,7 +12,7 @@ # Every Vagrant development environment requires a box. You can search for # boxes at https://vagrantcloud.com/search. - config.vm.box = "base" + config.vm.box = "centos/stream8" # Disable automatic box update checking. If you disable this, then # boxes will only be checked for updates when the user runs
-
仮想マシンを起動する。ただし, Box のダウンロードが遅い場合は Box のダウンロードが死ぬほど遅い場合 を参照すること。
> vagrant up
ログイン, ログアウト, シャットダウン
プロンプト記号が >
の場合はコマンドプロンプトで, $
の場合は CentOS にログインした状態で実行すること。
-
仮想マシンにログイン (SSH 接続) する。
> vagrant ssh
-
仮想マシンからログアウトする。
$ exit
-
仮想マシンをシャットダウンする。
$ sudo systemctl poweroff
-
仮想マシンがシャットダウンされていることを確認する。
> vagrant status
参考文献
Box のダウンロードが死ぬほど遅い場合
多少マシになる程度の対策。
- Web ブラウザーを開き, CentOS Cloud images にアクセスする。
- VirtualBox 用 Vagrant Box のリンクをコピーする。
- 今回は
CentOS-Stream-Vagrant-8-20210210.0.x86_64.vagrant-virtualbox.box
とする。
- 今回は
- Windows のスタートボタンを右クリックし, コマンドプロンプトをクリックする。
-
ダウンロード用のディレクトリーに移動し, Box をダウンロードする。
> cd Downloads > curl -LO https://cloud.centos.org/centos/8-stream/x86_64/images/CentOS-Stream-Vagrant-8-20210210.0.x86_64.vagrant-virtualbox.box
-
Box を追加する。
> vagrant box add centos/stream8 CentOS-Stream-Vagrant-8-20210210.0.x86_64.vagrant-virtualbox.box
他の仮想マシンを試す場合
Vagrant Cloud で検索する。
どっとはらい。