Create Multiple Linux Machines using Vagrant

Create Multiple Linux Machines using Vagrant

Any type of demo or learning in the big data area needs multiple machines to be fully configured and setup. The initial setup task of configuring the IPs and connecting all the machines to the internet is fairly laborious and time-consuming.

In this post, I will provide simple step by step instructions on how to have multiple machines fully configured using Vagrant. The below steps have been tried by me on Windows 10 laptop, but the steps should be similar on alternative desktops / laptops.

Pre-Requisites (Software Needed)

You will need the following software to be installed on your desktop/laptop.

Pre-Requisites (Fist Time Setup)

Vagrant First Time Setup ( https://www.vagrantup.com/intro/getting-started/project_setup.html )

If you are using Windows, please run the below steps on the Dos Command Prompt. Or use the appropriate steps for your Operating System.

  • cmd> mkdir testing-vagrant
  • cmd> cd testing-vagrant
  • cmd> vagrant init

This will create a Vagrantfile . We will replace its contents later.

Create Vagratfile

Place below “Vagrantfile” on any windows folder say c:\testing-vagrant2
Contents of Vagrantfile below:

Vagrant.configure("2") do |config|
##  config.vm.box = "bento/centos-7.2"
    config.vm.define "kfdmc1" do |kfdmc1| 
        kfdmc1.vm.box = "bento/centos-7.2"
        kfdmc1.vm.network "private_network", ip:"192.168.77.10"
        kfdmc1.vm.hostname = "kfdmc1"
        kfdmc1.vm.provider :virtualbox do |vb|
           vb.name = "kfdmc1"
                                 vb.memory = 2048
                                 vb.cpus = 1
        end
    end    
    config.vm.define "kfdmc2" do |kfdmc2| 
        kfdmc2.vm.box = "bento/centos-7.2"
        kfdmc2.vm.network "private_network", ip:"192.168.77.11"
        kfdmc2.vm.hostname = "kfdmc2"
        kfdmc2.vm.provider :virtualbox do |vb|
           vb.name = "kfdmc2"
                                 vb.memory = 2048
                                 vb.cpus = 1
        end
    end    
    config.vm.define "kfdmc3" do |kfdmc3| 
        kfdmc3.vm.box = "bento/centos-7.2"
        kfdmc3.vm.network "private_network", ip:"192.168.77.12"
        kfdmc3.vm.hostname = "kfdmc3"
        kfdmc3.vm.provider :virtualbox do |vb|
           vb.name = "kfdmc3"
                                 vb.memory = 2048
                                 vb.cpus = 1
        end
    end    
end

Start the Vagrant Machines

  • cmd> cd c:\testing-vagrant2
  • cmd> vagrant up

That is it .. vagrant will create the machines and start them up for you

The Machine Details

Please note the below in the machines created as per the details of the vagrantfile

Please note that there are 3 machines created 
Please note that the Memory is 2048 Mb each
Please note that we have assigned 1 CPU to each machine
The hostname of the machines are kfdmc1, kfdmc2 and kfdmc3 as per the vagrantfile
The IP addresses of the machines are 192.168.77.10, 192.168.77.11, 192.168.77.12 as per the vagrantfile
We can create more machines if our laptop/desktop has enough RAM
Please leave 4 GB for your host OS – Windows in my case
The Operating System Image used is “centos-7.2

 

Connect to the Machines using Putty

  • c:\testing-vagrant2> vagrant ssh kfdmc1

or

  • Use putty to connect to the machines

IP “192.168.77.10”
port “22”
Connection Type SSH

  • Alternatively use Putty to connect using

IP “127.0.0.1”
port “2222” or something similar
Check the Port details displayed after “vagrant up”
Connection Type SSH

  • UID/Password

vagrant/vagrant
root/vagrant

Check that you can connect to the Internet

$ ping -c1 google.com
Or
$ ping -c1 google.com | grep –color “0% packet loss”

Setup the /etc/ hosts on all the machines so that you can ssh using machine names

# vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.77.10 kfdmc1
192.168.77.11 kfdmc2
192.168.77.12 kfdmc3

Benefits

As mentioned earlier speed
You can create, destroy and recreate machines quickly
You will be able to try out with different versions of the operating system
This is just the beginning

References

https://www.virtualbox.org/
https://www.vagrantup.com/intro/getting-started/install.htm
l http://www.thisprogrammingthing.com/2013/getting-started-with-vagrant/
http://www.thisprogrammingthing.com/2015/multiple-vagrant-vms-in-one-vagrantfile/

Author: Pathik Paul

Webmaster: Ella Paul

One thought on “Create Multiple Linux Machines using Vagrant

Leave a Reply to Anubrata Chowdhury Cancel reply

Your email address will not be published. Required fields are marked *