In this article, I will explain the procedure to build two virtual machines ** CentOS 7 ** on ** Windows 10 ** using VirtualBox and Vagrant.
--Host OS: Windows10 --Guest OS: 2 CentOS7 (client, server) --Virtual machine construction tool: VirtualBox, Vagrant
To build the environment, use a method that combines ** Virtual Box ** and ** Vagrant **.
The reason for using Vagarnt is that you can easily set up the network and build a virtual machine just by operating commands and setting necessary files on the command prompt without touching VirtualBox directly.
After building the environment, you can connect to the virtual machine by SSH connection from the command prompt and operate Linux commands. Of course, it is also possible to make an SSH connection using TeraTerm or PuTTY.
Download the latest version of VirtualBox from the URL below. https://www.virtualbox.org/wiki/Downloads
After downloading, install it on your PC.
Download the latest version of Vagrant from the URL below. https://www.vagrantup.com/downloads.html
After downloading, install it on your PC. When the installation is complete, open a command prompt and type the following command. Installation is complete when the installed vagrant version is displayed.
C:¥>vagrant -v Vagrant 2.2.10
vagrant init command in any directory to create a Vagrantfile.
D:\hoge>vagrant init D:\hoge>dir 2020/10/20 18:25 3,080 Vagrantfile
Edit the Vagrantfile as follows.
# -*- mode: ruby -*- # vi: set ft=ruby : # All Vagrant configuration is done below. The "2" in Vagrant.configure # configures the configuration version (we support older styles for # backwards compatibility). Please don't change it unless you 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 see the online documentation at # https://docs.vagrantup.com. # Every Vagrant development environment requires a box. You can search for # boxes at https://vagrantcloud.com/search. config.vm.box = "centos/7" config.vm.define :client do | client | client.vm.hostname = "client" client.vm.network :private_network, ip: "192.168.33.10" end config.vm.define :server do | server | server.vm.hostname = "server" server.vm.network :private_network, ip: "192.168.33.20" end ...
After editing the Vagrantfile, type the
vagrant up command and two CentOS 7s will be created in about 2-3 minutes.
D:\hoge>vagrant up --provider=virtualbox Bringing machine 'client' up with 'virtualbox' provider... Bringing machine 'server' up with 'virtualbox' provider... ==> client: Importing base box 'centos/7'... ==> client: Matching MAC address for NAT networking... ==> client: Checking if box 'centos/7' version '1905.1' is up to date... ~~~ Omitted ~~~ ==> server: Setting hostname... ==> server: Configuring and enabling network interfaces... ==> server: Rsyncing folder: /cygdrive/d/hoge/ => /vagrant
You can check the status of the virtual machine with the
vagrant status command.
If it is
running, the startup is successful.
D:\hoge>vagrant status Current machine states: client running (virtualbox) server running (virtualbox) This environment represents multiple VMs. The VMs are all listed above with their current state. For more information about a specific VM, run `vagrant status NAME`.
vagrant ssh command to connect to the built virtual machine.
The default password for root privileges is
I was able to SSH into the CentOS environment from the command prompt as shown below.
D:\hoge>vagrant ssh client [[email protected] ~]$ [[email protected] ~]$ su - Password: [[email protected] ~]# [[email protected] ~]# cat /etc/centos-release CentOS Linux release 7.6.1810 (Core)