Setup Grafana lab on Ubuntu with Vagrant and Virtualbox

Grafana is a multi-platform open source solution for running data analytics, pulling up metrics that make sense of the massive amount of data, and monitoring apps through customization dashboards.

Ubuntu is a free and open-source Linux distribution based on Debian. Ubuntu is officially released in three editions: Desktop, Server, and Core for the internet of things devices and robots. All the editions can run on the computer alone, or in a virtual machine.

Vagrant is an open-source software product for building and maintaining portable virtual software development environments; e.g., for VirtualBox, KVM, Hyper-V, Docker containers, VMware, and AWS.

Oracle VM VirtualBox is a free and open-source hosted hypervisor for x86 virtualization, developed by Oracle Corporation. Created by Innotek, it was acquired by Sun Microsystems in 2008, which was in turn acquired by Oracle in 2010. VirtualBox can be installed on Windows, macOS, Linux, Solaris and OpenSolaris.

Step 1: Install VirtualBox by downloading the 6.X builds (latest as of today) for your platform. I recommend to install Oracle VM VirtualBox Extension Pack after installing VirtualBox.

Step 2: Install Vagrant by downloading the 2.x.x version (latest as of today) for your platform. Post installation, if you have multiple partitions in your PC, use the largest partition to run the vagrant boxes.

Step 3: Install Ubuntu by copying “Vagrantfile” for the version Ubuntu Focal Fossa here below. I’ve modified the original version by adding private network and public network. You need to replace the name of the Wi-Fi or the Network Interface Card. This change is made to allocate static IP and easier way to access the Grafana lab setup from the host or any other virtual machines running on your computer. Please save the file as Vagrantfile (without any extension) inside a difrectory/folder called grafana in the largest partition.

Vagrant.configure("2") do |config| = "ubuntu/focal64" "private_network", ip: "" "public_network", type: "dhcp", bridge: "Intel(R) Dual Band Wireless-AC 8265" 

Step 4: Change directory to grafana and run the command “vagrant up”. Wait for the command completion also notice any errors occured during the build of ubuntu box. If no errors then proceed to next step.

Step 4a: By default ubuntu box memory size is 1 GB. Add 3 GB so the total memory becomes 4 GB.

Step 5: Run the command “vagrant ssh” to login to the ubuntu box. Install the minimal ubuntu GUI by running the below commands. Follow the onscreen instructions if any comes up. Since I’ve already passed “-y” option to install silently.

sudo apt update -y && sudo apt upgrade -y && sudo apt install tasksel && sudo apt install ubuntu-desktop-minimal

sudo reboot {restarts ubuntu box. Login again by running the vagrant up command}

Step 5: There are two versions of Grafana 1 – Enterprise Edition 2 – OSS. Run the below commands to install grafana OSS version in the same sequence. For more info please visit grafana documentation page here

sudo apt-get install -y apt-transport-https
sudo apt-get install -y software-properties-common wget
wget -q -O - | sudo apt-key add -

# Alternatively you can add the beta repository, see in the table above
sudo add-apt-repository "deb stable main"

sudo apt-get update
sudo apt-get install grafana

After the successful installation we can launch grafana within the ubuntu box or from the host computer by entering the default port i.e. 3000

Step 6: Install MySQL Database Server and create database for grafana by following the below commands

vagrant@ubuntu-focal:/vagrant$ sudo apt install mysql-server

vagrant@ubuntu-focal:/vagrant$ sudo mysql_secure_installation {Follow the prompts and provide MySQL DB password}

vagrant@ubuntu-focal:/vagrant$ sudo systemctl status mysql
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2020-05-20 10:54:16 UTC; 11min ago
   Main PID: 7814 (mysqld)
     Status: "Server is operational"
      Tasks: 40 (limit: 4677)
     Memory: 327.7M
     CGroup: /system.slice/mysql.service
             └─7814 /usr/sbin/mysqld
May 20 10:54:16 ubuntu-focal systemd[1]: Starting MySQL Community Server...
May 20 10:54:16 ubuntu-focal systemd[1]: Started MySQL Community Server.

vagrant@ubuntu-focal:/vagrant$ sudo mysqladmin create grafdb {Create a new DB for grafana}

vagrant@ubuntu-focal:/vagrant$ sudo mysql
mysql> create user 'grafana'@'%' identified by 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> grant select on grafanadb.* to 'grafana'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
mysql> quit;
{Create grafana user and grant select access}

Step 7: Import Mysql Simmple Dashboard and data collectors by following the instructions provided in the below link

After setting up the simple dashboard, it should look like below screenshot.

Hope you’ve followed all the steps and able to configure Grafana lab environment successfully.

If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Twitter or Facebook. Thank you!

What am I missing here? Let me know in the comments and I’ll add it in!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s