"Go" vagrant use under Windows

Source: Internet
Author: User
Tags virtual environment

Original link Address: http://www.cnblogs.com/ac1985482/p/4029315.html

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
  1. 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.comFor more information on using Vagrant.

  2. 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

  3. Vagrant SSH #ssh登录

    D:\work\test>vagrant SSH
    sshExecutable 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 represents the 80 port in the virtual machine, and host:8080 represents the 8080 port that is mapped to the host.        after this, if the vagrant has been started, the command line input vagrant Reload Restart the machine, you can then host the injury using localhost:8080 to access the virtual machine 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:p rivate_network, IP: "192.168.1.104" 192.168.1.104 represents the IP of the virtual machine, multiple virtual machines need to visit each other, set in the same network segment can be

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:p Ublic_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

Ln-fs/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
Vagrant  Package--base   VM virtual machine name  --output   test.box (Packaging command) vagrant box  add   directory name  Test.box ( Add virtual machine) Vagrant init  Test (Initialize virtual machine) vagrant up (Start virtual machine) Vagrant Halt (Shutdown virtual machine-corresponds to shutdown) Vagrant Suspend (pause virtual machine-just pause, Information such as virtual machine memory is saved locally as a state file, and can continue to be used after a recovery operation Vagrant Resume (restores the virtual machine-corresponds to the previous pause) vagrant destroy (Remove the virtual machine, The configuration in the vagrantfile that was made after the deletion is not retained in the current virtual machine)    vagrant reload  (restart)

"Go" vagrant use under Windows

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.