導(dǎo)讀:雖然這里http://www.vagrantbox.es/已經(jīng)羅列出了許多個(gè)base box,但有些時(shí)候,可能根據(jù)自身的業(yè)務(wù)需要一些特殊的box,比如,筆者遇到的,需要一個(gè)帶桌面環(huán)境和瀏覽器測試用的box,這個(gè)在網(wǎng)上可沒有找到,無奈之下,只能自己裝虛擬機(jī),做一個(gè)base box出來,以便使用。本文主要針對(duì)ubuntu的base box的制作。本文出自cclo的blog,轉(zhuǎn)載時(shí)請(qǐng)務(wù)必以超鏈接形式標(biāo)明文章原始出處:http://xuclv.blog.51cto.com/5503169/1239351
步驟如下:(環(huán)境 OS:ubuntu12.04_Desktop virtualbox:4.1.12)
1.在物理機(jī)安裝好ubuntu系統(tǒng),在此系統(tǒng)上安裝virtualbox
2.下載一個(gè)需要的ubuntu版本的iso鏡像
3.創(chuàng)建一個(gè)新的虛擬機(jī)
給虛擬機(jī)起個(gè)名字為"vagrant-precise32"
確保您分配足夠的磁盤空間,40GB足夠了。
確保默認(rèn)的內(nèi)存分配也不用太高,建議360M。
如果不需要,禁用音頻,USB控制器等。大多數(shù)應(yīng)用程序都不需要播放音樂!因此,節(jié)約資源,禁用這些功能。
確保網(wǎng)絡(luò)控制器設(shè)置為NAT,為了端口轉(zhuǎn)發(fā)正常工作。
4.啟動(dòng)虛擬機(jī),安裝ubuntu,確保配置如下(非強(qiáng)制,如打算分發(fā)此box,建議遵循如下約定)
Hostname:vagrant-[os-name],例:vagrant-ubuntu-Steve
Domain: vagrantup.com
Root Password: vagrant
Main account login: vagrant
Main account password: vagrant
5.安裝完畢后,進(jìn)入虛擬機(jī)
6.根據(jù)自己需要,安裝一些常用軟件
sudo apt-get -y install vim
7.創(chuàng)建admin組
sudo groupadd admin
8.添加vagrant用戶到admin組
sudo usermod -G admin vagrant
9.修改sudoers文件
sudo vim /etc/sudoers #添加或修改如下行(有些發(fā)行版還需Disable requiretty):
Defaults env_keep="SSH_AUTH_SOCK"
%admin ALL=NOPASSWD: ALL
10.安裝puppet(chef沒有計(jì)劃裝進(jìn)去,如需要可安裝ruby,rubygems,chef)
sudo apt-get install puppet puppetmaster
11.安裝ssh
sudo apt-get install openssh-server
12.安裝vagrant的public keys
mkdir ~/.ssh/
cd ~/.ssh
wget http://github.com/mitchellh/vagrant/raw/master/keys/vagrant
wget http://github.com/mitchellh/vagrant/raw/master/keys/vagrant.pub
mv vagrant.pub authorized_keys
13.Install virtual box guest additions(為了共享文件夾,端口轉(zhuǎn)發(fā)等)
(1) First, build the necessary packages. You may have to look these up for your system, but they should be fairly similar. On Ubuntu and Debian based systems they are as follows:
$ sudo apt-get install linux-headers-$(uname -r) build-essential
(2) Next, make sure to insert the guest additions image by using the GUI and clicking on “Devices” followed by “Install Guest Additions.”. Then run the following to mount the CD Rom:
$ sudo mount /dev/cdrom /media/cdrom
(3) And finally, run the shell script which matches your system. For linux on x86, it is the following:
$ sudo sh /media/cdrom/VBoxLinuxAdditions.run
If you didn’t install a Desktop environment when you installed the operating system, as recommended to reduce size, the install of the VirtualBox additions should warn you about the lack of OpenGL or Window System Drivers, but you can safely ignore this.
14.清除緩存
sudo apt-get clean
15.關(guān)閉虛擬機(jī),進(jìn)入virtual box directory(~/VirtualBox VM/vagrant-precise32)
vagrant package --output ubuntu_32.box --base vagrant-precise32
總結(jié):以上步驟完成后生成的ubuntu_32.box就可以拿來用了,用vagrant box add ,vagrant init等自己測試看看吧,不會(huì)用vagrant?請(qǐng)看這里http://xuclv.blog.51cto.com/5503169/1239250
本文出自 “cclo的博客” 博客,請(qǐng)務(wù)必保留此出處http://xuclv.blog.51cto.com/5503169/1239351
聯(lián)系客服