CentOS6 配置 vagrant + VirtualBox

安装vagrant1.7.2

wget https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2_x86_64.rpm
rpm -ivh vagrant_1.7.2_x86_64.rpm

安装VirtualBox 4.2

# curl http://download.virtualbox.org/virtualbox/rpm/el/virtualbox.repo >/etc/yum.repos.d/virtualbox.repo
yum -y install gcc make dkms libGL libXmu libXt SDL SDL-devel SDL-static kernel-devel libpng libXcursor libXinerama fontconfig-devel freetype-devel VirtualBox-4.2

安装VitrualBox中的重要提示信息

reating group 'vboxusers'. VM users must be member of that group!

启用dbus

chkconfig messagebus on

如果执行VirtualBox报如下错误

No precompiled module for this kernel found -- trying to build one. Messages
emitted during module compilation will be logged to /var/log/vbox-install.log.

查看日志可发现

Makefile:185: *** Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again. Stop.

然后执行

# KERN_DIR=/usr/src/kernels/2.6.32-504.23.4.el6.x86_64 /etc/init.d/vboxdrv setup

运行过程中输出如下

Stopping VirtualBox kernel modules [ OK ]
Uninstalling old VirtualBox DKMS kernel modules [ OK ]
Trying to register the VirtualBox kernel modules using DKMS [ OK ]
Starting VirtualBox kernel modules [ OK ]

然后重启系统

VBoxManage list vms
VBoxManage list runningvms

vagrant安装爬 墙 插件

https_proxy=https://yourporxy:3128 http_proxy=http://yourporxy:3128 vagrant plugin install vagrant-proxyconf

vi Vagrantfile

config.proxy.http = "http://yourporxy:3128"
config.proxy.https = "https://yourporxy:3128"
config.proxy.no_proxy = "localhost,127.0.0.1"

vagrant的box文件可以通过迅雷加速下载到本地硬盘,然后通过命令导入,可节省大量时间

vagrant box add --name "centos-6.5-i386-vbox" centos-65-i386-vbox.box