Featured post

Create Multiple Virtual Machines Using Vagrant

 


Requirement 1: Hadoop is one of the state of the art technologies today and it tends to be utilized by creating a hadoop cluster. Now and again you don't need an undeniable cluster, however can make do with two servers only. Nonetheless, you will require no less than three datanodes. For this situation, you might involve one server as Namenode (since namenode has be a very good quality machine) and in the other server you can make 3 VMs and use them as 3 datanodes.

Requirement 2: You are working in a production environment where you are managing a major project. As all of us know that before we send the project on the live server, the project must be developed on the development server and tested on the test server. These servers are of a similar configuration. Henceforth, we might utilize vagrant to create these servers all together as opposed to building them individually.

There can be numerous other requirements where you might use this component. I would urge you to remark your necessity on this blog with the goal that it can help other people also.

It is expected that you have Vagrant and Virtual Box previously installed. Presently, we should perceive how to create multiple VMs using vagrant:

Step 1: Open the terminal (Linux or Mac) or command prompt (Windows)

Step 2: Create a new directory for vagrant :

$ mkdir vagrant_multi_rude
$ cd vagrant_multi_rude

Step 3: Initialize a new VagrantFile.

$ vagrant init

Step 4: Install a vagrant box. We are using “chef/centos-6.5” 

$ vagrant box add chef/centos-6.5

Step 5: Update the Vagrant File as below:

# This defines the version of vagrant
Vagrant.configure(2) do |config|
	# Specifying the box we wish to use
	config.vm.box = "chef/centos-6.5"
	# Adding Bridged Network Adapter
	config.vm.network "public_network"
	# Iterating the loop for three times
	(1..3).each do |i|
		# Defining VM properties
		config.vm.define "rude_vm#{i}" do |node|
			# Specifying the provider as VirtualBox and naming the VM's
			config.vm.provider "virtualbox" do |node|
				# The VM will be named as rude_vm{i}
				node.name = "rude_vm#{i}"  
			end
		end
	end
end

Step 6: Let’s start the rude_vms namely: rude_vm1, rude_vm2 and rude_vm3:

$ vagrant up

Congratulations! You have created three VMs using single vagrant file. You must be wondering how to use it. You can access it using ssh.
You can connect the VMs using the below host and port number:
                         rude_vm1        –>        Host : 127.0.0.1    |   Port  : 2222
                         rude_vm2        –>        Host : 127.0.0.1    |   Port  : 2200
                         rude_vm3        –>        Host : 127.0.0.1    |   Port  : 2201

Step 7: Download putty (windows shh client) from here. Run the application and connect to the VMs.

Comments