Vagrant.configure("2") do |config| # 定义虚拟机数量 vms = Array(1..3) vms.each do |i| config.vm.define "centos8-#{i}"do |node| # 设置虚拟机的Box node.vm.box = "centos8" # 设置虚拟机的主机名 node.vm.hostname="centos8-#{i}" # 设置虚拟机的IP node.vm.network "private_network", ip:"172.24.20.4#{i}", hostname:true # 虚拟化设置cpu/mem node.vm.provider "virtualbox"do |v| # 设置虚拟机的名称 v.name = "centos8-#{i}" # 设置虚拟机的内存大小 v.memory = 1024 # 设置虚拟机的CPU个数 v.cpus = 1 end end end end
up log
mvpbang@mvpbang c8-4x % vagrant up
Bringing machine 'centos8-1' up with 'virtualbox' provider...
Bringing machine 'centos8-2' up with 'virtualbox' provider...
Bringing machine 'centos8-3' up with 'virtualbox' provider...
==> centos8-1: Importing base box 'centos8'...
==> centos8-1: Matching MAC address for NAT networking...
==> centos8-1: Setting the name of the VM: centos8-1
==> centos8-1: Clearing any previously set network interfaces...
==> centos8-1: Preparing network interfaces based on configuration...
centos8-1: Adapter 1: nat
centos8-1: Adapter 2: hostonly
==> centos8-1: Forwarding ports...
centos8-1: 22 (guest) => 2222 (host) (adapter 1)
==> centos8-1: Running 'pre-boot' VM customizations...
==> centos8-1: Booting VM...
==> centos8-1: Waiting for machine to boot. This may take a few minutes...
centos8-1: SSH address: 127.0.0.1:2222
centos8-1: SSH username: vagrant
centos8-1: SSH auth method: private key
centos8-1:
centos8-1: Vagrant insecure key detected. Vagrant will automatically replace
centos8-1: this with a newly generated keypair for better security.
centos8-1:
centos8-1: Inserting generated public key within guest...
centos8-1: Removing insecure key from the guest if it's present...
centos8-1: Key inserted! Disconnecting and reconnecting using new SSH key...
==> centos8-1: Machine booted and ready!
==> centos8-1: Checking for guest additions in VM...
centos8-1: No guest additions were detected on the base box for this VM! Guest
centos8-1: additions are required for forwarded ports, shared folders, host only
centos8-1: networking, and more. If SSH fails on this machine, please install
centos8-1: the guest additions and repackage the box to continue.
centos8-1:
centos8-1: This is not an error message; everything may continue to work properly,
centos8-1: in which case you may ignore this message.
==> centos8-1: Setting hostname...
==> centos8-1: Configuring and enabling network interfaces...
==> centos8-1: Rsyncing folder: /Users/mvpbang/vagrants/c8-4x/ => /vagrant
==> centos8-2: Importing base box 'centos8'...
==> centos8-2: Matching MAC address for NAT networking...
==> centos8-2: Setting the name of the VM: centos8-2
==> centos8-2: Fixed port collision for 22 => 2222. Now on port 2200.
==> centos8-2: Clearing any previously set network interfaces...
==> centos8-2: Preparing network interfaces based on configuration...
centos8-2: Adapter 1: nat
centos8-2: Adapter 2: hostonly
==> centos8-2: Forwarding ports...
centos8-2: 22 (guest) => 2200 (host) (adapter 1)
==> centos8-2: Running 'pre-boot' VM customizations...
==> centos8-2: Booting VM...
==> centos8-2: Waiting for machine to boot. This may take a few minutes...
centos8-2: SSH address: 127.0.0.1:2200
centos8-2: SSH username: vagrant
centos8-2: SSH auth method: private key
centos8-2:
centos8-2: Vagrant insecure key detected. Vagrant will automatically replace
centos8-2: this with a newly generated keypair for better security.
centos8-2:
centos8-2: Inserting generated public key within guest...
centos8-2: Removing insecure key from the guest if it's present...
centos8-2: Key inserted! Disconnecting and reconnecting using new SSH key...
==> centos8-2: Machine booted and ready!
==> centos8-2: Checking for guest additions in VM...
centos8-2: No guest additions were detected on the base box for this VM! Guest
centos8-2: additions are required for forwarded ports, shared folders, host only
centos8-2: networking, and more. If SSH fails on this machine, please install
centos8-2: the guest additions and repackage the box to continue.
centos8-2:
centos8-2: This is not an error message; everything may continue to work properly,
centos8-2: in which case you may ignore this message.
==> centos8-2: Setting hostname...
==> centos8-2: Configuring and enabling network interfaces...
==> centos8-2: Rsyncing folder: /Users/mvpbang/vagrants/c8-4x/ => /vagrant
==> centos8-3: Importing base box 'centos8'...
==> centos8-3: Matching MAC address for NAT networking...
==> centos8-3: Setting the name of the VM: centos8-3
==> centos8-3: Fixed port collision for 22 => 2222. Now on port 2201.
==> centos8-3: Clearing any previously set network interfaces...
==> centos8-3: Preparing network interfaces based on configuration...
centos8-3: Adapter 1: nat
centos8-3: Adapter 2: hostonly
==> centos8-3: Forwarding ports...
centos8-3: 22 (guest) => 2201 (host) (adapter 1)
==> centos8-3: Running 'pre-boot' VM customizations...
==> centos8-3: Booting VM...
==> centos8-3: Waiting for machine to boot. This may take a few minutes...
centos8-3: SSH address: 127.0.0.1:2201
centos8-3: SSH username: vagrant
centos8-3: SSH auth method: private key
centos8-3:
centos8-3: Vagrant insecure key detected. Vagrant will automatically replace
centos8-3: this with a newly generated keypair for better security.
centos8-3:
centos8-3: Inserting generated public key within guest...
centos8-3: Removing insecure key from the guest if it's present...
centos8-3: Key inserted! Disconnecting and reconnecting using new SSH key...
==> centos8-3: Machine booted and ready!
==> centos8-3: Checking for guest additions in VM...
centos8-3: No guest additions were detected on the base box for this VM! Guest
centos8-3: additions are required for forwarded ports, shared folders, host only
centos8-3: networking, and more. If SSH fails on this machine, please install
centos8-3: the guest additions and repackage the box to continue.
centos8-3:
centos8-3: This is not an error message; everything may continue to work properly,
centos8-3: in which case you may ignore this message.
==> centos8-3: Setting hostname...
==> centos8-3: Configuring and enabling network interfaces...
==> centos8-3: Rsyncing folder: /Users/mvpbang/vagrants/c8-4x/ => /vagrant