Recently vagrant more popular, its main role is simply to pack a already installed system, packaged system in each platform general. Especially for a more complex development environment, a new computer, a new job, must be in the rebuild environment, this kind of thing is still relatively time-consuming, such as the use of PHP development of the lamp environment (I usually loaded lanmp–apache+nginx+mysql+php), There are REDIS,MONGODB,RABBITMQ these extensions, although they have a complete document, but many years to get down into a physical job. So vagrant to my advantage simply do not say and pleasure. You can have a packaged system for you, you can and I have quite a development environment. Save time and improve efficiency
Don't say much nonsense, then start using this vagrant
What about installing the software? Aluminum play Agrant+virtualbox), close your eyes and next.
Download a box image (directly find a mirrored download on the line)
After the two steps are complete, let's add a box called lamp.
Add a virtual machine called lamp (MAC OS x Environment)
Php
Vagrant Box Remove Lamp
mkdir lamp
CD lamp
Vagrant box Add lamp ~/dev/ubuntu-14.04-amd64.box
Vagrant Init
1
2
3
4
5
6
Vagrant Box Remove Lamp
mkdir lamp
CD lamp
Vagrant box Add lamp ~/dev/ubuntu-14.04-amd64.box
Vagrant Init
VI vagrantfile Edit the configuration file, add the following content, in the initialization will be used
Here to introduce the network configuration, the general situation of stand-alone development with a private network, only their own access to this IP, but this IP can also be linked to the Internet, to meet the needs of most of our people
Php
Config.vm.box = "lamp"
Config.vm.hostname = "lamp"
Config.vm.network "Private_network", IP: "192.168.8.10"
1
2
3
4
Config.vm.box = "lamp"
Config.vm.hostname = "lamp"
Config.vm.network "Private_network", IP: "192.168.8.10"
Vagrant SSH
Vagrant Package Lamp–output D:/vagrant/lamp.box
——————————— – Split line below are some commands ————————————
Php
Vagrant box Add lamp ~/dev/ubuntu-14.04-amd64.box #添加虚拟机 lamp
Vagrant Box List #列出所有虚拟机
Vagrant box Remove "web" #删除虚拟机web
Vagrant Init # Initialization
Vagrant Up # Start virtual machine
Vagrant Halt # Shut down the virtual machine
Vagrant Reload # Restart virtual machine
Vagrant SSH # SSH to virtual machine
Vagrant Status # View virtual machine running status
Vagrant Destroy # Destroy the current virtual machine
Note: If you use Private_network in network mode, you need to clear the Private_network settings before you pack and avoid unnecessary errors:
[CentOS]
sudo rm-f/etc/udev/rule.d/70-persistent-net.rules
[Ubuntu]
sudo vim/etc/interface
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Vagrant box Add lamp ~/dev/ubuntu-14.04-amd64.box #添加虚拟机 lamp
Vagrant Box List #列出所有虚拟机
Vagrant box Remove "web" #删除虚拟机web
Vagrant Init # Initialization
Vagrant Up # Start virtual machine
Vagrant Halt # Shut down the virtual machine
Vagrant Reload # Restart virtual machine
Vagrant SSH # SSH to virtual machine
Vagrant Status # View virtual machine running status
Vagrant Destroy # Destroy the current virtual machine
Note: If you use Private_network in network mode, you need to clear the Private_network settings before you pack and avoid unnecessary errors:
[CentOS]
sudo rm-f/etc/udev/rule.d/70-persistent-net.rules
[Ubuntu]
sudo vim/etc/interface
——————————— – Below the split line is the actual operation under Windows ————————————
Php
PS d:\vagrant> ls
Table of Contents: D:\vagrant
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a----2016/3/8 17:08 p.php
-a----2016/3/9 13:10 436951040 Trusty-server-cloudimg-amd64-vagrant-disk1.box
-a----2016/3/9 21:15 1220018733 Ubuntu-14.04-amd64.box
-a----2016/3/10 8:52 3180 vagrantfile
PS d:\vagrant> vagrant Box Add lamp D:\vagrant\ubuntu-14.04-amd64.box
==> Box:box file is not detected as metadata. Adding it directly ...
==> box:adding box ' lamp ' (V0) for provider:
box:unpacking Necessary Files From:file://d:/vagrant/ubuntu-14.04-amd64.box
box:progress:100% (rate:42.3m/s, Estimated time remaining:--:--:--)
==> box:successfully added box ' lamp ' (v0) for ' VirtualBox '!
PS d:\vagrant> vagrant Box List
Lamp (VirtualBox, 0)
PS d:\vagrant> vagrant Init lamp
A ' Vagrantfile ' has been placed in this directory. are now
Ready to ' vagrant up ' your A-environment! Please read
The comments in the Vagrantfile as-documentation on
' Vagrantup.com ' for the more information on using vagrant.
######################## #在此处有编辑配置文件的操作 #############################
PS d:\vagrant> vagrant Up
Bringing machine ' default ' up with ' VirtualBox ' provider ...
==> default:importing base box ' lamp ' ...
==> default:matching MAC address for NAT networking ...
==> default:setting The name of the vm:vagrant_default_1457571466457_85328
==> default:fixed Port collision for => 2222. Now on port 2200.
==> default:clearing Any previously set network interfaces ...
==> default:preparing Network interfaces based on configuration ...
Default:adapter 1:nat
Default:adapter 2:hostonly
Default:adapter 3:hostonly
==> default:forwarding Ports ...
Default:22 (Guest) => 2200 (host) (Adapter 1)
==> default:booting VM ...
==> default:waiting for machine to boot. This may take a few minutes ...
Default:ssh address:127.0.0.1:2200
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 does not match the installed version of
default:virtualbox! In most cases this are fine, but in rare cases it can
Default:prevent things such as shared folders from working properly. If You
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.3.36
Default:virtualbox version:5.0
==> default:setting hostname ...
==> default:configuring and enabling network interfaces ...
==> default:mounting Shared Folders ...
Default:/vagrant => d:/vagrant
PS d:\vagrant>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21st
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
PS d:\vagrant> ls
Table of Contents: D:\vagrant
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a----2016/3/8 17:08 p.php
-a----2016/3/9 13:10 436951040 Trusty-server-cloudimg-amd64-vagrant-disk1.box
-a----2016/3/9 21:15 1220018733 Ubuntu-14.04-amd64.box
-a----2016/3/10 8:52 3180 vagrantfile
PS d:\vagrant> vagrant Box Add lamp D:\vagrant\ubuntu-14.04-amd64.box
==> Box:box file is not detected as metadata. Adding it directly ...
==> box:adding box ' lamp ' (V0) for provider:
box:unpacking Necessary Files From:file://d:/vagrant/ubuntu-14.04-amd64.box
box:progress:100% (rate:42.3m/s, Estimated time remaining:--:--:--)
==> box:successfully added box ' lamp ' (v0) for ' VirtualBox '!
PS d:\vagrant> vagrant Box List
Lamp (VirtualBox, 0)
PS d:\vagrant> vagrant Init lamp
A ' Vagrantfile ' has been placed in this directory. are now
Ready to ' vagrant up ' your A-environment! Please read
The comments in the Vagrantfile as-documentation on
' Vagrantup.com ' for the more information on using vagrant.
######################## #在此处有编辑配置文件的操作 #############################
PS d:\vagrant> vagrant Up
Bringing machine ' default ' up with ' VirtualBox ' provider ...
==> default:importing base box ' lamp ' ...
==> default:matching MAC address for NAT networking ...
==> default:setting The name of the vm:vagrant_default_1457571466457_85328
==> default:fixed Port collision for => 2222. Now on port 2200.
==> default:clearing Any previously set network interfaces ...
==> default:preparing Network interfaces based on configuration ...
Default:adapter 1:nat
Default:adapter 2:hostonly
Default:adapter 3:hostonly
==> default:forwarding Ports ...
Default:22 (Guest) => 2200 (host) (Adapter 1)
==> default:booting VM ...
==> default:waiting for machine to boot. This may take a few minutes ...
Default:ssh address:127.0.0.1:2200
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 does not match the installed version of
default:virtualbox! In most cases this are fine, but in rare cases it can
Default:prevent things such as shared folders from working properly. If You
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.3.36
Default:virtualbox version:5.0
==> default:setting hostname ...
==> default:configuring and enabling network interfaces ...
==> default:mounting Shared Folders ...
Default:/vagrant => d:/vagrant
PS d:\vagrant>
Use Xshell to connect vagrant