Vagrant multi-machine multi-node virtual cluster

Keywords: Docker shell ssh VirtualBox

The first two articles share the homestead + vagrant configuration, but they are single-point. Now let's study the configuration of multi-node cluster together.

Multi-node Cluster Configuration/Creation

Install VirtualBox

Install Vagrant

Download Box

These previous articles have explanations and download links, which are not repeated. You can see: Write links here

Modify vagrantfile

1. The original vagrantfile is:

Vagrant.configure("2") do |config|
  ## Intermediate Notes Neglected
end

2. Modify the add code as follows:

Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.
  # config.vm.box = "base"

  (1..3).each do |i|

        config.vm.define "node#{i}" do |node|

        # Setting up the Box of the Virtual Machine
        node.vm.box = "laravel/homestead"

        # Setting the host name of the virtual machine
        node.vm.hostname="node#{i}"

        # Setting up IP of Virtual Machine
        node.vm.network "private_network", ip: "192.168.10.1#{i}"

        # Setting up shared directories between host and virtual machine
        node.vm.synced_folder "F:/workSpace/quickstart1", "/home/vagrant/share"

        # VirtaulBox related configuration
        node.vm.provider "virtualbox" do |v|

            # Set the name of the virtual machine
            v.name = "node#{i}"

            # Set the memory size of the virtual machine  
            v.memory = 2048

            # Setting CPU Number of Virtual Machines
            v.cpus = 1
        end

        # Software installation and configuration using shell scripts
        # node.vm.provision "shell", inline: <<-SHELL

        #     # Install docker 1.11.0
        #     wget -qO- https://get.docker.com/ | sed 's/docker-engine/docker-engine=1.11.0-0~trusty/' | sh
        #     usermod -aG docker vagrant

        # SHELL

         end
    end

Compared with creating a single virtual machine, there is a layer of loops in creating multiple virtual machines, and variable I can be used to set the name and IP of the node, using {i} to get the value:

(1..3).each do |i|

end

Through the previous article's explanation, you should know how to correspond to the shared file. In the code:

# Setting up shared directories between host and virtual machine
        node.vm.synced_folder "F:/workSpace/quickstart1", "/home/vagrant/share"

Creating Virtual Machines

vagrant up

This command creates three virtual machines in a loop: node1, node2, and node3. As shown in the picture:

Varant up creates and starts all the virtual machines in your loop.

Cluster management

Frequently used commands

Below are some common Vagrant management commands that only specify the name of the virtual machine when operating a particular virtual machine.

command explain
up Start homestead
halt Stop homestead
init Create initialized homestead.yaml
edit Edit homestead.yaml
suspend Hang up homestead
resume Hostead hanging up
ssh Log in to homestead via ssh
run Running commands on homestead through ssh
status Get the status of homestead
list List command
help Help in displaying commands
provision Reconfigure homestead
destroy Destroy homestead
update Update the homestead image

Start a single virtual machine

vagrant up node1

Start multiple virtual machines

vagrant up node1 node2

Start all virtual machines

vagrant up

Other logins to virtual machines and so on are described in the previous articles.

Posted by step on Wed, 03 Apr 2019 16:06:31 -0700