Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Setting Up a Local Linux Development Environment with Vagrant and VirtualBox

Tech May 13 1

Download and install the required tools: Vagrant, VirtualBox, WindTerm, and a CentOS 7 Vagrant box image. Ensure all components are available locally before proceeding.

Initialize a Vagrant project by creating a dedicated directory and running the initialization command. This generates a configuration file for the virtual machine.

mkdir ~/vm_config && cd ~/vm_config
vagrant init

Edit the generated Vagrantfile to specify the box, network settings, and resource allocation. Customize the IP address, memory, and CPU cores as needed.

Vagrant.configure("2") do |config|
  config.vm.box = "centos7"
  config.vm.network "public_network", ip: "192.168.1.100"
  config.vm.provider "virtualbox" do |vb|
    vb.memory = "3072"
    vb.name = "dev_centos7"
    vb.cpus = 2
  end
end

Add the CentOS 7 box image to Vagrant and start the virtual machine. Verify the VM is running successfully.

vagrant box add centos7 ~/Downloads/CentOS-7.box
vagrant up

Access the virtual machine via SSH using Vagrant, then switch to the root user and change the default password for enhanced security.

vagrant ssh
sudo -i
passwd

Modify the SSH configuration to allow pasword authentication, then restart the SSH service to apply the changes.

sed -i 's/^PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config
systemctl restart sshd

Use WindTerm or any SSH client to connect to the VM using the configured IP address and the new root password. This enables remote management of the development environment.

For additional disk space, install the Vagrant disksize plugin and update the Vagrantfile to specify a larger disk. After modifying the configuration, reload the virtual machine to apply the disk changes.

vagrant plugin install vagrant-disksize
Vagrant.configure("2") do |config|
  config.vm.box = "centos7"
  config.disksize.size = '100GB'
  config.vm.network "public_network", ip: "192.168.1.100"
  config.vm.provider "virtualbox" do |vb|
    vb.memory = "3072"
    vb.name = "dev_centos7"
    vb.cpus = 2
  end
  config.vm.provision "shell", inline: <<-SHELL
    sleep 10
    if ! command -v growpart &> /dev/null; then
      if [ -f /etc/redhat-release ]; then
        yum install -y cloud-utils-growpart
      elif [ -f /etc/debian_version ]; then
        apt-get update
        apt-get install -y cloud-utils-growpart
      fi
    fi
    growpart /dev/sda 1
    partprobe /dev/sda
    FS_TYPE=$(lsblk -f /dev/sda1 | awk 'NR==2 {print $2}')
    case $FS_TYPE in
      ext2|ext3|ext4)
        resize2fs /dev/sda1
        ;;
      xfs)
        xfs_growfs /dev/sda1
        ;;
      *)
        echo "Unsupported file system: $FS_TYPE"
        ;;
    esac
  SHELL
end
vagrant reload

Ensure compatibility by using Vagrant version 2.3.5 or later with VirtualBox 7.0 to avoid potential issues during setup.

Tags: Vagrant

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.