How to use a command-line tool called Vagrant to build your own verification environment
table of contents
My name is Ito and I am an infrastructure engineer.
It is commonplace in this world that we do not touch the customer's environment.
Normally, you should prepare a similar verification environment and perform verification there, but if you
messed with the production environment without permission and something happened, you are a disqualified infrastructure engineer! That's right.
Vagrant which we will introduce this time
is a tool that allows you to easily prepare a virtual verification environment that would be troublesome to prepare
What is Vagrant?
Vagrant specializes in efficiently creating and manipulating virtual machine (VM) environments, and is a command line tool that works in conjunction with various virtualization software such as VirtualBox, VMware, and AWS (EC2).
This time, we will install Vagrant using VirtualBox.
procedure
Let's install Vagrant.
Installing VirtualBox
Vagrant requires software called VitrualBox that can start a virtual OS on the OS.
Download VirtualBox from the following site.
Downloads – Oracle VM VirtualBox
I think there will be no problems if you follow the installer.
If you are unsure about the installation procedure, please refer to the following site.
Install VirtualBox on Windows | VirtualBox Mania
Installing Vagrant
Next is the installation of Vagrant.
Download from the site below.
Download - Vagrant by HashiCorp
As with VirtualBox, if you are unsure about the installation procedure, please refer to the following site.
Steps to install Vagrant on Windows | WEB ARCH LABO
After installation, try entering the following command at the command prompt.
You should see the version of Vagrant.
C:Userstest>vagrant --version Vagrant 1.7.4
Try starting up a virtual environment
Let's actually start up a virtual environment using Vagrant.
Vagrant downloads a disk image called "box" and
creates the box file as a virtual environment according to the configuration file.
box file can be obtained from below.
Official: Discover Vagrant Boxes | Atlas by HashiCorpUnofficial
: A list of base boxes for Vagrant - Vagrantbox.esActually
, I think you often use the unofficial vagrantbox.es.
By the way, you can also create your own box file.
First, let's download the box file.
vagrant box add <box name> <box URL>
It will look like this. Download the centos7 box file with the name centos70.
$ vagrant box add centos70 https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.1.0/centos-7.0-x86_64.box ==> box: Box file was not detected as metadata. Adding it directly... ==> box: Adding box 'centos70' (v0) for provider: box: Downloading: https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.1.0/centos-7.0-x86_64.box box: ==> box: Successfully added box 'centos70' (v0) for 'virtualbox'!
Check if box is downloaded.
$ vagrant box list centos70 (virtualbox, 0)
You can confirm that a box named "centos70" has been downloaded.
Next, create a definition file based on box.
A virtual server will be started based on this definition file.
$ vagrant init centos70 A `Vagrantfile` has been placed in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `vagrantup.com` for more information on using Vagrant.
A definition file called "Vagrantfile" will be created in the current directory.
By configuring this definition file, you can start a virtual server with various settings.
Now it's time to start up the virtual server.
It loads the settings in Vagrantfile and starts up.
$ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'centos70'... ==> default: Matching MAC address for NAT networking... ==> default: Setting the name of the VM: centos7_default_1455040381652_22475 ==> default: Clearing any previously set forwarded ports... ==> 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 for machine to boot. This may 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: default: Vagrant insecure key detected. Vagrant will automatically replace default: this with a newly generated keypair for better security. default: default: Inserting generated public key within guest... default: Removing insecure key from the guest if it's present... default: Key inserted! Disconnecting and reconnecting using new SSH key... ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... ==> default: Mounting shared folders... default: /vagrant => D:/system/cygwin64/home/itou/centos7
I'll try connecting.
$ vagrant ssh Last login: Sat May 30 12:27:44 2015 from 10.0.2.2 Welcome to your Vagrant-built virtual machine. [vagrant@localhost ~]$
Done!
In addition to the commands listed above, frequently used commands are listed below.
#Stop Vagrant vagrant halt #Reload Vagrantfile (restart) vagrant reload #Discard Vagrant (throw away the created virtual server) vagrant destroy #Check Vagrant status vagrant status
summary
The above is a simple way to build a verification environment using Vagrant!
The only thing that takes the most time is downloading the box file.
I think the company has default settings on the server.
The virtual environment with such settings added can be made into a box file, so
there is no need to perform the same operations for each verification environment.
Also, by using Vagrantfile, you
can easily configure port forwarding, set private IP addresses, and launch multiple virtual environments.
If you can master this area, you will be able to easily build complex environments.
Everyone, please use Vagrant to build a good verification environment!
If you want to consult a cloud professional
At Beyond, we use the technical capabilities we have cultivated as a multi-cloud integrator and managed service provider (MSP) since our founding to design, build, and migrate using various cloud/server platforms such as AWS, GCP, Azure, and Oracle Cloud. I went there.
We provide custom-made cloud/server environments that are optimized for customers according to the specifications and functions of the systems and applications they require, so if you are interested in the cloud, please feel free to contact us. .
● Cloud/server design/construction
● Cloud/server migration/migration
● Cloud/server operation, maintenance, and monitoring (24 hours a day, 365 days a year)