1. Download and Install the Vagrant - (https://www.vagrantup.com/downloads.html)
i. Check the vagrant installed version: vagrant -vagrant
ii. Check the OS path if you can find the vagrant command.
2. Download and Install the Oracle Virtual Box - (https://www.virtualbox.org/wiki/Downloads)
3. Create a new folder for Vagrant box instances - vagrant-boxes
4. Get the required box name from the vagrant catalog - https://app.vagrantup.com/boxes/search
5. Go to the newly created folder (vagrant-boxes) and run command to create the vagrant instance.
- vagrant init ubuntu/trusty64
i. ubuntu/trusty64 is the vagrant box available in the catalog.
ii. You get the following error:
The box 'xxxxxx' could not be found or could not be accessed in the remote catalog.
Use the following command to download the vagrant intance
- vagrant box add ubuntu/trusty64 https://app.vagrantup.com/ubuntu/boxes/trusty64
6. The vagrant will create an instance configuration file (VagranFile). Review the file and update the configuration only if you are sure what you are doing.
7. Run the command to up the vagrant instance, the command will download the instance and make it ready to use.
- vagrant up
i.e Just make sure you are on the right path/directory.
- vagrant destroy : to delete the vagrant instance
- vagrant suspend : to shutdown the vagrant instance
- vanrant resume : to started the suspended instance
- bagramt reload : to reload the instance incase of change in vm configuration.
8. The VM system specification(RAM, Processor, Hard drive) can be updated in vagrantfile (the configuration file which created in step#5)
#Provider Settings
config.vm.provider "virtualbox" do |vb|
vb.memory = 2048
vm.cpus = 4
end
- vagrant reload
The specification can be updated through the oracle box. ??!! (Need to verify)
9. SSH the box through vagrant command and continue with setuping other apps (apache, mysql, etc) on box.
- vagrant ssh
10. Enable the network settings in vagrantfile (the configuration file which created in step#5)
#Network Settings
config.vm.network "forwarded_port", guest: 80, host: 8080
#If wanted to use private network ip then above statment must be commited
config.vm.network "private_network", ip: "192.168.10.10"
- vagrant reload
11. Add hostname/domain name on the local environment, it's completely based on OS like in Linux: \etc\hosts
192.168.10.10 mybox.local www.mybox.local
12. Setup share folder in vagrantfile (the configuration file which created in step#5)
#Folder Settings
config.vm.synced_folder ".", "/vagrant_data", mount_options =>["dmode=777","fmode=666"]
# . is a current folder of host OS and it can be different path like /home/isyed/Downloads
# "/vagrant_data" is destination folder and it can also be any file path in gest os.
# mount_options =>["dmode=777","fmode=666"] are the permission on the folder to make it more secure
# Check NFS with Vagrant to increase the performance for network shared folders - :nfs => { :mount_options =>["dmode=777","fmode=666"]}
config.vm.synced_folder ".", "/vagrant_data", :nfs => { :mount_options =>["dmode=777","fmode=666"]}
- vagrant reload
13. Setup a provision Settings : You can add the list of command which is going to be executed by vagrant once the instance is recreated.
#Provision Settings
config.vm.provision "shell", inline: <<-SHELL
apt-get update
apt-get install -y apache2
SHELL
The provision command can be stored in different provision file, to do so update the provision settings:
#Provision Settings
config.vm.provision "shell", path:"bootstrap.sh"
Add new file bootstrap.sh file and add the all the commands which you need to execute after the instance is up.
Vagrantfile
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
# config.vm.box_check_update = false
# config.vm.network "forwarded_port", guest: 80, host: 8080
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
# config.vm.network "private_network", ip: "192.168.0.8"
# config.vm.network "public_network"
# config.vm.synced_folder "../data", "/vagrant_data"
# config.vm.hostname = "vlamp"
# config.ssh.username = "vlamp"
# config.vm.network "public_network", bridge:"en0: Wi-Fi (AirPort)", ip: "192.168.0.120”
config.vm.network "public_network", :bridge => "eth0", ip: "192.168.0.180", :netmask => "255.255.255.128", auto_config: false
# config.vm.network "public_network", use_dhcp_assigned_default_route: true
# Attempt to 'guess' the default network
# config.vm.network :public_network, :bridge => 'en0: Wi-Fi (AirPort)'
config.vm.provider "virtualbox" do |vb|
# Set Instance Name
vb.name = "vlamp"
# Display the VirtualBox GUI when booting the machine
vb.gui = false
# Customize the amount of memory on the VM:
vb.memory = "1024"
end
config.vm.provision "shell", inline: <<-SHELL
apt-get update
#apt-get install -y apache2
SHELL
end
--------------------------------------------------------------------------------------------------------------------------
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
# config.vm.box_check_update = false
# config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "private_network", ip: "192.168.10.10"
# config.vm.network "public_network"
config.vm.synced_folder ".", "/vagrant", type: "virtualbox"
config.vm.provider "virtualbox" do |vb|
vb.gui = false
vb.name = "coremedia9"
vb.cpus = 4
vb.memory = "1024"
end
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
# config.vm.provision "shell", inline: <<-SHELL
# apt-get update
# apt-get install -y apache2
# SHELL
end
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
# config.vm.box_check_update = false
# config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "private_network", ip: "192.168.10.10"
# config.vm.network "public_network"
config.vm.synced_folder ".", "/vagrant", type: "virtualbox"
config.vm.provider "virtualbox" do |vb|
vb.gui = false
vb.name = "coremedia9"
vb.cpus = 4
vb.memory = "1024"
end
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
# config.vm.provision "shell", inline: <<-SHELL
# apt-get update
# apt-get install -y apache2
# SHELL
end
--------------------------------------------------------------------------------------------------------------------------
No comments:
Post a Comment