LoginSignup
19

More than 5 years have passed since last update.

仮想環境 Vagrant + VirtualBox ~ Centos6.5 (OS X Mavericks)

Last updated at Posted at 2014-09-17

1. Vagrantのインストール

公式サイトから最新版をダウンロードしてインストール
http://www.vagrantup.com/

今回は、Vagrant-1.6.5.dmgをダウンロードし インストールしました。

  • インストール確認
$ vagrant --version
Vagrant 1.6.5

2. VirtualBoxのインストール

公式サイト最新版をダウンロードしてインストール
https://www.virtualbox.org/

今回は、VirtualBox-4.3.16-95972-OSX.dmgをダウンロードし インストールしました。

3. 仮想マシンの作成

Vagrantでは[box]という仮想マシンのイメージを作成する事で簡単に複数の仮想マシンを作成できます。

  • vagrantにcentosのboxを追加

  • 追加したboxから仮想マシンを作成して起動

boxの追加

  • 追加

今回は、以下からダウンロードして追加しました。

$ vagrant box add centos6.5 https://github.com/2creatives/vagrant-centos/releases/download/v6.5.3/centos65-x86_64-20140116.box
  • 確認
$ vagrant box list
centos6.5 (virtualbox,0)

VMの作成

  • 作成 VMを作成する場所へ移動し、以下のコマンドを実行。
$ vagrant init centos6.5

準備が完了!

VMの起動

$ vagrant up

接続

ターミナルで接続してみる。

$ vagrant ssh

vagrantユーザーでログインできていればOK!!!
※デフォルトでvagrantユーザーが用意されています。

  • ログアウト
$ exit

VMの終了

$ vagrant halt

その他のコマンド

  • VMの再起動
$ vagrant reload
  • VMの状況の確認
$ vagrant status

4. 仮想マシンの設定

macからvagrant上の仮想マシンのにアクセスする為の設定
[Vagrantfile]というファイルが設定ファイルになる。

今回は、Railsでポート3000を使用する為のポートフォアリング設定を追加する。

※mac側の操作だよ。

$ vim Vagrantfile
config.vm.network "forwarded_poot", guest: 3000, host: 3000

後は、リロードなり、再起動すればOKです。

お疲れ様でした♪

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
19