In this tutorial, I’m deployed centos VM from Vagrantfiles. For example, Vagrant centos box example for Centos 6 and Centos 7. To use Vagrant, Virtualbox, and Centos. Vagrant the essential for DevOps Roles.
The first, to create Project folder as below:
$ mkdir vagrant_centos $ cd vagrant_centos $ vagrant init
To create a vagrant ssh key
[huupv@huupv example01]$ ssh-keygen
The Private key and public key in /home/huupv/project/keys/.ssh
To configure vagrant ssh key in Vagrantfiles
config.ssh.insert_key = false config.vm.boot_timeout = 800 config.ssh.private_key_path = ["keys/.ssh/vagrant_rsa", "~/.vagrant.d/insecure_private_key"] config.vm.provision "file", source: "keys/.ssh/vagrant_rsa.pub", destination: "~/.ssh/authorized_keys"
To configure a vagrant box in Vagrantfiles
For centos 6 or Centos 7
config.vm.box = “centos/6” config.vm.box = “centos/7”
Modifying Vagrant box memory and CPU settings
# Set VM memory size vb.customize ["modifyvm", :id, "--memory", "512"] # Set VM cpu size config.vm.customize ["modifyvm", :id, "--cpus", 2]
Configure Forwarded port network
config.vm.network "forwarded_port", guest: 80, host: 8888 config.vm.network :public_network, :bridge => "eth1", :auto_config => false
To set VM hostname for Guest VM
#Set VM hostname config.vm.hostname = "Server01"
To install the packages necessary for Vagrant Centos box
config.vm.provision :shell, path: "VAGRANT_ENV/bootstrap.sh"
Vagrant centos box example in a vagrantfile file
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "centos/6"
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: 8888
config.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 size
vb.customize ["modifyvm", :id, "--memory", "512"]
# 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"]
end
end
To run vagrant up a Virtual Machine, to starts guest VM
[huupv@huupv example01]$ vagrant up
Conclusion
Thought the article, you can use Vagrant centos box example as above. I hope will this your helpful.Thank you for reading the DevopsRoles page!
Thank you very much for the Vagrant centos box example!
I am not a native English speaker myself, but I can see some spelling errors.
PM me if you want me to help you in return by fixing them 🙂