Setting Up a Vagrant Centos box example: A Practical

Introduction

Explore the practical steps to set up a Vagrant CentOS box example in this detailed guide. Whether you’re working with CentOS 6 or 7, this tutorial provides clear instructions and essential tips for using Vagrant to deploy CentOS virtual machines effectively.

In this tutorial, I deployed a centos VM from Vagrantfiles. For example, the Vagrant Centos box example for Centos 6 and Centos 7. To use Vagrant, Virtualbox, and Centos.

The first is to create a 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 the 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 the Vagrant Centos box

config.vm.provision :shell, path: "VAGRANT_ENV/bootstrap.sh"

Vagrant Centos box example in a Vagrantfile.

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 start guest VM

[huupv@huupv example01]$ vagrant up
Setting Up a Vagrant Centos box example

Conclusion

This guide demystifies the process of deploying CentOS using Vagrant, making it accessible for developers and IT professionals alike. With these insights, you’re now equipped to streamline your development and testing environments efficiently.

Thought the article, you can use the 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 DevopsRoles.com 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 “Setting Up a Vagrant Centos box example: A Practical

  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.