Linux Vagrant+virtualbox Environment Setup Steps

Source: Internet
Author: User
Tags mirror website

Linux Vagrant+virtualbox Environment Setup Steps

Vagrant is a tool for building a virtual development environment that is ideal for developing Web applications in languages such as Php/python/ruby/java.

We can package a Linux development environment through Vagrant and distribute it to team members. Members can develop programs on their favorite desktop system (Mac/windows/linux), but the code can be unified in a packaged environment to run, very domineering.

1. Installing VirtualBox

Virtual machines still have to rely on VirtualBox to build, free small. Although Vagrant also supports VMware, VMware is charged, and the corresponding Vagrant version is also charged.

2. Installing vagrant

Download vagrant, follow the prompts to install the step-by-step;
Installation package acquisition and installation process can refer to "step by step to teach you to install the latest version of Vagrant"

3. Get the base image of the official package

Through Baidu to obtain the mirror website, according to their own needs to download the corresponding image.
Here Select "CentOS 7.0 x64 (Minimal, VirtualBox Guest additions 4.3.28, Puppet 3.8.1-see here for more infos)". Just click "Copy", copy and then through the Thunderbolt download can be;

4. Add image to Vagrant

The image storage path I downloaded is H:/vagrantbox/centos-7.0-x86_64.box,
Create a development directory h:/centos7/, you can also use the existing directory, switch to the development directory, the current working directory to install the shift and then right mouse, select "Open Command Window Here" to enter the current working directory on the command line
Enter in the terminal:
Vagrant Box Add Centos7 h:/vagrantbox/centos-7.0-x86_64.box
Centos7 is the name we give this box, H:/vagrantbox/centos-7.0-x86_64.box is the path of box;

5. Initializing the development environment

Initializes the environment of the current directory with the Centos7 mirror. Enter the current working directory under the command line, and initialize it by executing the following command
Vagrant Init Centos7

6. Modify Settings

After the Vagrant initialization succeeds, a vagrantfile configuration file is generated in the initialized directory, which can be customized by modifying the configuration file.
Vagrant By default is to use port mapping method to map the port of the virtual machine locally to achieve similar http://localhost:80 this way of access, this method is more troublesome, new open and modify the port when you have to edit. In comparison, the host-only mode appears to be much more convenient. Open the Vagrantfile and remove the comment from the line below (remove #) and Save:
Config.vm.network:p rivate_network, IP: "192.168.33.10"
Restart the virtual machine so that we can access the machine with 192.168.33.10, you can change the IP to another address as long as there is no conflict on the line.
There are a lot of configuration changes follow up and then continue to explain;

7. Start and Login

Execute the following command under the command-line working directory to start the virtual machine
Vagrant up
You will see that the terminal shows the start-up process, and after the boot is complete, we can login to the virtual machine with SSH, and the rest of the steps are to configure the various environments and parameters you want to run in the virtual machine.
SSH login can also be connected using the Client Connection tool
Vagrant SSH
Switch to the development directory
Cd/vagrant is the ' h:/centos7/' on the host
The h:/centos7/directory corresponds to the directory in the virtual machine/vagrant

8. Packaging and distribution

When you have configured your development environment, exit and shut down the virtual machine. To package the development environment in the terminal:
Vagrant Package
When the package is complete, a Package.box file is generated in the current directory, and the file is passed on to other users, and other users simply add the box and initialize their development directory to get an identical development environment.

9. Common commands

Vagrant Init # Initialization
Vagrant up # To start a 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 health status
Vagrant Destroy # Destroys the current virtual machine

Vagrant up Config.vm.boot_timeout problem:

Timed out while waiting for the machine to boot. This means
Vagrant was unable to communicate and the guest machine within
The configured ("Config.vm.boot_timeout" value) time period.

If You look above, should is able to see the error (s) that
Vagrant had when attempting to connect to the machine. These errors
is usually good hints as to who may wrong.

If you ' re using a custom box, make sure this networking is properly
Working and you ' re able to connect to the machine. It is a common
Problem that networking isn ' t setup properly in these boxes.
Verify that authentication configurations is also setup properly,
as well.

If The box appears to is booting properly, you could want to increase
The timeout ("Config.vm.boot_timeout") value.

Solution:

In the Vagrantfile file, add:

  Config.ssh.username   = "vagrant"  config.ssh.password   = "vagrant"  Config.ssh.insert_key = "true"

Linux Vagrant+virtualbox Environment Setup Steps

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.