Vagrant centos box example

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/", destination: "~/.ssh/authorized_keys"

To configure a vagrant box in Vagrantfiles

For centos 6 or Centos 7 = “centos/6” = “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 "forwarded_port", guest: 80, host: 8888 :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/"

Vagrant centos box example in a vagrantfile file

 Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| = "centos/6"
 config.vm.hostname = "Server01"
 config.ssh.insert_key = false
 config.vm.provision :shell, path: "VAGRANT_ENV/"
 # Create a private network, which allows host-only access to the machine
 # using a specific IP.
 # :private_network, ip: "" "forwarded_port", guest: 80, host: 8888 :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"]

To run vagrant up a Virtual Machine, to starts guest VM

[huupv@huupv example01]$ vagrant up


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!

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

1 thought on “Vagrant centos box example

  1. 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 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.