Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |node|
# 主机数量
(2..6).each do |index|
node.vm.define "node#{index}" do |config|
# box config
config.vm.box = "centos7.6.1810"
config.vm.box_check_update = false
config.vm.post_up_message = "Hello, welcome to server power by vagrant."
# network config
config.vm.network "forwarded_port", guest: 80, host: "1707#{index}", host_ip: "0.0.0.0"
config.vm.network "private_network", ip: "10.10.10.2#{index}"
# file sync
config.vm.synced_folder "/root/yang-dev", "/root/deploy"
config.vm.hostname = "node#{index}"
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
vb.gui = false
# cpu
vb.cpus = 4
# Customize the amount of memory on the VM:
vb.memory = 8192
vb.customize ["storagectl", :id, "--name", "SATA Controller", "--add", "sata", "--controller", "IntelAHCI"]
# 磁盘
(1..3).each do |disk|
file_to_disk = "/disk#{index}/box/vd#{disk}.vdi"
unless File.exist?(file_to_disk)
vb.customize ["createhd", "--filename", file_to_disk, "--size", 1000 * 1024, "--format", "VDI"]
end
# 如果有多个盘,--port 使用不同只
vb.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", "#{disk}", "--device", 0, "--type", "hdd", "--medium", file_to_disk]
end
end
config.vm.provision "shell", inline: <<-SHELL
echo "hello vagrent."
echo "$(id)"
SHELL
end
end
end