Vagrant deployment development environment, not a little bit cool

Source: Internet
Author: User

First talk about the difference between vagrant and Docker.

Vagrant is used to tube virtual machines, and Docker is a pipe container (such as inaccurate, also correct)

Docker startup speed is certainly unparalleled, and vagrant of course not to be very docker than the start speed, vagrant is the tube virtual machine, virtual machine and the difference between the container, we have a different opinion.


Let's introduce vagrant:

Vagrant is a ruby-based tool for creating and deploying virtualized development environments. It uses Oracle's open source VirtualBox Virtualization System to create automated virtual environments using chef---Baidu encyclopedia


First of all, I want to create a batch of virtual machines, based on different images, based on different systems (mainly Linux systems), each host has a number of network cards and assign designated network segment and IP.

If it is VMware, I think most people want to keep clicking the different buttons have completed the above requirements, of course, if the use of Pyvmomi may not require too much manual click (I think the step-by-step repeat click is very anti-human ~)

If it is another cloud platform, of course, with the help of the API, but I want to create a host that can be distributed like Docker, for example, let everyone on the host computer can be simple to create the required environment, and in the private cloud, each person set may be too waste of resources, everyone is public, it is not so clean.

If not in the host unit, based on Docker, the service application to break up, placed in each container, and Docker orchestration tools such as Kubernetes,compose What to create is also good, but here in order to highlight the convenience of vagrant to host units.


Requirements continue to be specific as follows, 2 apps server,2 db server,1 load Balanced lb server


Again before the simple vagrant get started

Vagrant Installation

One: Installation VirtualBox

Download the corresponding installation package

Https://www.virtualbox.org/wiki/Downloads


Two: Install vagrant

Download the corresponding installation package

Https://www.vagrantup.com/downloads.html


Because the platform has a corresponding installation package, so the installation process will not do too much introduction

This article mainly operates on window

VirtualBox 4.2.36

Vagrant 1.8.1

Linux platforms such as CentOS reference http://blog.csdn.net/haibinzhang/article/details/9234753


This should be the case when the installation is complete.

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7C/41/wKioL1bO90WDLcTlAACkzlpBdyI466.png "title=" 1.png " alt= "Wkiol1bo90wdlctlaackzlpbdyi466.png"/>

Then the main use of a few commands, detailed reference, official documents: https://www.vagrantup.com/docs/

This article mainly explains the following several options

Box,destroy,global-status,halt,init,package,resume,ssh,status,suspend,up

The above command is summed up in five main sections

A: Vagrant environment files packaged in a certain format, similar to image files

Box

Two: Virtual machine operation (DESTROY,HALT,INIT,SUSPEND,UP)

Destroy, shutdown, initialize, resume, suspend, boot

Three: Packaging

Package

Four: Connection

Ssh

V: Virtual machine status

Status,global-status


Before creating a virtual machine, of course, you need a mirror, here is the box file with a. box suffix, which can be added locally or online

box:http://www.vagrantbox.es/

Vagrant Box List view current box listing

Add box locally, as follows

Vagrant Box Add CENTOS6 E:\vagrant\box\centos65.box

CENTOS6 is our custom box name, which will be used later and then the box file path

Note: It is recommended to add the working directory with the box file on the same disk, such as C drive, D drive

Add box online, add the box name format for the user/box name, refer to Https://atlas.hashicorp.com/boxes/search, as follows

Vagrant box Add hashicorp/precise64 or Vagrant box add https://github.com/2creatives/vagrant-centos/releases/download/ V6.4.2/centos64-x86_64-20140116.box


View Box list

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7C/42/wKioL1bO91Ljuf01AAASXNc6S4A039.png "title=" 2.png " alt= "Wkiol1bo91ljuf01aaasxnc6s4a039.png"/>


Now we can initialize a virtual machine that we need.

Create a working directory to store related files

Vagrant Init

Creates a vagrantfile file in the current directory that tells Vagrant what virtual machine we want to create

Here we do

Vagrant Init CENTOS6

After removing all comments, the main content is as follows

Vagrant.configure (2) Do |config| Config.vm.box = "CENTOS6" End

The above Config.vm.box = "CENTOS6", mainly indicates which box file is based on.

And then start

Vagrant up

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7C/42/wKioL1bO92CAy-UnAABVQ4sIqNQ094.png "title=" 3.png " alt= "Wkiol1bo92cay-unaabvq4siqnq094.png"/>

Start the process as above.

After launch, we can ssh in directly.

Vagrant SSH

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7C/43/wKiom1bO9yewVX0GAAAwitVvKqE615.png "title=" 4.png " alt= "Wkiom1bo9yewvx0gaaawitvvkqe615.png"/>

The shutdown is

