Running multiple instances of Vagrant VM

Today, I hit with a scenario where I wanted to setup a Mediawiki -Mail server model, so that I can test the working of the main email system. My goal was to implement the handling of mail bounces using VERP as part of my GSoC proposal. My mentors suggested that I should be able to mange two VM’s in vagrant – one running the MediaWiki web- server, which will send the mail with the help of the inbuilt php functions and the other box, which would run a plain installation of Ubuntu with a mail-server installed -Exim4. Exim4 is used by the MediaWiki servers.
Setting up two vagrant instances was the difficult part. I am explaining, how I went through.You can get the Mediawiki Vagrant from here .
Now, the usual steps for a single instance vagrant-for-MWiki, as given  is to clone the repo, get inside, and give vagrant up. So, inorder to run multiple instances, we need to understand clearly what happens on vagrant up.

Vagrant
Now, every vagrant has a VagrantFile, which basically controls what all goes inside the box, or what all needs to come up, when ‘vagrant up’ is given.Going through the vagrantfile  , you can see that
Vagrant.configure('2') do |config|
is the main function under which the default configurations for the linux is written. Now, going through (http://docs.vagrantup.com/v2/multi-machine/) will show exactly how to add the two servers.

/* The boxes I need to add are named “webserver” and “mail”
*I need to have both the VM’s under the same private network, so that they will communicate.
*Therefore, I need to assign Box#1 with 10.11.12.10 amd Box#2 with 10.11.12.13.
*Make sure you change all required vm.box to webserver.vm.box
*Make sure you give different forwarded_port to both of your installations.
*Consider giving 1024 to first and 1025 to second better delete the declaration
*FORWARDED_PORT = 8080 line, and just substitute it with the corresponding port numbers.
*/

Now, inorder to append the existing Vagrant file :

Vagrant.configure('2') do |config|
config.vm.define "webserver" do |webserver|
config.vm.hostname = 'mediawiki-vagrant.dev'
webserver.vm.box = 'precise-cloud'
webserver.vm.network :private_network,
ip: '10.11.12.10'

and continue it till

puppet.facter = $FACTER = {
'fqdn' => config.vm.hostname,
'forwarded_port' => 1240,
'shared_apt_cache' => '/vagrant/apt-cache/',
}
end

after which, add the configurations for your second “mail” box:-

config.vm.define "mail" do |mail|
mail.vm.box = 'precise-cloud'
config.vm.hostname = 'eximmail'
mail.vm.network :private_network,
ip: '10.11.12.13'
mail.vm.network :forwarded_port,
guest: 80, host:1250, id: 'http'

and copy all the code from above from

 # www-data needs .. to
'shared_apt_cache' => '/vagrant/apt-cache/',
}
end

so that it will have all the properties of the other VM.
And at the last, make sure you end the box configs.
Now, fire up the separate boxes with the commands:

vagrant up webserver
vagrant up mail

Now, follow instructions in (http://askubuntu.com/questions/22743/how-do-i-install-guest-additions-in-virtualbox) to install the LinuxGuestAdditions.Any queries, please comment.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s