Vagrant Box configures the local development environment and common error solutions

Source: Internet
Author: User
Tags what interface

Here is a reference link (http://jingyan.baidu.com/article/642c9d34e15cdd644b46f74b.html), of course, you can follow the following steps: A: Prepare a variety of materials

(1) VirtualBox (https://www.virtualbox.org/)
(2) Vagrant (https://www.vagrantup.com/downloads.html)
(3) Vagrant box (http://www.vagrantbox.es/This is a virtualbox provided box, of course you can use the development team to configure the box) two: Start installation

(1) Install VirtualBox (you can replace the installation directory, and then directly next to the next step is OK)
(2) Install vagrant (this is best on the default installation bar, because it refers to the directory)
(3) Install the vagrant, and then you can create a folder inside your work disk to install the virtual machine, such as I am: E:\CENTOS6. Then enter the directory in the terminal:

First: Execute the installation command:

(The Add centos6--centos6 here is an alias for the virtual machine box to facilitate later operation.) E:/vagrantbox/centos6.box is the third step in the preparation of the Material vagrant box)

Second: Initializing the development environment

This is the basis of the installation, the following is to modify the configuration file Vagrantfile. The file is modified as follows:

#-*-Mode:ruby-*-# vi:set Ft=ruby: # All vagrant configuration are done below. The "2" in Vagrant.configure # configures the configuration version (we support older styles for # backwards compatibility ).
Please don ' t change it unless your know what # you ' re doing.
  Vagrant.configure ("2") do |config|
  # The most common configuration options are documented and commented below.

  # for a complete reference, please do not have the online documentation at # https://docs.vagrantup.com. # Every Vagrant development environment requires a box.
  Can search for # boxes at Https://atlas.hashicorp.com/search. Config.vm.box = "CENTOS6"//box alias # Disable Automatic box update checking. If You are disable this, then # boxes to be checked for updates the user runs # ' vagrant box outdated '.
  This isn't recommended. # config.vm.box_check_update = False # Create a forwarded port mapping which allows access to a specific port # Withi n the machine from a port on the host MachiNe.
  In the example below, # accessing ' localhost:8080 ' would access port on the guest machine.  Config.vm.network "Forwarded_port", guest:80, host:80/port configuration, in order to access the virtual machine Nginx # Create A private network, which allows
   Host-only access to the machine # using a specific IP. Config.vm.network "Private_network", IP: "192.168.33.10"//IP configuration, configured to access virtual machines (such as SSH, etc.) # Create a public network, which Gen
  Erally matched to bridged network.
  # bridged networks make the machine appear as another physical device on # your network. # config.vm.network "Public_network" # Share a additional folder to the guest VM. The argument is # the ' path on the ' host to the actual folder. The second argument is # the "path on" the guest to mount the folder.
   and the optional third # argument is a set of non-required options. Config.vm.synced_folder "D:/workplace/code", "/home/www/"//Front path (D:/workplace/code) is the address of the native code, The following address is the directory of the virtual machine's Nginx deployment # provider-specific configuration so can finE-tune various # backing providers for vagrant.
  These expose provider-specific options.
  # Example for VirtualBox: # config.vm.provider ' VirtualBox ' do |vb| # Display The VirtualBox GUI when booting the machine # Vb.gui = true # # Customize The amount of memory O n the VM: # vb.memory = "1024" # end # View The documentation for the provider your are using for more # info

  Rmation on available options. # Define A vagrant Push strategy for pushing to Atlas. Other push strategies # such as FTP and Heroku are also available.
  The documentation at # https://docs.vagrantup.com/v2/push/atlas.html for more information.
  # config.push.define "Atlas" do |push| # Push.app = "Your_atlas_username/your_application_name" # end # Enable provisioning with a shell script. Additional provisioners such as # Puppet, Chef, Ansible, Salt, and Docker are also. Please, the # documentation for more information about their specific syntaxand use. # config.vm.provision "Shell", inline: <<-shell # apt-get Update # apt-get INSTALL-Y # Shell End

Third: Start the virtual machine
Or in the current directory, enter the vagrant up command, start the virtual machine

IV: SSH link virtual machine

Enter the Nginx profile directory:

The following is according to their own needs to add their own profile, of course, remember to configure their own virtual machine Hosts file (if the domain name is not accessible)

As a whole, here are some vagrant common commands:
(1) Vagrant Init # Initialization
(2) Vagrant up # Start virtual machine
(3) Vagrant Halt # Shut down the virtual machine
(4) Vagrant Reload # restart virtual machine
(5) Vagrant SSH # SSH to virtual machine
(6) Vagrant Status # View virtual machine running status
(7) Vagrant Destroy # Destroy the current virtual machine Three: some common mistakes

(1) Vagrant up times the following error:

Angel:vagrant $ vagrant up bringing machine ' default ' up with ' VirtualBox ' provider ... [Default]

Clearing any previously set forwarded ports ... [Default]

Creating Shared Folders Metadata ... [Default]

Clearing any previously set network interfaces ... [Default] Available Bridged network interfaces:1) En0: Ethernet 2 En1:wi-fi (AirPort) 3) bridge100 What interface should the Netwo RK Bridge to?

2 [default] Preparing network interfaces based on configuration ... [Default]

Forwarding ports ...

[Default]--=> 2222 (adapter 1) [default] booting VM ... [Default] Waiting for machine to boot.

This may take a few minutes ... [Default]

Machine booted and ready! [Default]

Configuring and enabling network Interfaces ...

The following SSH command responded with a Non-zero exit status.

Vagrant assumes that this means the command failed! Arpcheck=no/sbin/ifup eth1 2>/dev/null Stdout from of Command:device eth1 does not seem to be present, delaying I

Nitialization. Stderr from The command: 

Solution Although vagrant up to start an error, but vagrant SSH can still log into the virtual machine, after entering the virtual machine, execute the following command

sudo rm-f/etc/udev/rules.d/70-persistent-net.rules

Yes, the problem is that when the persistent network device Udev rules (persistent network device UDEV rules) are set by the original VM and the new VM is created with box, these rules need to be updated. This is in conflict with the instructions in Vagrantfile to set private network for the new VM. It's good to delete it.

It's no problem to start again (vagrant Reload).

(2) Using the Vagrant box add centos6 E:\vagrantboxfile\centos.box command when the following error occurs:

Couldn ' t open the file \vagrantboxfile\centos.box

Solution:
Put the Centos.box file in the directory you want to initialize, directly with the following command, Vagrant Box add centos6 centos.box, do not write the absolute path, so you can install successfully.

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.