You can also add a box from publicly available catalog of Vagrant boxes at https://atlas.hashicorp.com/boxes/search
Modify Vagrantfile to configure CPUs, memory, network and mount shared folders. The below configuration will work for Virtualbox.
Open Git Bash
$ cd centos7-vagrant
$ vagrant init anandbitra/centos-7.1
$ vi Vagrantfile
Comment all the lines and add the below lines.
Vagrant.configure("2") do |config|
config.vm.define "webserver" do |web_config|
web_config.vm.box = "anandbitra/centos-7.1"
web_config.vm.hostname = "webserver"
web_config.vm.network "public_network", type: "dhcp"
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--usb", "off"]
vb.customize ["modifyvm", :id, "--usbehci", "off"]
vb.gui = false
vb.cpus = 1
vb.memory = 2048
end
end
config.vm.define "dbserver" do |db_config|
db_config.vm.box = "anandbitra/centos-7.1"
db_config.vm.hostname = "dbserver"
db_config.vm.network "public_network", type: "dhcp"
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--usb", "off"]
vb.customize ["modifyvm", :id, "--usbehci", "off"]
vb.gui = false
vb.cpus = 1
vb.memory = 1024
end
end
config.vm.define "master-node-01" do |db_config|
db_config.vm.box = "anandbitra/centos-7.1"
db_config.vm.hostname = "master-node-01"
# db_config.vm.network "public_network", type: "dhcp"
db_config.vm.network "private_network", ip: "192.168.1.10"
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--usb", "off"]
vb.customize ["modifyvm", :id, "--usbehci", "off"]
vb.gui = false
vb.cpus = 1
vb.memory = 1024
end
end
config.vm.define "core-node-01" do |db_config|
db_config.vm.box = "anandbitra/centos-7.1"
db_config.vm.hostname = "core-node-01"
# db_config.vm.network "public_network", type: "dhcp"
db_config.vm.network "private_network", ip: "192.168.1.11"
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--usb", "off"]
vb.customize ["modifyvm", :id, "--usbehci", "off"]
vb.gui = false
vb.cpus = 1
vb.memory = 1024
end
end
config.vm.define "core-node-02" do |db_config|
db_config.vm.box = "anandbitra/centos-7.1"
db_config.vm.hostname = "core-node-02"
# db_config.vm.network "public_network", type: "dhcp"
db_config.vm.network "private_network", ip: "192.168.1.12"
config.vm.provider "virtualbox" do |vb|
vb.gui = false
vb.cpus = 1
vb.memory = 1024
vb.customize ["modifyvm", :id, "--usb", "off"]
vb.customize ["modifyvm", :id, "--usbehci", "off"]
if !File.exists?(./data1.vdi)
vb.customize ['createhd', '--filename', data1, '--variant', 'Fixed', '--size', 10 * 1024]
end
vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', data1]
if !File.exists?(./data2.vdi)
vb.customize ['createhd', '--filename', data2, '--variant', 'Fixed', '--size', 10 * 1024]
end
vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 2, '--device', 0, '--type', 'hdd', '--medium', data2]
end
end
end
Start all the VMs
$ vagrant up
Shutdown all the VMs
$ vagrant halt
Show information about Vagrant environments.
$ vagrant global-status
Start specific VM
$ vagrant up <
Shudown specific VM
$ vagrant halt <name>
Login to specific VM
$ vagrant ssh <name>
Destroy VM
$ vagrant destroy <id>