Virtual Boxを入れる
virtual boxに必要なdkmsを入れる
# yum info dkms
# yum install dkms
virtual box用リポジトリ設定
# cd /etc/yum.repos.d/
# wget http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo
リポジトリ設定の更新
# yum update
virtual boxインストール
# yum search VirtualBox
# yum install VirtualBox-4.3.x86_64
virtual boxに必要な設定
# usermod -a -G vboxusers <user_name>
例:
# usermod -a -G vboxusers root
vagrant入れる
vagrant取得
wget https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.4_x86_64.rpm
vgrantインストール
yum install vagrant_1.7.4_x86_64.rpm
インストールできたか確認
vagrant
Usageが出ればOK
エラーが出た場合の対処
下記のエラーが出た場合、
/lib/ld-linux.so.2: bad ELF interpreter:
ld-linux.so.2を入れる
参考:http://slumbers99.blogspot.jp/2012/04/centos-64bit-libld-linuxso2-bad-elf.html
yum install ld-linux.so.2
ubuntu用のテンプレートを入れる
vagrant boxを選ぶ
boxを追加する
vagrant box add <自環境内でのbox名> <boxのURI>
例:
vagrant box add ubuntu1404 https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-i386-vagrant-disk1.box
Ubuntuを立てる
作業用ディレクトリを作る
※VMの起動用ファイルが作業しているディレクトリ内に作成されるため、あらかじめディレクトリを作っておくと楽。
任意の名前で良い。例:
mkdir ubuntu1404
cd ubuntu1404
起動用ファイルを作成する
vagrant init <自環境内でのbox名>
起動する
vagrant up
デフォルトだと以下のようなログが出た後、起動完了する
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu1404'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: ubuntu1404_default_1422176679874_12941
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 => 2222 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Connection timeout. Retrying...
default: Warning: Remote connection disconnect. Retrying...
default: Warning: Remote connection disconnect. Retrying...
default: Warning: Remote connection disconnect. Retrying...
default: Warning: Remote connection disconnect. Retrying...
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if its present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
default: /vagrant => /root/vagrant/ubuntu1404
コンソールに接続する
# vagrant ssh
シャットダウンする
# vagrant halt