Build a development environment using Vagrant

Source: Internet
Author: User

Build a development environment using Vagrant

To do Web development, you must build a development environment locally. Although various scripts currently have corresponding Windows versions, or even one-click installation packages, however, in many cases, the consistency with the Windows environment is not so good. The problem is that the actual deployment environment is usually Linux, and the development and deployment environments are often different, A lot of debugging is required before going online. Even worse, if many machines need to be installed, it would be a disaster.

Virtual machines are indispensable for playing Linux in Windows, but installing the system is still quite troublesome. In today's automated world, Vagrant is such an artifact. Based on Ruby development, it uses open-source VirtualBox as virtualization support and can be easily deployed across platforms.

Today, I tried to replace the environment of several machines with Vagrant, which was very smooth, so I tried to sort out the usage summary:

How to Use vagrant to install a Hadoop cluster on a virtual machine

Efficient Puppet module Management in Vagrant

Use Vagrant and Fabric for Integration Testing

Build a development environment using Vagrant

Configure the Vagrant environment in Windows

Currently, the latest version Vagrant 1.2.7 (Vagrantfile V2) is selected, and VirtualBox uses 4.2.16.

Preparations:

Download installation VirtualBox: https://www.virtualbox.org/

Download installation Vagrant: http://www.vagrantup.com/

Download the required box:

An official example: http://files.vagrantup.com/precise32.box

You can also download more different systems in the http://www.vagrantbox.es/here, or even the box that can be directly used in the configured environment, although you can directly use the web site in Vagrant, Vagrant automatically download and install, however, considering the network conditions, we recommend that you download it first.

As I used to use CentOS, I went to CentOS 6.3 x86_64 minimal. This Box can be selected based on my personal situation.

Set the environment:

After the installation is complete and the system is restarted, you can set up the environment.

First, create a working directory locally and switch to the corresponding directory under the command line.

Vagrant box add base CentOS-6.3-x86_64-minimal.box

Base indicates specifying the default box, or you can specify a name for the box, such as centos63. When using base, you can directly use vagrant init for initialization. If you specify a name, the box name must be specified during initialization.

The CentOS-6.3-x86_64-minimal.box is the file name corresponding to the box, here can be the local save box path, you can also download the box URL, if it is the URL, Vagrant will automatically start the download.


[Vagrant] Downloading with Vagrant: Downloaders: File...
[Vagrant] Copying box to temporary location...
[Vagrant] Extracting box...
[Vagrant] Verifying box...
[Vagrant] Cleaning up downloaded box...

After setting the box, run it in the current working directory.

Vagrant init

Generate the corresponding Vagrantfile. Open Vagrantfile in a text editor and perform some common configurations:

Network Configuration:

Vagrant has three network modes.

1. Port ing is usually used to map the ports in the virtual machine to the corresponding ports of the host machine for direct use. In Vagrantfile, configure:

Config. vm. network: forwarded_port, guest: 80, host: 8080

Guest: 80 indicates port 80 in the VM, and host: 8080 indicates port 8080 mapped to the host.

2. If you need to freely access the virtual machine, but others do not need to access the virtual machine, you can use private_network, set the IP address for the virtual machine, and configure in Vagrantfile:

Config. vm. network: private_network, ip: "192.168.1.104"

192.168.1.104 indicates the IP address of the Virtual Machine. If multiple virtual machines need to access each other, set it to the same network segment.

3. If you need to use a virtual machine as a computer in the current LAN for DHCP, configure it in Vagrantfile:

Config. vm. network: public_network

Directory ing:

Since it is a development environment, the development work must be done locally, instead of all going into the virtual machine to complete, and the virtual machine should be able to run the service properly in the background, otherwise it will put the cart before the horse upside down, therefore, you need to use the directory ing function to map the local directory to the corresponding directory of the virtual machine.

By default, the current working directory is mapped to the/vagrant directory of the Virtual Machine. Files in the current directory can be directly accessed under/vagrant, you can also create a soft connection through ln, as shown in figure

Ln-fs/vagrant/wwwroot/var/www

The preceding parameter "wwwroot/" indicates the local path. Here the relative path of the working directory is used, and the absolute path can also be used, for example, "d:/www /"

The following parameter "/var/www" indicates the mapped directory in the VM.

For more details, please continue to read the highlights on the next page:

  • 1
  • 2
  • Next Page

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.