4
4

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.

真っ新なPCにVagrantを使って仮想サーバを立てる

Last updated at Posted at 2013-07-10

CentOSのイメージファイルを落としてCDに焼く

まずは、理研などからisoイメージファイルを落としてくる。今回は、6.4の64bit版、minimalを利用する。

CentOSのインストールを行う

ここはGUIなので割愛。マイナーバージョンは違うが、下記サイトが参考になった。
参照:CentOS6.2の最小構成インストール - minimal - | パソコン技術者の日々

疎通確認

$ ping -c 4 google.com
Unknown host google.com

ネットワーク設定

vi  /etc/sysconfig/network-script/ifcfg-eth0
-ONBOOT=no
+ONBOOT=yes

再起動

/etc/rc.d/init.d/network restart

再度疎通確認

$ ping -c 4 google.com
PING google.com (173.194.38.101) 56(84) bytes of data.
64 bytes from nrt19s18-in-f5.1e100.net (173.194.38.101): icmp_seq=1 ttl=51 time=2.42 ms
64 bytes from nrt19s18-in-f5.1e100.net (173.194.38.101): icmp_seq=2 ttl=51 time=2.29 ms
64 bytes from nrt19s18-in-f5.1e100.net (173.194.38.101): icmp_seq=3 ttl=51 time=2.35 ms
64 bytes from nrt19s18-in-f5.1e100.net (173.194.38.101): icmp_seq=4 ttl=51 time=2.34 ms

--- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3006ms
rtt min/avg/max/mdev = 2.296/2.356/2.425/0.057 ms

User作成

$ adduser worker
$ passwd worker
$ visudo
worker ALL=(ALL) ALL

必要なもののinstall

yumのfastestmirrorプラグインをロード

$ yum -y install yum-fastestmirror #一番早いサーバからパッケージを取得してくれるようになる
$ yum -y update # パッケージのアップデート
$ yum groupinstall -y "Development Tools" # 開発に必要なツールを入れてくれる
$ yum -y install wget # が、wgetは入らないので別途インストール
$ yum -y install vim # これはお好みで

ここまで終わったら一旦再起動

$ reboot

これを忘れるとVirtual Box立ち上げ時に "Error! Your kernel headers for kernel [version] cannot be found" と怒られる

RPFforgeからDKMSのインストール

まずは。RPMforgeリポジトリを導入して、標準リポジトリで提供されないパッケージをyumでインストールできるようにする。ここはInstalling RPMforgeを参考に進めていく。

$ wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm #上記サイトから利用しているCentOSのバージョンに合ったものを選んで利用する
$ rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
$ rpm -Uvh rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm #wgetでダウンロードしたrpm名を指定する

デフォルトでRPMForgeからインストールしないようにする

あくまでサードパーティとのレポジトリなので、必ずしも最新ではないし、安全を保証できないので、必要な時だけ明示的に --enablerepoをつけで有効にするようにするため、RPMForgeリポジトリをデフォルトでは無効にする。

$ vim /etc/yum.repos.d/rpmforge.repo

-enabled=1
+enabled=0

DKMSをインストール

$ yum -y --enablerepo rpmforge install dkms

KEARN_DIRの定義

$ vim ~/.bashrc

VirtualBoxのインストール

Installing and using VirtualBox on CentOSを参考に進めていく。

$ cd /etc/yum.repos.d/
$ wget  http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo

デフォルトでVirtualboxからインストールしないようにする

$ vim virtualbox.repo

-enabled=1
+enabled=0

Virtual Boxをインストール

$ yum -y --enablerepo virtualbox install VirtualBox-4.2

vboxusersグループにuserを追加

$ usermod -a -G vboxusers root

VirtualBoxの起動

$ /etc/init.d/vboxdrv setup

Vagrantのインストール

Vagrant Downloadsから利用したいversionのrpmを探す

$ yum -y localinstall http://files.vagrantup.com/packages/7e400d00a3c5a0fdf2809c8b5001a035415a607b/vagrant_1.2.2_x86_64.rpm

BaseBoxの追加

VagrantでVMを構築する場合、BaseBoxと呼ばれるひな形を利用する。Vagrantbox.esには様々なVMイメージが用意されているが、危険性を指摘する声もあるので自己判断で。
参照:vagrant ユーザよ、その VM は安全なのか? (veewee のすゝめ) - Hack like a rolling stone

今回は、アメリカ国立再生可能エネルギー研究所の提供するBaseBoxを利用して進める。

$ vagrant box add CentOS6.4  http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20130427.box
$ mkdir foobar
$ cd foobar/
$ vagrant init CentOS6.4

VMの立ち上げ

$ vagrant up

VMに接続

$ vagrant ssh foobar
4
4
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
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?