Overview
I used to use this machine directly for daily use because I have a machine at home with Linux, but later on I couldn’t use this machine directly at work, so the usage of this machine was low, so I stopped using it directly and used it as a server and connected to it via remote connection.
However, I feel that this machine is OK for personal use, so I want to open some VMs to do some separate things. As a rule of thumb, I would probably use Virsh directly (I don’t want to install GUI and use WebUI), but thinking that these VMs I use may also be available to the public cloud, I chose another familiar tool: Vagrant.
Introduction to Vagrant
Vagrant is a tool developed by Hashicorp for managing VM infrastructure, it’s a bit like Docker in concept, that is, you can manage your development and runtime environment through a configuration file that can be versioned, Docker is through Compose (a large Docker manages container environments through Compose (Kubernetes for large orchestration), while Vagrant manages VM environments through Vagrantfile.
Vagrant can support different virtualization platforms through plugins, where virtualization platforms are not only local virtualization platforms (KVM, Vmware etc) but also public cloud platforms, so Vagrant view smoothes out the differences between platforms through Vagrantfile, allowing developers to migrate smoothly.
Installation Configuration
Installing Vagrant
Arch-based Linux can be installed directly through the package management tool at
[root@liqiang.io]# yay -Sy vagrant
Just wait for the installation to finish. For more other systems you can follow the instructions in the official documentation: Installing Vagrant.
Installing the DigitialOcean plugin
[root@liqiang.io]# vagrant plugin install vagrant-digitalocean
[root@liqiang.io]# cat Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'yaml'
current_dir = File.dirname(File.expand_path(__FILE__))
configs = YAML.load_file("#{current_dir}/.vagrant.yaml")
vagrant_config = configs['configs']
do_token = vagrant_config['digital_ocean_token']
Vagrant.configure('2') do |config|
config.vm.define "droplet1" do |config|
config.vm.provider :digital_ocean do |provider, override|
override.ssh.private_key_path = '~/.ssh/id_rsa'
override.vm.box = 'digital_ocean'
override.vm.box_url = "https://github.com/devopsgroup-io/vagrant-digitalocean/raw/master/box/digital_ocean.box"
override.nfs.functional = false
override.vm.allowed_synced_folder_types = :rsync
provider.token = do_token
provider.image = 'ubuntu-18-04-x64'
provider.region = 'nyc1'
provider.size = 's-1vcpu-1gb'
end
end
end
Installing KVM Plugins
- Following Guide: Vagrant Installation
[root@liqiang.io]# sudo pacman --sync --sysupgrade --refresh
[root@liqiang.io]# sudo pacman --query --search 'iptables' | grep "local" | grep "iptables " && \
sudo pacman --remove --nodeps --nodeps --noconfirm iptables
[root@liqiang.io]# sudo pacman --sync --needed --noprogressbar --noconfirm \
iptables-nft libvirt qemu openbsd-netcat bridge-utils dnsmasq vagrant \
pkg-config gcc make ruby
[root@liqiang.io]# vagrant plugin install vagrant-libvirt
Vagrant testing
[root@liqiang.io]# vagrant init fedora/32-cloud-base
[root@liqiang.io]# vagrant up --provider=digital_ocean # Try digital ocean
[root@liqiang.io]# vagrant up --provider=libvirt # try libvirt
[root@liqiang.io]# vagrant ssh
[root@liqiang.io]# vagrant destroy
Specify virtualization via environment variables
[root@liqiang.io]# export VAGRANT_DEFAULT_PROVIDER=libvirt
Problems
enables ipv6 by default
When booting via vagrant up, I found that ipv6 is used by default, and then it fails to.
[root@liqiang.io]# vagrant up
Bringing machine 'default' up with 'libvirt' provider...
==> default: Checking if box 'centos/7' version '2004.01' is up to date...
... ...
I didn’t find out what the cause was, and suspected that it might be caused by some configuration not taking effect after the installation without rebooting, so I tried a reboot, and then found that it worked fine after the reboot.
Remarks
- I wanted to use Vultr for the public cloud, but vagrant-vultr was in disrepair, so I gave up.