TrackIt
TrackIt
Contact us
Blogs

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 :
3
4Vagrant.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 = 2
11 vb.memory = 2048
12 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 end
15end

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 :
3
4Vagrant.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 = 2
13 vb.memory = 2048
14 unless File.exist?(file_to_disk)
15 vb.customize ['createhd', '--filename', file_to_disk, '--size', 50 * 1024]
16 end
17 vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', file_to_disk]
18 end
19 end
20 end
21end

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 :
3
4Vagrant.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 = 2
13 vb.memory = 2048
14 unless File.exist?(file_to_disk)
15 vb.customize ['createhd', '--filename', file_to_disk, '--size', 50 * 1024]
16 end
17 vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', file_to_disk]
18 end
19 node.vm.provision "shell", inline: <<-SHELL
20 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.list
22 apt-get update
23 apt-get install -y rozofs-storaged
24 apt-get install -y rozofs-exportd
25 apt-get install -y rozofs-rozofsmount
26 apt-get install -y rozofs-manager-lib
27 apt-get install -y rozofs-manager-cli
28 apt-get install -y rozofs-manager-agent
29 apt-get install -y rozofs-rozodiag
30 apt-get install -y nagios-plugins-rozofs
31 apt-get install -y vim
32 mkdir -p /srv/rozofs/storages/storage_1_#{i}
33 mkfs.ext4 /dev/sdb -F
34 mount /dev/sdb /srv/rozofs/storages/storage_1_#{i}
35 /etc/init.d/rozofs-storaged restart
36 cp /vagrant/storage.conf /etc/rozofs/storage.conf
37 sed -i \'s/storage_1_1/storage_1_#{i}/\' /etc/rozofs/storage.conf
38 sed -i \'s/sid = 1/sid = #{i}/\' /etc/rozofs/storage.conf
39 /etc/init.d/rozofs-storaged restart
40 SHELL
41 end
42 end
43end

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 :
3
4Vagrant.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 = 2
13 vb.memory = 2048
14 unless File.exist?(file_to_disk)
15 vb.customize ['createhd', '--filename', file_to_disk, '--size', 50 * 1024]
16 end
17 vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', file_to_disk]
18 end
19 node.vm.provision "shell", inline: <<-SHELL
20 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.list
22 apt-get update
23 apt-get install -y rozofs-storaged
24 apt-get install -y rozofs-exportd
25 apt-get install -y rozofs-rozofsmount
26 apt-get install -y rozofs-manager-lib
27 apt-get install -y rozofs-manager-cli
28 apt-get install -y rozofs-manager-agent
29 apt-get install -y rozofs-rozodiag
30 apt-get install -y nagios-plugins-rozofs
31 apt-get install -y vim
32 mkdir -p /srv/rozofs/storages/storage_1_#{i}
33 mkfs.ext4 /dev/sdb -F
34 mount /dev/sdb /srv/rozofs/storages/storage_1_#{i}
35 /etc/init.d/rozofs-storaged restart
36 cp /vagrant/storage.conf /etc/rozofs/storage.conf
37 sed -i \'s/storage_1_1/storage_1_#{i}/\' /etc/rozofs/storage.conf
38 sed -i \'s/sid = 1/sid = #{i}/\' /etc/rozofs/storage.conf
39 /etc/init.d/rozofs-storaged restart
40 SHELL
41 end
42 end
43 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 = 2
51 vb.memory = 2048
52 unless File.exist?(file_to_disk)
53 vb.customize ['createhd', '--filename', file_to_disk, '--size', 50 * 1024]
54 end
55 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 end
59 vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 2, '--device', 0, '--type', 'hdd', '--medium', file_to_disk_export]
60 end
61 rozomds.vm.provision "shell", inline: <<-SHELL
62 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.list
64 apt-get update
65 apt-get install -y rozofs-storaged
66 apt-get install -y rozofs-exportd
67 apt-get install -y rozofs-rozofsmount
68 apt-get install -y rozofs-manager-lib
69 apt-get install -y rozofs-manager-cli
70 apt-get install -y rozofs-manager-agent
71 apt-get install -y rozofs-rozodiag
72 apt-get install -y nagios-plugins-rozofs
73 apt-get install -y vim
74 mkdir -p /srv/rozofs/storages/storage_1_1
75 mkfs.ext4 /dev/sdb -F
76 mount /dev/sdb /srv/rozofs/storages/storage_1_1
77 /etc/init.d/rozofs-storaged restart
78 cp /vagrant/storage.conf /etc/rozofs/storage.conf
79 sed -i \'s/storage_1_1/storage_1_1/\' /etc/rozofs/storage.conf
80 sed -i \'s/sid = 1/sid = 1/\' /etc/rozofs/storage.conf
81 /etc/init.d/rozofs-storaged restart
82 rozo agent restart
83 rozo volume expand 10.0.42.11 10.0.42.12 10.0.42.13 10.0.42.14 -E 10.0.42.11
84 sleep 20
85 rozo export create 1 -E 10.0.42.11
86 sleep 20
87 rozo mount create -E 10.0.42.11
88 SHELL
89 end
90 config.vm.post_up_message = "
91 vagrant ssh rozomds
92 vagrant ssh rozo02
93 vagrant ssh rozo03
94 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.11
210.0.42.12:
3- STORAGED: running
4- ROZOFSMOUNT:
5 - /mnt/rozofs@10.0.42.11/export_1: mounted
610.0.42.13:
7- STORAGED: running
8- ROZOFSMOUNT:
9 - /mnt/rozofs@10.0.42.11/export_1: mounted
1010.0.42.11:
11- EXPORTD: running
12- STORAGED: running
13- ROZOFSMOUNT:
14 - /mnt/rozofs@10.0.42.11/export_1: mounted
1510.0.42.14:
16- STORAGED: running
17- 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.11
2EXPORTS:
3- EXPORT 1:
4 - vid: 1
5 - root: /srv/rozofs/exports/export_1
6 - 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.11
2EXPORTS:
3- EXPORT 1:
4 - vid: 1
5 - root: /srv/rozofs/exports/export_1
6 - md5: ''
7 - squota: ''
8 - hquota: ''
9- EXPORT 2:
10 - vid: 1
11 - root: /srv/rozofs/exports/export_2
12 - md5: ''
13 - squota: ''
14 - hquota: ''

Now we mount our export:

1root@rozomds:~# rozo mount create -e export_2 -E 10.0.42.11
210.0.42.12:
3- export export_2 (eid=2) on /mnt/rozofs@10.0.42.11/export_2:
4 configuration: added
5 status: mounted
610.0.42.13:
7- export export_2 (eid=2) on /mnt/rozofs@10.0.42.11/export_2:
8 configuration: added
9 status: mounted
1010.0.42.11:
11- export export_2 (eid=2) on /mnt/rozofs@10.0.42.11/export_2:
12 configuration: added
13 status: mounted
1410.0.42.14:
15- export export_2 (eid=2) on /mnt/rozofs@10.0.42.11/export_2:
16 configuration: added
17 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.