Vagrant Halt

Hang Up

Vagrant Suspend

Recovering from a suspended state

Vagrant Resume

Virtual machine destruction, a little removed from the disk meaning

Vagrant Destroy

Note: The above command must be in the directory where the Vagrantfile file is located

Then, view the virtual machine status

Vagrant Status

View the virtual machine status for the Vagrantfile file in the current directory

Vagrant Global-status

View global virtual machine status

Note: Since virtual machines, of course, can perform snapshots or something, please explore them yourself

Getting Started ends ...


Go to the Chase

Batch Create 2 Apps server,2 db server,1 load Balanced lb server

As you can see, the more important thing is the Vagrantfile file, which tells Vagrant what to do and what to create.

First define the IP and hostname for each virtual machine, as follows

App_servers = {: App1 = [' 192.168.13.2 ', ' 192.168.15.3 '],: app2 = [' 192.168.13.3 ', ' 192.168.15.4 ']} Db_servers = {:d B1 = [' 192.168.14.2 ', ' 192.168.15.5 '],:d b2 = [' 192.168.14.3 ', ' 192.168.15.6 ']}lb_s Ervers = {: LB1 = ' 192.168.15.2 '}

Because it's ruby-based, it's like a list in Python, the dictionary is a little different, but it's not ugly.

App-server defines two host APP1,APP2 and binds the IP addresses of the two NICs

Db-server above

Lb-server is a

And then of course it's a loop, and if there's a note, there's no need to declare app-servers.

App_servers.each do |app_server_name,app_server_ip|    Config.vm.define App_server_name do |app_config| App_config.vm.host_name = app_server_name.to_s app_config.vm.network:p rivate_network,ip:app_server_ip[0] App_confi G.vm.network:p rivate_network,ip:app_server_ip[1],virtualbox_inet:true End End

There are two main points to explain

A: There are a few do, there are a few end

Two: Traverse App-server, with App_servers.each do |app_server_name,app_server_ip|, where APP_SERVER_NAME,APP_SERVER_IP of course is the variable of the time of traversal, Corresponding to app-server inside the app1,[' 192.168.13.2 ', ' 192.168.15.3 ']

Config.vm.define define the host name created

App_config.vm.host_name definition hostname

App_config.vm.network:p rivate_network,ip define NIC binding IP

Complete as follows

Vagrant.configure (2)  do |config|   config.vm.box =  "CENTOS6"   end    app_servers = { :app1 => [' 192.168.13.2 ', ' 192.168.15.3 '],                      :app2 => [' 192.168.13.3 ', ' 192.168.15.4 ']             }   db_servers = { :d b1 => [' 192.168.14.2 ', ' 192.168.15.5 '],                    :d b2 => [' 192.168.14.3 ', ' 192.168.15.6 ']             }   lb_servers = { :lb1 =>   ' 192.168.15.2 '             }    app_servers.each do&nbSp;|app_server_name,app_server_ip|     config.vm.define app_server_name do  |app_config|        app_config.vm.host_name = app_ server_name.to_s        app_config.vm.network :p Rivate_network,ip : app_server_ip[0]        app_config.vm.network :p Rivate_ network,ip: app_server_ip[1],virtualbox_inet: true      end   end   db_servers.each do |db_server_name,db_server_ip|      config.vm.define db_server_name do |app_config|          app_config.vm.host_name = db_server_name.to_s          app_config.vm.network :p rivate_network,ip: db_server_ip[0]          app_config.vm.network :p rivate_network,ip: db_server_ip[1],virtualbox_inet: true       end   end   lb_servers.each do |lb_server_name , Lb_server_ip|      config.vm.define lb_server_name do |app_ Config|         app_config.vm.host_name = lb_server_ name.to_s         app_config.vm.network :p Rivate_network,ip:  lb_server_ip     end   endend


Startup is probably as follows

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7C/42/wKioL1bO972gixboAABtX4Zwm5k619.png "title=" 5.png " alt= "Wkiol1bo972gixboaabtx4zwm5k619.png"/>


In fact, a one-time Kai Five, the general computer (refers to 4GB) is slightly strenuous, so either in their own computer room to play on the server, or in a slightly better host play it ~ ~ ~


PostScript: Personally think Vagrant for operation is still very friendly, based on the command line tool is cool enough (personal feeling) ~ and in some cases, we need to frequently create virtual machine to test, build some service cluster, need a light, simple, repeatable, reliable environment, and these, Vagrant is available, and it's simpler and easier to use than creating virtual machines on VMware or a private cloud.


This article is from the "Ear Note" blog, be sure to keep this source http://youerning.blog.51cto.com/10513771/1745102

Vagrant deployment development environment, not a little bit cool

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.