In order to use multiple virtual machines within our project, we need to tell Vagrant about them,
and we need to provide additional configuration for the individual virtual machines within the ordinary
Vagrant project configuration file.
We can tell Vagrant that we want to assign a name to a virtual machine being managed by the project.
Within this sub configuration, we provide the information Vagrant needs that is specific to that VM.
The syntax for the sub configurations is as follows You have to provide the name of the virtual machine
after config, dot vm dot.
Define configuration information.
So the whole line will look like config, dot vm dot.
Define name of the virtual machine do and the name of the virtual machine again followed by the end
command.
For example, the file the vagrant file for two virtual machines will look like this vagrant API version
two and the configuration for it where green dot configure two and double quotes and break it do config
and then followed by the lines describing the machines we want to run.
In this case it will be server one or SRB one and server two for each server.
We define the box by the LAN server as a 1.3. box equals to hashicorp slash size 64 or centos slash
seven.
As in my case, each configuration sub configuration for the VM is closed by the end command and the
end command for the whole vagrant file.
So in this case we will initiate two virtual machines as we want.
Enter server two running CentOS slash seven box when our multiple machines boot up in our multi machine
project, Vagrant automatically maps different ports from our host machine to the SSH ports on the various
guest machines.
Let's take a look at the console output when booting a vagrant project with two virtual machines and
find the information regarding a SSH port assigned to each of these machines.
As you can see, vagrant maps the ssh port on the virtual machine designated as we want to port with
the following number 2222 on the host machine and the SSH port of the machine designated as with two
to the port, which is available now.
This gives us the opportunity to simply using the standard SSH command from a terminal like party on
Windows machine or Siguiente terminal like mine to connect to local host with a port number that vagrant
assigns to each machine.
For example, to connect to the machine that is mapped to port 20 200.
We simply run the switch followed by the user vagrant in this case, which is default for all vagrant
machines at local host dash P and port number.
This this P port number option tells the command to use a non standard port and specifies the port we
wish to use.
It could be any number.
Alternatively, we can use the vagrant ssh command to connect to the virtual machines.
The difference is that in a multi virtual machine environment we must also provide the name of the virtual
machine.
For example, Vagrant is a such as av1.
This is the most common usage of connecting to machine rather than directly connecting to the virtual
machine via its IP address.