1
| box,destroy,global-status,halt,init,package,resume, ssh ,status,suspend,up |
1
| vagrant box add centos6 E:\vagrant\box\centos65.box |
1
2
3
4
| vagrant box add hashicorp /precise64 或者 vagrant box add https: //github .com /2creatives/vagrant-centos/releases/download/v6 .4.2 /centos64-x86_64-20140116 .box |
1
| vagrant init |
1
| vagrant init centos6 |
1
2
3
| Vagrant.configure(2) do |config| config.vm.box = "centos6" end |
1
| vagrant up |
1
| vagrant ssh |
1
| vagrant halt |
1
| vagrant suspend |
1
| vagrant resume |
1
| vagrant destroy |
1
| vagrant status |
1
| vagrant global-status |
1
2
3
4
5
6
7
8
| app_servers = { :app1 => [ '192.168.13.2' , '192.168.15.3' ], :app2 => [ '192.168.13.3' , '192.168.15.4' ] } db_servers = { :db1 => [ '192.168.14.2' , '192.168.15.5' ], :db2 => [ '192.168.14.3' , '192.168.15.6' ] } lb_servers = { :lb1 => '192.168.15.2' } |
1
2
3
4
5
6
7
| app_servers.each do |app_server_name,app_server_ip| config.vm.define app_server_name do |app_config| app_config.vm.host_name = app_server_name.to_s app_config.vm.network :private_network,ip: app_server_ip[0] app_config.vm.network :private_network,ip: app_server_ip[1],virtualbox_inet: true end end |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
| Vagrant.configure(2) do |config| config.vm.box = "centos6" end app_servers = { :app1 => [ '192.168.13.2' , '192.168.15.3' ], :app2 => [ '192.168.13.3' , '192.168.15.4' ] } db_servers = { :db1 => [ '192.168.14.2' , '192.168.15.5' ], :db2 => [ '192.168.14.3' , '192.168.15.6' ] } lb_servers = { :lb1 => '192.168.15.2' } app_servers.each do |app_server_name,app_server_ip| config.vm.define app_server_name do |app_config| app_config.vm.host_name = app_server_name.to_s app_config.vm.network :private_network,ip: app_server_ip[0] app_config.vm.network :private_network,ip: app_server_ip[1],virtualbox_inet: true end end db_servers.each do |db_server_name,db_server_ip| config.vm.define db_server_name do |app_config| app_config.vm.host_name = db_server_name.to_s app_config.vm.network :private_network,ip: db_server_ip[0] app_config.vm.network :private_network,ip: db_server_ip[1],virtualbox_inet: true end end lb_servers.each do |lb_server_name,lb_server_ip| config.vm.define lb_server_name do |app_config| app_config.vm.host_name = lb_server_name.to_s app_config.vm.network :private_network,ip: lb_server_ip end end end |
使用的软件:
1. CentOS: CentOS release 6.4 (Final)
2. Vagrant: vagrant_1.2.2_i686.rpm
3. Virtualbox: VirtualBox-4.2-4.2.14_86644_el6-1.i686.rpm
一、安装Vagrant:
#yum -y install vagrant_1.2.2_i686.rpm
二、安装VirtualBox:
#yum -y install VirtualBox-4.2-4.2.14_86644_el6-1.i686.rpm
三、安装Linux头包(linux-header package):
#yum install kernel-devel
四、设置环境变量
#export KERN_DIR=/usr/src/kernels/2.6.32-358.11.1.el6.i686/
#export KERN_INCL=/usr/src/kernels/2.6.32-358.11.1.el6.i686/include/
五、Build
#/etc/init.d/vboxdrv setup
六、创建Vagrant工作区,开始使用Vagrant
#cd ~
#mkdir vagrant_workspace
#cd vagrant_workspace
#vagrant init precise32 http://files.vagrantup.com/precise32.box
#vagrant up
注:第七步骤仅当vagrant up出现import bug时才需要。
七、修复VirtualBox import bug(NS_ERROR_CALL_FAILED)
#cd ~/.vagrant.d/boxes/BaseBoxName/virtualbox
#openssl sha1 *.vmdk *.ovf > box.mf
#cd ~/vagrant_workspace
#vagrant up
注:文中BaseBoxName为precise32
链接: