21
21

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.

技術検証するならVPSレンタルより、自分のPCで、Vagrant + Chefを使って仮想サーバを立ち上げよう【導入編】【vagrant入門】

Last updated at Posted at 2013-07-21

前提条件

インストール済みパッケージ

ruby 1.9.3p448
gem 1.8.23

VirtualBox

https://www.virtualbox.org/wiki/Downloads
version 4.2.16
をインストール済み

仮想環境を立ち上げる作業開始

仮想環境構築で使う、gemパッケージのvagrantをインストール

$ gem install vagrant
$ vagrant -v
Vagrant version 1.2.2

OSイメージを取得してbox化

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

boxとはインスタンス生成のために使うベースとなるもの。
OSだけではなく、予め様々なパッケージがインストール済みのものもある。
今回は、OSだけで

box listの確認

$ vagrant box list
centos64_64 (virtualbox)

作業用の環境作成

$ mkdir ~/vagrant
$ cd ~/vagrant

作業環境の初期化

$ vagrant init

vagrant起動設定ファイルの作成

$ vim Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
  #使用するbox名
  config.vm.box = "centos64_64"

  #コメントを外すと、VirtualBoxのアプリが立ち上がるよ
  config.vm.boot_mode = :gui
end

どきどきの仮想環境立ち上げ!!!(●^o^●)

$ vagrant up

お、VirtualBoxが立ち上がったぞ!!
でも、毎回立ち上がったら面倒臭いので、、、設定を変えて見ましょう

vagrant起動設定ファイルの作成(修正版)

$ vim Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
  #使用するbox名
  config.vm.box = "centos64_64"

  #コメントを外すと、VirtualBoxのアプリが立ち上がるよ
  #config.vm.boot_mode = :gui
end

2回目の立ち上げ実行

$ vagrant up

ただし2回目はVirtualBoxが立ち上がらないので、どうなったのか心配になります。。

そこで、立ち上がったか確認

$ vagrant status
Current machine states:

default                  running (virtualbox)

running…起動してるやん。

仮想環境につないでみよう( ー`дー´)キリッ

$ vagrant ssh

接続後の環境でおふざけ(これはスルー推奨)

$ echo 'Hello VM'
Hello VM

あまり意味はありません、とりあえす「こんにちは世界(VirtualMachine)」をしたかっただけです。

では、もったいない気もするが破壊します。

$ vagrant destroy

これだけ。。๑゜д˚๑
キヲツケテモウモドラナイ

本当に破壊したか確認

$ vagrant status
Current machine states:

default                  not created (virtualbox)

not created。。モウないのか

今回は、仮想環境立ち上げまでだけなので終わりですが 作って壊せる環境がただ!っていうのが嬉しいところ!! 次は、chefとかを使って、色々httpd起動とかやってみます。

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?