Install VirtualBox
Install Vagrant
Install VirtualBox
https://www.virtualbox.org/wiki/Downloads -- for windows
Install Vagrant
https://releases.hashicorp.com/vagrant/ -- select the version (msi file for windows)
- Create a folder vagrant and open a command prompt
- run the command vagrant init from opened command prompt.
- A vagrant file will create in open folder.
- write a vagrant file for os.
Creating centos virtual machine.
Vagrant file - https://app.vagrantup.com/centos/boxes/8
Sample vagrant file for centos and past this line in vagrant file
VAGRANTFILE_API_VERSION = "2"Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|config.vm.box = "centos/7"config.vm.hostname = "Server01"config.ssh.insert_key = false#config.vm.provision :shell, path: "VAGRANT_ENV/bootstrap.sh"# Create a private network, which allows host-only access to the machine# using a specific IP.config.vm.network :private_network, ip: "192.168.33.10"config.vm.network "forwarded_port", guest: 80, host: 8888config.vm.network :public_network, :bridge => "eth1", :auto_config => false# Share an additional folder to the guest VM# config.vm.synced_folder ".", "/vagrant", disabled: true# config.vm.synced_folder ".", "/home/vagrant/provision", type: "rsync"config.vm.provider :virtualbox do |vb|# Set VM memory sizevb.customize ["modifyvm", :id, "--memory", "20000"]# these 2 commands massively speed up DNS resolution, which means outbound# connections don't take forever (eg the WP admin dashboard and update page)vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]endend
Multiple virtual machine from vagrant file
Vagrant.configure("2") do |config|config.ssh.insert_key = falseconfig.vm.provider :virtualbox do |vb|vb.memory = 256vb.cpus = 1end#Disabling the default /vagrant shareconfig.vm.synced_folder ".", "/vagrant", disabled: trueMACHINE = ["docker-swarm-01","docker-swarm-01","docker-swarm-01"]N = 2(0..N).each do |i|config.vm.define "server#{i}" do |node|node.vm.hostname = MACHINE[i]node.vm.box = "centos/7"node.vm.network :private_network, ip: "192.168.3.#{10+i}"endendend
and we need to run vagrant up from command prompt from vagrant file folder
And will see the operating system in Virtual box
No comments:
Post a Comment