Learn how to install Vagrant with KVM provider in this comprehensive guide. Follow our step-by-step instructions to set up a powerful development environment using Vagrant and KVM on your Linux system. Perfect for developers and system administrators looking to optimize their workflow. #centlinux #vagrant #libvirt
Vagrant is an open-source tool designed for building and managing virtualized development environments. It simplifies the process of setting up, configuring, and deploying virtual machines by providing a consistent workflow. Vagrant uses a simple configuration file, called a Vagrantfile, to define the properties and behavior of the virtual environments, making it easy for developers to create and share reproducible environments. It supports various virtualization providers, including VirtualBox, VMware, and KVM, and can integrate with configuration management tools like Ansible, Puppet, and Chef. This makes Vagrant a valuable tool for developing, testing, and deploying software in a consistent and isolated environment.
Vagrant was originally tied with Oracle VirtualBox. But later Vagrant added the support for other virtualization platforms such as VMWare and KVM.
In technical terminology, these virtualization platforms (VirtualBox, KVM, VMWare, etc) are called Providers, while the Vagrant itself is termed as Provisioner.
Read Also: Install Vagrant with VirtualBox on Ubuntu Server 18
KVM (Kernel based Virtual Machine) is a virtualization module in Linux kernel, that allows Kernel to function as a Hypervisor. In CentOS 7 or later, KVM has replaced legacy Xen Kernel, and now the KVM is used in most of the Linux distros for virtualization.
KVM is free and open source and we can use it to configure a high performance and feature enrich virtualization server.
Recommended Online Training: Vagrant Essentials: Learn DevOps Using Vagrant
We are provisioned a CentOS 8 Server with following specifications.
Connect with vagrant-02.centlinux.com as root user by using PuTTY.
We are updating installed software packages in our CentOS 8 server by using dnf command.
# dnf update -y
Since, we are planning to use Vagrant with KVM provider, therefore, we need to install libvirt and KVM/QEMU packages on our CentOS 8 server.
# dnf install -y @virt virt-install
Here, we have installed libvirt and KVM/QEMU on CentOS 8 but for a detailed step by step guide you can refer to our previous article: Install KVM based Virtualization Server.
Vagrant is written in Ruby and it requires Ruby development tools for compilation of Vagrant extensions and plugins. Thus, we are required to install Ruby on CentOS 8 before installing Vagrant.
Ruby 2.5.5 is available in AppStream yum repository and we can install it using dnf command.
# dnf install -y ruby ruby-devel
Check version of installed ruby command.
# ruby -v ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]
Ruby requires Nokogiri library for parsing HTML and XML while compliling Vagrant extensions.
We can either install nokogiri from EPEL (Extra Packages for Enterprise Linux) or by using RubyGem package manager.
Since, we have RubyGem package manager already installed with installation of Ruby, therefore, we can use it to install nokogiri gem.
But first we have to install the nokogiri dependencies as follows.
# dnf install -y make gcc rpm-build ruby-devel zlib-devel
Now, install nokogiri library using gem command.
# gem install nokogiri Fetching: mini_portile2-2.4.0.gem (100%) Successfully installed mini_portile2-2.4.0 Fetching: nokogiri-1.10.9.gem (100%) Building native extensions. This could take a while... Successfully installed nokogiri-1.10.9 2 gems installed
At the time of this writeup, latest stable version is Vagrant 2.2.9. You can download Vagrant 2.2.9 for your respective operating system from Vagrant website.
Copy the URL of your required Vagrant RPM and use wget command to download it.
# wget https://releases.hashicorp.com/vagrant/2.2.9/vagrant_2.2.9_x86_64.rpm --2020-05-08 15:40:41-- https://releases.hashicorp.com/vagrant/2.2.9/vagrant_2.2.9_x86_64.rpm Resolving releases.hashicorp.com (releases.hashicorp.com)... 151.101.241.183, 2a04:4e42:39::439 Connecting to releases.hashicorp.com (releases.hashicorp.com)|151.101.241.183|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 43598220 (42M) [application/x-redhat-package-manager] Saving to: âvagrant_2.2.9_x86_64.rpmâ vagrant_2.2.9_x86_6 100%[===================>] 41.58M 937KB/s in 48s 2020-05-08 15:41:30 (890 KB/s) - âvagrant_2.2.9_x86_64.rpmâ saved [43598220/43598220]
Install Vagrant RPM on CentOS 8 by using dnf command.
# dnf install -y vagrant_2.2.9_x86_64.rpm
Check version of installed vagrant command.
# vagrant --version Vagrant 2.2.9
Vagrant has been installed on CentOS 8 server.
We need to install a Vagrant plugin to use KVM provider.
libvirt-devel package is required for vagrant-libvirt plugin installation, and we are installing it by using dnf command.
# dnf install –y libvirt-devel
Now, install vagrant-libvirt plugin as follows.
# vagrant plugin install vagrant-libvirt Installing the 'vagrant-libvirt' plugin. This can take a few minutes... Building native extensions. This could take a while... Building native extensions. This could take a while... Fetching fog-libvirt-0.7.0.gem Fetching vagrant-libvirt-0.0.45.gem Installed the plugin 'vagrant-libvirt (0.0.45)'!
We have successfully installed Vagrant with KVM on CentOS 8.
Boxes are the package format for Vagrant environments. A box can be used by anyone on any platform that Vagrant supports to bring up an identical working environment.
You can search for your required boxes at Vagrant Cloud.
We are downloading the centos/7 box by using vagrant command.
# vagrant box add centos/7 --provider=libvirt ==> box: Loading metadata for box 'centos/7' box: URL: https://vagrantcloud.com/centos/7 ==> box: Adding box 'centos/7' (v1905.1) for provider: libvirt box: Downloading: https://vagrantcloud.com/centos/boxes/7/versions/1905.1/providers/libvirt.box ==> box: Box download is resuming from prior download progress Download redirected to host: cloud.centos.org ==> box: Successfully added box 'centos/7' (v1905.1) for 'libvirt'!
Vagrant also needs rsync utility, so install it using dnf command.
# dnf install -y rsync
Create a project directory for our CentOS 7 virtual machine.
# mkdir centos7 # cd centos7
Use vagrant command to initialize our CentOS 7 project. This command will create a Vagrantfile in our project directory, that can be used to create the desired virtual machine. You can customize this Vagrantfile according to your requirements.
# vagrant init centos/7 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.
Create and start CentOS 7 virtual machine as follows.
# vagrant up Bringing machine 'default' up with 'libvirt' provider... ==> default: Checking if box 'centos/7' version '1905.1' is up to date... ==> default: Creating image (snapshot of base box volume). ==> default: Creating domain with the following settings... ==> default: -- Name: centos7_default ==> default: -- Domain type: kvm ==> default: -- Cpus: 1 ==> default: -- Feature: acpi ==> default: -- Feature: apic ==> default: -- Feature: pae ==> default: -- Memory: 512M ==> default: -- Management MAC: ==> default: -- Loader: ==> default: -- Nvram: ==> default: -- Base box: centos/7 ==> default: -- Storage pool: default ==> default: -- Image: /var/lib/libvirt/images/centos7_default.img (41G) ==> default: -- Volume Cache: default ==> default: -- Kernel: ==> default: -- Initrd: ==> default: -- Graphics Type: vnc ==> default: -- Graphics Port: -1 ==> default: -- Graphics IP: 127.0.0.1 ==> default: -- Graphics Password: Not defined ==> default: -- Video Type: cirrus ==> default: -- Video VRAM: 9216 ==> default: -- Sound Type: ==> default: -- Keymap: en-us ==> default: -- TPM Path: ==> default: -- INPUT: type=mouse, bus=ps2 ==> default: Creating shared folders metadata... ==> default: Starting domain. ==> default: Waiting for domain to get an IP address... ==> default: Waiting for SSH to become available... 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: Configuring and enabling network interfaces... default: SSH address: 192.168.121.18:22 default: SSH username: vagrant default: SSH auth method: private key ==> default: Rsyncing folder: /root/centos7/ => /vagrant
To check status of our CentOS 7 virtual machine.
# virsh list Id Name State ---------------------------------------------------- 2 centos7_default running
We have successfully created our first virtual machine by using Vagrant boxes and KVM provider.
If you planning to implement Vagrant in your environment then we strongly recommend you to read Hands-On DevOps with Vagrant (PAID LINK) by Packt Publishing.
Setting up Vagrant with KVM provider can significantly enhance your development workflow by providing a consistent and efficient environment. This combination leverages the flexibility of Vagrant and the powerful performance of KVM to create robust virtualized environments. Whether you’re a developer, system administrator, or IT professional, mastering this setup can streamline your projects and boost productivity.
If you need assistance with installing Vagrant with the KVM provider, I’m here to help. With my expertise, I can guide you through the process, troubleshoot any issues, and ensure your environment is optimized for your specific needs.
Enhance your development process with a properly configured Vagrant and KVM setup. Visit my Fiverr gig: DevOps Engineer to get started and take your development environment to the next level!
Puppy Linux is a fast, lightweight OS designed for speed and simplicity, perfect for old…
Learn how to change Apache document root in Linux by following this step-by-step guide. Adjust…
Discover how to change Apache port in Linux easily. Follow our simple guide to modify…
Learn how to create a virtual host in Apache Server with this comprehensive guide. Set…
Discover 10 practical tasks for the RHCSA exam with step-by-step solutions. Boost your Linux skills…
Discover the ultimate Fail2ban configuration guide. Learn how to set up, customize, and optimize Fail2ban…
This website uses cookies.
View Comments
Thanks Sir