Vagrantのインストール
Vagrant公式サイト
Boxファイルのダウンロード
参考URL
・VagrantBoxファイルの一覧
http://www.vagrantbox.es/
・VagrantCloudのCentOS64bit版のたぶん最新(2014/10/31現在)
https://vagrantcloud.com/nrel/boxes/CentOS-6.5-x86_64
・CentOSだと今は下記URLからがたぶん最新(2014/10/31現在)
https://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.5-x86_64-v20140504.box
VagrantにBoxファイルを追加
$ cd [ダウンロードディレクトリ] # ダウンロードしたディレクトリへ移動
$ vagrant box add centos65 CentOS-6.5-x86_64-v20140504.box
==> box: Adding box 'centos65' (v0) for provider:
box: Downloading: file:///Users/knife0125/Develop/100_NexSeed/ 100_vagrant/10_boxes/lxc-centos6.5-2013-12-02.box
==> box: Successfully added box 'centos65' (v0) for 'lxc'!
$ vagrant box list # Vagrantに保持されているBoxファイルを一覧表示
centos64_ja (virtualbox, 0)
centos65 (virtualbox, 0)
Vagrantで仮想マシンを作成
※ 全てのコマンドをVagrantプロジェクトを作成するディレクトリ直下でやりましょう!
"vagrant init"でVagrantfileを作成
$ vagrant init centos65
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.
Vagrantfileを編集して仮想マシンの設定を変更
プライベートネットワーク内でのIPを固定する
例:IPアドレスを192.168.33.10に固定
$ vim Vagrantfile
+ config.vm.network "private_network", ip: "192.168.33.10"
仮想マシンのメモリ容量を設定する
例:メモリ容量を1024MBに変更
$ vim Vagrantfile
+ config.vm.provider "virtualbox" do |vb|
+ vb.customize ["modifyvm", :id, "--memory", "1024"]
+ end
ホストマシンとゲストOSの間で共有フォルダを設定する
MacローカルのVagrant緑化のhttpdStoreディレクトリと、vagrantログイン後の/var/www/htmlディレクトリを共有フォルダに設定する。
(そうすることで、Macローカルファイルをいじることが、イコールでvagrantサーバのApache配下のファイルをいじることに変更することができる)
$ vim Vagrantfile
+ config.vm.synced_folder "./httpdStore", "/var/www/html/"
Vagrantサーバを起動
$ vagrant up # vagrantサーバを起動
$ vagrant ssh # vagrantサーバへssh接続
その他 Vagrantコマンド
Vagrantサーバを起動する時
$ vagrant up
VagrantへSSH接続する時
$ vagrant ssh
Vagrantの設定変更を反映させたい時
$ vagrant reload
Vagrantサーバを落とす時
$ vagrant halt
Vagrantのサーバを殺したい時
※ 思わずVirtualBox側で削除すると、Vagrant的には良くないことになるので、きちんとdestroyしましょう!
$ vagrant destroy