Skip to content

Instantly share code, notes, and snippets.

@Buravo46
Last active October 5, 2016 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Buravo46/4d92bd687fea8e46b5a81782a47ddf72 to your computer and use it in GitHub Desktop.
Save Buravo46/4d92bd687fea8e46b5a81782a47ddf72 to your computer and use it in GitHub Desktop.
【Varant】複数のVMを立ち上げて、お互いに通信する方法

前提

  • windows 10
  • virtual box 5.1.6
  • vagrant 1.8.6

手順

  • Vagrantfileを編集する。

後続の「VagrantFile」を参照する。

  • VMを立ち上げる。
全てのVMを立ち上げる。
# vagrant up

指定のVMを立ち上げる。
# vagrant up master
# vagrant up slave
  • SSHで接続する。
vagrantのSSHコマンドで対象のVMへ接続する。
# vagrant ssh master
masterへ接続後、slaveへ接続する。
# ssh vagrant@192.168.33.11

VagrantFile

# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
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 = "CentOS7"

  config.vm.define :master do |master|
    master.vm.box = "CentOS7"
    master.vm.hostname = "MASTER"
    master.vm.network :forwarded_port, id: "ssh", guest: 22, host: 2222
    master.vm.network "private_network", ip: "192.168.33.10"
  end

  config.vm.define :slave do |slave|
    slave.vm.box = "CentOS7"
    slave.vm.hostname = "SLAVE"
    slave.vm.network :forwarded_port, id: "ssh", guest: 22, host: 2223
    slave.vm.network "private_network", ip: "192.168.33.11"
  end
  config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
  #   vb.gui = true
  #
  #   # Customize the amount of memory on the VM:
    vb.memory = "1024"
  end
end

参考サイト

vagrantで複数の仮想サーバを作る

VagrantとDockerとAnsibleで環境自動構築!(前編:vagrantとAnsible編)

[Vagrant] Vagrant で複数のVM を立ち上げて、お互いに通信できるようにするには [VirtualBox]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment