4
3

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.

Virtual Boxでローカル環境を作る初心者メモ

Last updated at Posted at 2018-09-11

ローカル開発環境を作る

引き続きの環境づくり。
Virtual Boxの上にCentOS乗せるんだけどVagrantというのをつなぎにして扱いやすくする方法。

手順はドットインストール。
ローカル開発環境の構築 macOS編 (全14回) - プログラミングならドットインストール

Virtual Box

virtualbox.orgからダウンロードしてインストール

Vagrant

vagrantup.com からダウンロードしてインストール

フォルダ構成つくりと設定

ホームフォルダ>MyVagrant>MyCentOS_201809 の下に仮想環境作って、IPアドレスを192.168.33.10にする。

# ホームフォルダの下にMyVagrantとかでVagrant用のフォルダを作る
$ mkdir MyVagrant

# 作ったフォルダに移動
$ cd MyVagrant/

# サーバーが入るフォルダ作る(お試しで作るので目印に月いれてみる)
$ mkdir MyCentOS_201809

# 作ったとこに移動
cd MyCentOS_201809/

# CentOS6.8で初期化。設定ファイルの'Vagrantfile'ができつつ仮想環境ができる。
vagrant init bento/centos-6.8

# 'Vagrantfile'に192.168.33.10と記述する(エディタで書く代わりのコマンド)
sed -i '' -e 's/# config.vm.network "private_network", ip: "192.168.33.10"/config.vm.network "private_network", ip: "192.168.33.10"/' Vagrantfile

vagrant initすると以下のメッセージ出してくれました。

Vagrantfileがこのフォルダにできたよ。
vagrant upで起動できるよ。
Vagrantfileにあるコメント読んで。
ドキュメントは vagrantup.com にあるよ。

IPアドレス書き込むコマンド打ったあとVagrantfile開いてみたら15行目と35行目に初期化したOSと設定したIPアドレスが書かれてました。

# 15行目
config.vm.box = "bento/centos-6.8"

# 35行目
config.vm.network "private_network", ip: "192.168.33.10"

仮想マシンを起動して終了

# 仮想マシンを起動する(起動したい仮想マシンのVagrantfileのあるフォルダで)
$ vagrant up

# 仮想マシンの状態を確認する
$ vagrant status

# 仮想マシンの停止
$  vagrant suspend 

# 強制終了したいときは
$ vagrant halt

Cloud9でもいいのか、、、
いやでもキッチンのWiFi弱いし、、、
あとでCloud9もやってみよう。

今日のコマンド

lessでもファイルの中身は見れる
less Vagrantfile

4
3
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
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?