Wednesday, 22 July 2015

Creating Cluster of Vagrant Machines


CLUSTER OF VAGRANT MACHINE

Setting up a cluster with one vagrant file:

Make sure you have a virtualbox installed in your machine by the command:
vboxmanage –version
If it is not installed then install it with the following command:
sudo apt-get install virtualbox

Make sure you have a vagrant installed in your machine by the command:
vagrant –version
If it is not installed then install it with the following command:
sudo apt-get install vagrant

Create a file named Vagrantfile in the empty directory of your choice having the following code in it:

Vagrant.configure("2") do |config|
    # Number of nodes to provision
    numNodes = 4
    # IP Address Base for private network
    ipAddrPrefix = "192.168.56.10"

    # Define Number of RAM for each node
    config.vm.provider "virtualbox" do |v|
        v.customize ["modifyvm", :id, "--memory", 1024]
    end

    # Download the initial box from this url
    config.vm.box_url = "http://files.vagrantup.com/precise64.box"

    # Provision Config for each of the nodes
    1.upto(numNodes) do |num|
        nodeName = ("node" + num.to_s).to_sym
        config.vm.define nodeName do |node|
            node.vm.box = "precise32"
            node.vm.network :private_network, ip: ipAddrPrefix + num.to_s
            node.vm.provider "virtualbox" do |v|
                v.name = "Couchbase Server Node " + num.to_s
            end
        end
    end

end


Then run the command vagrant up to up the cluster! This will setup 4 node cluster for you.

No comments:

Post a Comment