---
title: CentOSにVagrantをインストール
tags: []
categories: ["Dev", "Infrastructure", "Vagrant"]
date: 2014-02-23T01:40:07Z
updated: 2014-02-23T01:40:07Z
---

環境

    $ uname -r
    2.6.32-431.5.1.el6.x86_64

## VirtualBoxインストール

    $ wget http://download.virtualbox.org/virtualbox/rpm/el/virtualbox.repo
    $ sudo cp virtualbox.repo /etc/yum.repos.d/
    $ sudo yum install VirtualBox-4.3

`kernel-devel`も必要っぽい

    $ sudo yum install kernel-devel

カーネルのバージョンが合っていないといけない
$ rpm -qa | grep kernel-devel
kernel-devel-2.6.32-431.5.1.el6.x86_64

## Vagrantインストール

    $ wget https://dl.bintray.com/mitchellh/vagrant/vagrant_1.4.3_x86_64.rpm -O vagrant_1.4.3_x86_64.rpm
    $ sudo rpm -ivh vagrant_1.4.3_x86_64.rpm

カーネルモジュールのビルドおよび組み込み

    $ sudo /etc/init.d/vboxdrv setup
    Stopping VirtualBox kernel modules                         [  OK  ]
    Recompiling VirtualBox kernel modules                      [  OK  ]
    Starting VirtualBox kernel modules                         [  OK  ]

VM作成

    $ vagrant init centos-65-x64 http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-puppet.box
    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.

`Vagrantfile`の以下をコメントを外してメモリサイズを変更。

      config.vm.provider :virtualbox do |vb|
      #   # Don't boot with headless mode
      #   vb.gui = true
      #
      #   # Use VBoxManage to customize the VM. For example to change memory:
        vb.customize ["modifyvm", :id, "--memory", "2048"]
      end

起動

    $ vagrant up
    Bringing machine 'default' up with 'virtualbox' provider...
    [default] Box 'centos-65-x64' was not found. Fetching box from specified URL for
    the provider 'virtualbox'. Note that if the URL does not have
    a box for this provider, you should interrupt Vagrant now and add
    the box yourself. Otherwise Vagrant will attempt to download the
    full box prior to discovering this error.
    Downloading box from URL: http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-puppet.box
    Extracting box...te: 9628k/s, Estimated time remaining: --:--:--)
    Successfully added box 'centos-65-x64' with provider 'virtualbox'!
    [default] Importing base box 'centos-65-x64'...
    [default] Matching MAC address for NAT networking...
    [default] Setting the name of the VM...
    [default] Clearing any previously set forwarded ports...
    [default] Clearing any previously set network interfaces...
    [default] Preparing network interfaces based on configuration...
    [default] Forwarding ports...
    [default] -- 22 => 2222 (adapter 1)
    [default] Running 'pre-boot' VM customizations...
    [default] Booting VM...
    [default] Waiting for machine to boot. This may take a few minutes...
    [default] Machine booted and ready!
    [default] Mounting shared folders...
    [default] -- /vagrant

SSH接続

    $ vagrant ssh
    Last login: Thu Jan 16 09:37:38 2014 from 10.0.2.2
    Welcome to your Packer-built virtual machine.

とりあえずできた。
