How to Set up a Vagrant Dev Environment - A Step-by-Step Guide
Author
TrackIt
Date Published
Today, we are going to learn how to setup an environment with the awesome tool that any DevOps should know, Vagrant.
Behind this name is a wonderful software which automates the use of virtual machines (VMs) to create reproducible environments on-the-fly.
By creating a simple configuration file, within minutes you will have a fresh virtual machine started and provisioning without any other human interaction. The Vagrant Dev Environment!
Since Vagrant is not a pure virtualization tool by itself, it makes use of providers to do the virtualization such as VMWare, VirtualBox, etc...
And what a better way to demonstrate the power of this tool if not by setting up a distributed file system!
And this is a good thing because RozoFS is exactly what we are going to need. RozoFS is a high performance and scalable open source distributed file system.
You may take a look at what they do, it’s pretty interesting! http://rozosystems.com/
This demonstration will go as follows: first we will setup the RozoFS cluster, then we will run some rozo commands to show how it works.
In this tutorial, I will suppose that Vagrant and VirtualBox are already installed in your computer, if not here are the download links:
That being said, let’s get to the heart of the matter!
The Vagrant file
The Vagrant file will be the heart of our environment. It contains all the instructions to setup our system.
So to start, create a text file named Vagrantfile and copy paste the code below:
1# -*- mode: ruby -*-2# vi: set ft=ruby :34Vagrant.configure(2) do |config|5 file_to_disk = "./tmp/large_disk_rozo01.vdi"6 node.vm.box = "bento/ubuntu-14.04"7 node.vm.hostname = "rozo01"8 node.vm.network "private_network", ip: "10.0.42.11"9 node.vm.provider :virtualbox do |vb|10 vb.cpus = 211 vb.memory = 204812 vb.customize ['createhd', '--filename', file_to_disk, '--size', 50 * 1024]13 vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', file_to_disk]14 end15end
Basically, here we have defined all the basic stuff for a VM : Operating System, hostname, IP, disk and the provider (VirtualBox in our case).
But this will create only one VM, and it's not really what we need. Since we are building a cluster, we will need more machines, so let's modify this Vagrantfile to look more like our goal.
1# -*- mode: ruby -*-2# vi: set ft=ruby :34Vagrant.configure(2) do |config|5 (2..4).each do |i|6 file_to_disk = "./tmp/large_disk_rozo0#{i}.vdi"7 config.vm.define "rozo0#{i}" do |node|8 node.vm.box = "bento/ubuntu-14.04"9 node.vm.hostname = "rozo0#{i}"10 node.vm.network "private_network", ip: "10.0.42.1#{i}"11 node.vm.provider :virtualbox do |vb|12 vb.cpus = 213 vb.memory = 204814 unless File.exist?(file_to_disk)15 vb.customize ['createhd', '--filename', file_to_disk, '--size', 50 * 1024]16 end17 vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', file_to_disk]18 end19 end20 end21end
So now it will deploy 3 VM's with the same configuration except for the hostname and IP.
Then we will need to execute some shell commands into each VM. So for that, there is a vagrant instruction that allows us to run a shell command just after the VM creation;
node.vm.provision "shell", inline:
The shell commands that we need to run will install and configure everything for RozoFS.
Let's see now how our Vagrantfile looks.
1# -*- mode: ruby -*-2# vi: set ft=ruby :34Vagrant.configure(2) do |config|5 (2..4).each do |i|6 file_to_disk = "./tmp/large_disk_rozo0#{i}.vdi"7 config.vm.define "rozo0#{i}" do |node|8 node.vm.box = "bento/ubuntu-14.04"9 node.vm.hostname = "rozo0#{i}"10 node.vm.network "private_network", ip: "10.0.42.1#{i}"11 node.vm.provider :virtualbox do |vb|12 vb.cpus = 213 vb.memory = 204814 unless File.exist?(file_to_disk)15 vb.customize ['createhd', '--filename', file_to_disk, '--size', 50 * 1024]16 end17 vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', file_to_disk]18 end19 node.vm.provision "shell", inline: <<-SHELL20 wget -O - http://dl.rozofs.org/deb/devel@rozofs.com.gpg.key | apt-key add -21 echo deb http://dl.rozofs.org/deb/master $(lsb_release -sc) main | tee /etc/apt/sources.list.d/rozofs.list22 apt-get update23 apt-get install -y rozofs-storaged24 apt-get install -y rozofs-exportd25 apt-get install -y rozofs-rozofsmount26 apt-get install -y rozofs-manager-lib27 apt-get install -y rozofs-manager-cli28 apt-get install -y rozofs-manager-agent29 apt-get install -y rozofs-rozodiag30 apt-get install -y nagios-plugins-rozofs31 apt-get install -y vim32 mkdir -p /srv/rozofs/storages/storage_1_#{i}33 mkfs.ext4 /dev/sdb -F34 mount /dev/sdb /srv/rozofs/storages/storage_1_#{i}35 /etc/init.d/rozofs-storaged restart36 cp /vagrant/storage.conf /etc/rozofs/storage.conf37 sed -i \'s/storage_1_1/storage_1_#{i}/\' /etc/rozofs/storage.conf38 sed -i \'s/sid = 1/sid = #{i}/\' /etc/rozofs/storage.conf39 /etc/init.d/rozofs-storaged restart40 SHELL41 end42 end43end
Finally we need to declare one more VM for our master rozo node. The reason why it's not included in the first loop is because this host needs a specific shell command to run in it.
So here is the final Vagrantfile:
1# -*- mode: ruby -*-2# vi: set ft=ruby :34Vagrant.configure(2) do |config|5 (2..4).each do |i|6 file_to_disk = "./tmp/large_disk_rozo0#{i}.vdi"7 config.vm.define "rozo0#{i}" do |node|8 node.vm.box = "bento/ubuntu-14.04"9 node.vm.hostname = "rozo0#{i}"10 node.vm.network "private_network", ip: "10.0.42.1#{i}"11 node.vm.provider :virtualbox do |vb|12 vb.cpus = 213 vb.memory = 204814 unless File.exist?(file_to_disk)15 vb.customize ['createhd', '--filename', file_to_disk, '--size', 50 * 1024]16 end17 vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', file_to_disk]18 end19 node.vm.provision "shell", inline: <<-SHELL20 wget -O - http://dl.rozofs.org/deb/devel@rozofs.com.gpg.key | apt-key add -21 echo deb http://dl.rozofs.org/deb/master $(lsb_release -sc) main | tee /etc/apt/sources.list.d/rozofs.list22 apt-get update23 apt-get install -y rozofs-storaged24 apt-get install -y rozofs-exportd25 apt-get install -y rozofs-rozofsmount26 apt-get install -y rozofs-manager-lib27 apt-get install -y rozofs-manager-cli28 apt-get install -y rozofs-manager-agent29 apt-get install -y rozofs-rozodiag30 apt-get install -y nagios-plugins-rozofs31 apt-get install -y vim32 mkdir -p /srv/rozofs/storages/storage_1_#{i}33 mkfs.ext4 /dev/sdb -F34 mount /dev/sdb /srv/rozofs/storages/storage_1_#{i}35 /etc/init.d/rozofs-storaged restart36 cp /vagrant/storage.conf /etc/rozofs/storage.conf37 sed -i \'s/storage_1_1/storage_1_#{i}/\' /etc/rozofs/storage.conf38 sed -i \'s/sid = 1/sid = #{i}/\' /etc/rozofs/storage.conf39 /etc/init.d/rozofs-storaged restart40 SHELL41 end42 end43 config.vm.define "rozomds" do |rozomds|44 rozomds.vm.box = "bento/ubuntu-14.04"45 rozomds.vm.hostname = "rozomds"46 rozomds.vm.network "private_network", ip: "10.0.42.11"47 file_to_disk = "./tmp/large_disk_rozo.vdi"48 file_to_disk_export = "./tmp/export_disk.vdi"49 rozomds.vm.provider :virtualbox do |vb|50 vb.cpus = 251 vb.memory = 204852 unless File.exist?(file_to_disk)53 vb.customize ['createhd', '--filename', file_to_disk, '--size', 50 * 1024]54 end55 vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', file_to_disk]56 unless File.exist?(file_to_disk_export)57 vb.customize ['createhd', '--filename', file_to_disk_export, '--size', 50 * 1024]58 end59 vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 2, '--device', 0, '--type', 'hdd', '--medium', file_to_disk_export]60 end61 rozomds.vm.provision "shell", inline: <<-SHELL62 wget -O - http://dl.rozofs.org/deb/devel@rozofs.com.gpg.key | apt-key add -63 echo deb http://dl.rozofs.org/deb/master $(lsb_release -sc) main | tee /etc/apt/sources.list.d/rozofs.list64 apt-get update65 apt-get install -y rozofs-storaged66 apt-get install -y rozofs-exportd67 apt-get install -y rozofs-rozofsmount68 apt-get install -y rozofs-manager-lib69 apt-get install -y rozofs-manager-cli70 apt-get install -y rozofs-manager-agent71 apt-get install -y rozofs-rozodiag72 apt-get install -y nagios-plugins-rozofs73 apt-get install -y vim74 mkdir -p /srv/rozofs/storages/storage_1_175 mkfs.ext4 /dev/sdb -F76 mount /dev/sdb /srv/rozofs/storages/storage_1_177 /etc/init.d/rozofs-storaged restart78 cp /vagrant/storage.conf /etc/rozofs/storage.conf79 sed -i \'s/storage_1_1/storage_1_1/\' /etc/rozofs/storage.conf80 sed -i \'s/sid = 1/sid = 1/\' /etc/rozofs/storage.conf81 /etc/init.d/rozofs-storaged restart82 rozo agent restart83 rozo volume expand 10.0.42.11 10.0.42.12 10.0.42.13 10.0.42.14 -E 10.0.42.1184 sleep 2085 rozo export create 1 -E 10.0.42.1186 sleep 2087 rozo mount create -E 10.0.42.1188 SHELL89 end90 config.vm.post_up_message = "91 vagrant ssh rozomds92 vagrant ssh rozo0293 vagrant ssh rozo0394 vagrant ssh rozo04"95end
If you want more details on a specific command, you may check Vagrant documentation, you will surely find what you want : https://www.vagrantup.com/docs/
Now, from where the Vagrantfile is located, run the following command:
vagrant up
It will execute all the instructions of the Vagrantfile and once it finishes you will get a fresh environment with RozoFS setup in it.
So now, let's run some RozoFS commands!
Test the environment with RozoFS commands
Like many cluster architectures, there is a master server. It will be from the master server that the RozoFS commands will be run.
So to connect to this master, named rozomds (according to our Vagrantfile), run the vagrant command:
vagrant ssh rozomds
Now we are inside our Vagrant box. From there, we are going to create an export and with one command we'll mount it on our cluster.
First, let's see if we already have an export. Run the following command:
1root@rozomds:~# rozo node status -E 10.0.42.11210.0.42.12:3- STORAGED: running4- ROZOFSMOUNT:5 - /mnt/rozofs@10.0.42.11/export_1: mounted610.0.42.13:7- STORAGED: running8- ROZOFSMOUNT:9 - /mnt/rozofs@10.0.42.11/export_1: mounted1010.0.42.11:11- EXPORTD: running12- STORAGED: running13- ROZOFSMOUNT:14 - /mnt/rozofs@10.0.42.11/export_1: mounted1510.0.42.14:16- STORAGED: running17- ROZOFSMOUNT:18 - /mnt/rozofs@10.0.42.11/export_1: mounted
As you can see, we already have an export named export_1 and it's already mounted on all our vagrant hosts.
The other command to see all your exports with more details is:
1root@rozomds:~# rozo export get -E 10.0.42.112EXPORTS:3- EXPORT 1:4 - vid: 15 - root: /srv/rozofs/exports/export_16 - md5: ''7 - squota: ''8 - hquota: ''
Note that the rozo command has a very detailed manual and it could be very useful! man rozo
Now we want to create a new export. It's as simple as following:
1root@rozomds:~# rozo export create -n export_2 1 -E 10.0.42.11
Run the command again to get our exports:
1root@rozomds:~# rozo export get -E 10.0.42.112EXPORTS:3- EXPORT 1:4 - vid: 15 - root: /srv/rozofs/exports/export_16 - md5: ''7 - squota: ''8 - hquota: ''9- EXPORT 2:10 - vid: 111 - root: /srv/rozofs/exports/export_212 - md5: ''13 - squota: ''14 - hquota: ''
Now we mount our export:
1root@rozomds:~# rozo mount create -e export_2 -E 10.0.42.11210.0.42.12:3- export export_2 (eid=2) on /mnt/rozofs@10.0.42.11/export_2:4 configuration: added5 status: mounted610.0.42.13:7- export export_2 (eid=2) on /mnt/rozofs@10.0.42.11/export_2:8 configuration: added9 status: mounted1010.0.42.11:11- export export_2 (eid=2) on /mnt/rozofs@10.0.42.11/export_2:12 configuration: added13 status: mounted1410.0.42.14:15- export export_2 (eid=2) on /mnt/rozofs@10.0.42.11/export_2:16 configuration: added17 status: mounted
Our export has been successfully mounted on all our hosts.
If you want to go further with RozoFS file system, this documentation will be very helpful: https://media.readthedocs.org/pdf/rozofs/latest/rozofs.pdf
Conclusion
In this article, we have seen how to build a functional distributed file system running anywhere with the help of Vagrant. Now you can provide to all your developers this Vagrantfile and they will be able to run the embedded solution from their laptop or their development machine.
About TrackIt
https://www.youtube.com/watch?v=QBiJ156cA2I
TrackIt is an international AWS cloud consulting, systems integration, and software development firm headquartered in Marina del Rey, CA.
We have built our reputation on helping media companies architect and implement cost-effective, reliable, and scalable Media & Entertainment workflows in the cloud. These include streaming and on-demand video solutions, media asset management, and archiving, incorporating the latest AI technology to build bespoke media solutions tailored to customer requirements.
Cloud-native software development is at the foundation of what we do. We specialize in Application Modernization, Containerization, Infrastructure as Code and event-driven serverless architectures by leveraging the latest AWS services. Along with our Managed Services offerings which provide 24/7 cloud infrastructure maintenance and support, we are able to provide complete solutions for the media industry.
