LoginSignup
27
27

More than 5 years have passed since last update.

vagrant + virtualbox 仮想サーバ構築

Last updated at Posted at 2013-07-16

VirtualBoxのインストール

公式サイトからダウンロードします

VirtualBox

Mac OS X 環境なので以下を使います

VirtualBox 4.2.16 for OS X hosts x86/amd64

Vagrantの導入

Rubyとrubygemsのバージョン確認

$ ruby -v
ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-darwin12.4.1]
$ gem -v
1.8.23

rubygemsからVagrantをインストールする
(2013/7/17修正)
RubyGems経由だと1.0.7がインストールされてしまうため、
以下サイトから、1.2.2をダウンロードしてインストールした
http://downloads.vagrantup.com/

$ gem install vagrant

インストール出来ました

$ vagrant -v
Vagrant version 1.2.2

OSイメージをダウンロードする
Linux CentOS 6.4 を使います

$ vagrant box add centos http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20130427.box

ダウンロードが終わったら初期化します

$ vagrant init

初期化が終わるとVagrantfile が作成されているので、仮想サーバの起動前にネットワークの設定を行います。
IPは適当に。

$ vi Vagrantfile
  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  config.vm.network :private_network, ip: "192.168.50.12" ← コメントアウトを外します

仮想サーバを起動します

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[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 VM to boot. This can take a few minutes.
[default] VM booted and ready for use!
[default] Configuring and enabling network interfaces...
[default] Mounting shared folders...
[default] -- /vagrant

仮想サーバへsshで接続出来るようにssh設定をします
以下コマンドでssh設定を吐き出してくれるので、

$ vagrant ssh-config --host melody
Host melody
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile "/var/root/.vagrant.d/insecure_private_key"
  IdentitiesOnly yes
  LogLevel FATAL

リダイレクトで、ssh設定をファイルに書き込みます

$ vagrant ssh-config --host melody >> ~/.ssh/config

これで、仮想サーバへのsshでログインが行えます

$ ssh melody

 参考

入門Chef Solo - Infrastructure as Code 伊藤直也 (著)
http://www.amazon.co.jp/%E5%85%A5%E9%96%80Chef-Solo-Infrastructure-Code-ebook/dp/B00BSPH158

27
27
2

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
27
27