Vagrant Use under Windows
Download and install virtualbox:https://www.virtualbox.org/
Download and install vagrant:http://www.vagrantup.com/
Download the box you need to use:
Add box
Add a Debian box as follows
E:\ubuntu\vagrant-Box-ngixn-php-fpm-mysql-redis-nodejs>vagrantbox Add Debian package. box==> box:adding box ' Debian ' (v0) for provider: box:Downloading:file://e:/ubuntu/ vagrant-box-ngixn-php-fpm-mysql-redis-nodejs/package. Box box:progress: 100% (Rate: 11.0m/s, estimated time remaining:--:--:--) ==> box:successfully AD ded box ' Debian ' (v0) for ' VirtualBox '!
Vagrantfile
Under any vagrant project there is a vagrantfile, just like the makefile one eye gauge, used to configure the vagrant of the virtual machine information created by the comfort.
Vagrant using Add image
add abc boxpath[url|path] #abc未名称
Development to the development directory
Vagrant init ABC #初始化
D:\work\test>vagrant Init Debian
A has been placed in the this Vagrantfile
directory. You is 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.
Vagrant up #启动
D:\work\test>vagrant up
Bringing machine ' default ' up with ' VirtualBox ' provider ...
==> default:importing base box ' Debian ' ...
==> default:matching MAC address for NAT networking ...
==> default:setting The name of the vm:test_default_1413449093680_48484
==> default:clearing Any previously set network interfaces ...
==> default:preparing Network interfaces based on configuration ...
Default:adapter 1:nat
==> default:forwarding Ports ...
default:22 = 2222 (Adapter 1)
==> default:booting VM ...
==> default:waiting to boot. This could take a few minutes ...
Default:ssh address:127.0.0.1:2222
Default:ssh username:vagrant
DEFAULT:SSH Auth method:private Key
Default:Warning:Connection timeout. Retrying ...
Default:Warning:Connection timeout. Retrying ...
==> Default:machine booted and ready!
==> default:checking for guest additions in VM ...
==> default:mounting Shared Folders ...
Default:/vagrant = D:/work/test
Vagrant SSH #ssh登录
D:\work\test>vagrant SSH
ssh
Executable not found in any directories in the%PATH% variable. is an
SSH client installed? Try installing Cygwin, MinGW or Git, all of which
Contain an SSH client. Or Use your favorite SSH client with the following
Authentication information shown below:
host:127.0.0.1
port:2222
Username:vagrant
Private Key:c:/users/zhangwei_f/.vagrant.d/insecure_private_key
Log on using Xshell after SSH is turned on
Network configuration
Vagrant's network has three modes
1, more commonly used is port mapping, is to map the port in the virtual machine to host the corresponding port to use directly, in the Vagrantfile configuration:
config.vm.network :forwarded_port, guest: 80, host: 8080guest: 80 表示虚拟机中的80端口, host: 8080 表示映射到宿主机的8080端口。 开启这个后,如果vagrant已经启动了,在命令行输入 vagrant reload 重启机器,就可以再宿主机伤使用 localhost:8080来访问虚拟机的localhost:80 。
2, if you need free access to the virtual machine, but others do not need to access the virtual machine, you can use Private_network, and set the IP for the virtual machine, in the Vagrantfile configuration:
config.vm.network :private_network, ip: "192.168.1.104"192.168.1.104 表示虚拟机的IP,多台虚拟机的话需要互相访问的话,设置在相同网段即可
3, if you need to use the virtual machine as a computer in the current LAN, the local area network for DHCP, then configure in Vagrantfile:
config.vm.network :public_network
Directory Mapping:
Since it is the development environment, then the development work must still be done locally, not all into the virtual machine to complete, the virtual machine is good in the background to run the service, or the cart before the horse, so here you need to use the directory mapping function, the local directory mapping to the corresponding directory of the virtual machine.
By default, the current working directory is mapped to the/vagrant directory of the virtual machine, the files under the current directory can be accessed directly under/vagrant, and, of course, you can create a soft connection through LN, such as
/vagrant/wwwroot /var/www
To do directory mapping, of course, from the point of view of automation configuration, can not enter the system without the need to enter the system, so the vagrant can also do directory mapping operations:
config.vm.synced_folder "wwwroot/", "/var/www"
The preceding parameter "wwwroot/" represents the local path, where the relative path to the working directory is used, and the absolute path can be used here, for example: "d:/www/"
The following parameter "/var/www" represents the directory in the virtual machine corresponding to the mapping.
Some commands
up (启动虚拟机)vagrant halt (关闭虚拟机——对应就是关机)vagrant suspend (暂停虚拟机——只是暂停,虚拟机内存等信息将以状态文件的方式保存在本地,可以执行恢复操作后继续使用)vagrant resume (恢复虚拟机 —— 与前面的暂停相对应)vagrant destroy (删除虚拟机,删除后在当前虚拟机所做进行的除开Vagrantfile中的配置都不会保留) vagrant reload (重启)
Vagrant Use under Windows