Problems encountered

I need to deploy an ETCD cluster, not a pseudo-cluster using the Goreman tool. In order to be equivalent to the real environment, three machines are needed, but the author has only one host, Centos system, configured with 8G dual-core. The idea of starting the VIRTUAL machine in standalone Centos came to mind.

Environment to prepare

The use of Vagrant needs to be combined with VirtualBox, and we prepare the installation sources for both software, as well as the centos7 images used:

#virtualbox
https://www.virtualbox.org/wiki/Linux_Downloads

#vagrant
https://www.vagrantup.com/downloads.html

#centos7.box
http://cloud.centos.org/centos/7/vagrant/x86_64/images/
Copy the code

The author downloaded the latest version, the download speed of the official website is really slow (you can contact the author to obtain the downloaded installation package if necessary), the file is as follows:

$ls CentOS - 7 - x86_64 - Vagrant - 2002 _01 VirtualBox. Box VirtualBox - 6.1-6.1.6 _137129_el7-1. X86_64. RPM Vagrant_2. 2.7 _x86_64. RPMCopy the code

The installation

$yum -y localinstall virtualbox-6.1-6.1.6_137129_el7-1.x86_64. RPM vagrant_2.7_x86_64. RPMCopy the code

As above, install Vagrant and VirtualBox.

Initialize the

The common commands for Vagrant are the following, commands for managing boxes, such as add, delete, and so on. The following commands are used to complete the function of the command:

Add the box file, which is the image file we just downloaded, and you can use it everywhere.
vagrant  box add  CentOS-7-x86_64-Vagrant-2002_01.VirtualBox.box --name centos7
Create a configuration file
vagrant init centos7
Copy the code

The initialization step generates a Vagrantfile, or configuration file.

$ vagrant init centos7

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.
Copy the code

Vagrantfile configuration

Common configurations are as follows:

  • Config.vm. box: This name is used again after the name in vagrant Init
  • Config.vm. hostname: specifies the vm hostname
  • Config.vm.net work: This is the configuration of the virtual machine network, because of the complexity, we will discuss separately later
  • Config.vm. synced_folder: You can specify bindings manually in addition to the default directory bindings
  • Config.ssh. username: The default user is Vagrant, which is often used by official downloads of boxes. If it is a custom box, the user name may be different. Set the user name to be used with this configuration.
  • Config.vm. provision: Config.vm. provision: Config.vm. provision: Installs and configures VMS when they are started for the first time

There are more detailed configuration, see: www.vagrantup.com/docs/vagran…

Vagrant.configure("2") do |config|

  config.vm.box = "centos7"

   config.vm.network "public_network", ip: "192.168.0.5"

   config.vm.provider "virtualbox" do |vb|
     # Display the VirtualBox GUI when booting the machine
     vb.gui = false
     # Customize the amount of memory on the VM:
     vb.memory = "1024"
   end
end
Copy the code

As you can see, the configuration is relatively simple, with the network specified using a bridge, the GUI turned off, and the memory limited to 1GB.

Start the

$ vagrant  up

The provider 'virtualbox' that was requested to back the machine
'default' is reporting that it isn't usable on this system. The
reason is shown below:

VirtualBox is complaining that the kernel module is not loaded. Please
run `VBoxManage --version` or open the VirtualBox GUI to see the error
message which should contain instructions on how to fix this error.
Copy the code

Virtualbox-is-what-the-kernel-module-is-not-loaded The reason is that Vagrant relies on kernel-devel GCC to make Perl. Start kernel-devel, and it is best to follow Vagrant’s instructions to install and use the kernel version of the library.

View the kernel version with uname:

$ uname -aLinux aoho 3.10.0-1062.1.2. El7. X86_64#1 SMP Mon Sep 30 14:19:46 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
Copy the code

So we need to install the appropriate package:

The kernel - devel - 3.10.0-1062.1.2. El7. X86_64. RPMCopy the code

Download the corresponding package from the official website and install it. Start the vagrant:

# Start the VM
vagrant up
Enter the VM
vagrant ssh
Copy the code

And you’re done!

Recommended reading

The interview collection

Subscribe to the latest articles, welcome to follow my official account

reference

  1. Vagrant configuration file Vagrantfile details -2
  2. How to handle The VirtualBox startup error message: The vboxdrv kernel module is not loaded
  3. virtualbox-is-complaining-that-the-kernel-module-is-not-loaded
  4. www.vagrantup.com