CentOS環境にvagrant+VirtualBoxを導入
CentOS環境にvagrant+chef(+VirtualBox)を導入するメモ
以下理由により、VMWareESXi5.0をインストールしていたPCを潰して、CentOS6.6をインストールした。
・vagrantはVMWare(player)でも動作する様子。また、vagrant-vsphereというものがあるが、単体のVMWareESXiのみでは動くのかわからなかった。
・インストールしていたPCは、OSレスで購入していた。
導入にあたり、以下URLが大変役に立ちました。GUIを利用しないのは、大変スムーズですね。
○DKMS のインストール
$ sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm [sudo] password for manatee: http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm を取得中 警告: /var/tmp/rpm-tmp.TgJlkV: ヘッダ V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY 準備中... ########################################### [100%] 1:epel-release ########################################### [100%] $ sudo yum install dkms $ chkconfig --list |grep dkms dkms_autoinstaller 0:off 1:off 2:on 3:on 4:on 5:on 6:off
注意:DKMSのインストールにて、kernel-develパッケージが追加インストールされるが、
同時にkernelのバージョンをそろえないとモジュールがロードしない。
○VirtualBox のインストール
リポジトリ追加
$ cd /etc/yum.repos.d/ $ sudo wget http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo
VirtualBoxのインストール
$ sudo yum install VirtualBox-4.3 $ chkconfig --list |grep box vboxautostart-service 0:off 1:off 2:on 3:on 4:on 5:on 6:off vboxballoonctrl-service 0:off 1:off 2:on 3:on 4:on 5:on 6:off vboxdrv 0:off 1:off 2:on 3:on 4:on 5:on 6:off vboxweb-service 0:off 1:off 2:on 3:on 4:on 5:on 6:off
○VirtualBoxを実行するユーザーアカウントを、VirtualBoxのグループ(vboxusers)に割り当て
$ sudo usermod -a -G vboxusers manatee
○Vagrant の導入
最新版のURLを以下から確認
$ sudo rpm -Uvh https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2_x86_64.rpm
セットアップして起動
Getting Started - Vagrant Documentation
これ以降、kernel-develとkernelパッケージのバージョンが一致していなかったため、エラーが発生。
エラー解消の試行錯誤のため、不要な操作が含まれている可能性があります。
$ vagrant init hashicorp/precise32 The user that is running Vagrant doesn't have the proper permissions to write a Vagrantfile to the specified location. Please ensure that you call `vagrant init` in a location where the proper permissions are in place to create a Vagrantfile. $ vagrant up A Vagrant environment or target machine is required to run this command. Run `vagrant init` to create a new Vagrant environment. Or, get an ID of a target machine from `vagrant global-status` to run this command on. A final option is to change to a directory with a Vagrantfile and to try again.
(OS再起動)
$ vagrant init hashicorp/precise32 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 up VirtualBox is complaining that the kernel module is not loaded. Please run `VBoxManage --version` or open the VirtualBox GUI to see the error message which should contain instructions on how to fix this error.
⇒エラー発生
$ VBoxManage --version WARNING: The vboxdrv kernel module is not loaded. Either there is no module available for the current kernel (2.6.32-504.el6.x86_64) or it failed to load. Please recompile the kernel module and install it by sudo /etc/init.d/vboxdrv setup You will not be able to start VMs until this problem is fixed. 4.3.28r100309
⇒エラー発生
$ sudo /etc/init.d/vboxdrv setup [sudo] password for manatee: Stopping VirtualBox kernel modules [ OK ] Uninstalling old VirtualBox DKMS kernel modules [ OK ] Trying to register the VirtualBox kernel modules using DKMSError! echo Your kernel headers for kernel 2.6.32-504.el6.x86_64 cannot be found at /lib/modules/2.6.32-504.el6.x86_64/build or /lib/modules/2.6.32-504.el6.x86_64/source. [失敗] (Failed, trying without DKMS) Recompiling VirtualBox kernel modules [失敗] (Look at /var/log/vbox-install.log to find out what went wrong)
⇒エラー発生
$ cat /var/log/vbox-install.log Uninstalling modules from DKMS removing old DKMS module vboxhost version 4.3.28 '------------------------------ Deleting module version: 4.3.28 completely from the DKMS tree. '------------------------------ Done. Attempting to install using DKMS Creating symlink /var/lib/dkms/vboxhost/4.3.28/source -> /usr/src/vboxhost-4.3.28 DKMS: add completed. Failed to install using DKMS, attempting to install without Makefile:183: *** Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again. 中止.
⇒カーネルの環境変数が定義されていない様子なので、exportしてみたが、再度エラーが発生。
$ export KERN_DIR=/usr/src/kernels/2.6.32-504.23.4.el6.x86_64 $ sudo /etc/init.d/vboxdrv setup [sudo] password for manatee: Stopping VirtualBox kernel modules [ OK ] Uninstalling old VirtualBox DKMS kernel modules [ OK ] Trying to register the VirtualBox kernel modules using DKMSError! echo Your kernel headers for kernel 2.6.32-504.el6.x86_64 cannot be found at /lib/modules/2.6.32-504.el6.x86_64/build or /lib/modules/2.6.32-504.el6.x86_64/source. [失敗] (Failed, trying without DKMS) Recompiling VirtualBox kernel modules [失敗] (Look at /var/log/vbox-install.log to find out what went wrong)
⇒再度エラー発生。
$ rpm -qa | grep kernel kernel-headers-2.6.32-504.el6.x86_64 libreport-plugin-kerneloops-2.0.9-21.el6.centos.x86_64 kernel-devel-2.6.32-504.23.4.el6.x86_64 kernel-firmware-2.6.32-504.el6.noarch abrt-addon-kerneloops-2.0.8-26.el6.centos.x86_64 dracut-kernel-004-356.el6.noarch kernel-2.6.32-504.el6.x86_64
⇒kernel-develとkernelパッケージのバージョンの不一致を確認。
vagrantをyumでインストールした際に、依存関係でkernel-develのみ最新になっていたのが原因。
カーネル関連パッケージについて、すべて最新にアップデートした。
$ sudo yum install kernel kernel-firmware kernel-headers
●OS再起動
$ rpm -qa | grep kernel libreport-plugin-kerneloops-2.0.9-21.el6.centos.x86_64 kernel-devel-2.6.32-504.23.4.el6.x86_64 kernel-2.6.32-504.23.4.el6.x86_64 abrt-addon-kerneloops-2.0.8-26.el6.centos.x86_64 kernel-firmware-2.6.32-504.23.4.el6.noarch kernel-headers-2.6.32-504.23.4.el6.x86_64 dracut-kernel-004-356.el6.noarch kernel-2.6.32-504.el6.x86_64 <|| サービスの起動状態を確認。モジュールはロードされている様子。 >|| $ service vboxautostart-service status Usage: /etc/init.d/vboxautostart-service {start|stop} $ service vboxballoonctrl-service status Checking for VBox watchdog service ...not running $ service vboxdrv status VirtualBox kernel modules (vboxdrv, vboxnetflt, vboxnetadp, vboxpci) are loaded. $ service vboxweb-service status Checking for VBox Web Service ...not running $ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Checking if box 'hashicorp/precise32' is up to date... ==> 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: 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.2.0 default: VirtualBox Version: 4.3 ==> default: Mounting shared folders... default: /vagrant => /home/manatee ==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision` ==> default: to force provisioning. Provisioners marked to run always will still run. >||