低レベルインフラエンジニアの忘備録

Linux系の各種作業を自分用の忘備録として残しています

RHEL6にVagrant(CentOS6.7)をインストール

qiita.com

こちらのサイトを参考にさせていただきました。

 

(1)DKMSインストール

カーネルモジュールのビルドとアップデートを助けるフレームワークのようで、カーネルをアップデートしてもViurualBoxのカーネルモジュールも自動的にアップデートされるみたいです。

# yum --enablerepo rpmforge install dkms

⇒あ、rpmforgeつかってます

 

(2)VirtualBoxのインストール

①専用のリポジトリ追加

# cd /etc/yum.repos.d
# wget http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo
# yum --enablerepo=virtualbox list | grep VirtualBox
VirtualBox-3.2.x86_64 3.2.28_100435_el6-1 virtualbox
VirtualBox-4.0.x86_64 4.0.36_104075_el6-1 virtualbox
VirtualBox-4.1.x86_64 4.1.44_104071_el6-1 virtualbox
VirtualBox-4.2.x86_64 4.2.36_104064_el6-1 virtualbox
VirtualBox-4.3.x86_64 4.3.36_105129_el6-1 virtualbox
VirtualBox-5.0.x86_64 5.0.18_106667_el6-1 virtualbox

 

②5.0をインストールしてみる

# yum --enablerepo=virtualbox install VirtualBox-5.0

 

③rootをvboxusers グループに追加

# usermod -a -G vboxusers root

 

 

(3)Vagrantインストール

 

 

(4)Vagrantセットアップ
centos用のボックスを追加

# vagrant box add centos67 https://github.com/CommanderK5/packer-centos-template/releases/download/0.6.7/vagrant-centos-6.7.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'centos67' (v0) for provider:
box: Downloading: https://github.com/CommanderK5/packer-centos-template/releases/download/0.6.7/vagrant-centos-6.7.box
==> box: Successfully added box 'centos67' (v0) for 'virtualbox'!

⇒/root/.vagrant.d/boxes/centos67ディレクトリが作成されます

 

②適当にディレクトリ作成して移動

# cd /root/vagrant/centos67

 

③仮想化環境初期化

# vagrant init centos67
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.


Vagrant起動

# vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos67'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: centos67_default_1461121012287_41932
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 (guest) => 2200 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2200
default: SSH username: vagrant
default: SSH auth method: private key
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 it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
default: The guest additions on this VM do not match the installed version of
default: VirtualBox! In most cases this is fine, but in rare cases it can
default: prevent things such as shared folders from working properly. If you see
default: shared folder errors, please make sure the guest additions within the
default: virtual machine match the version of VirtualBox you have installed on
default: your host and reload your VM.
default:
default: Guest Additions Version: 4.3.30
default: VirtualBox Version: 5.0
==> default: Mounting shared folders...
default: /vagrant => /root/vagrant/centos67

 

⑤ログインしてみる

# vagrant ssh
[vagrant@localhost ~]$ cat /etc/redhat-release
CentOS release 6.7 (Final)
[vagrant@localhost ~]$ su -
パスワード:
[root@localhost ~]#

⇒初期パスワードはvagrantです