How to Setup Grafana Instance on a Cloud Virtual Machine [Ubuntu/Debian]

Grafana-setup-vm

Grafana is a great Data-Visualisation tool which is widely used in IIOT – Industrial Internet of Things Scenarios. Grafana is also in various DevOps applications.

Here, we will learn how to deploy a Grafana Instance on Cloud Virtual Machine running Linux (Ubuntu).

Grafana-setup-vm

Steps to Install Grafana on Ubuntu Virtual Machine

Before proceeding with the steps make sure you have opened port 80 of your Virtual Machine.

Step 1 : Make sure your server is upto date.

sudo apt update
sudo apt upgrade

Step 2 : Add Grafana gpg key to install signed packages and add the repository.

curl https://packages.grafana.com/gpg.key | sudo apt-key add -
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"

Step 3 : Update the repository and install Grafana.

sudo apt update
sudo apt -y install grafana

Step 4 : Systemctl commands to control the service

sudo systemctl start grafana-server
sudo systemctl stop grafana-server
sudo systemctl restart grafana-server

// Enable it to startup on boot.
sudo systemctl enable grafana-server

// check status of Service
sudo systemctl status grafana-server

After starting the server, default username and password is admin , change your password after first login.

Grafana listen on Port 80

By default, Grafana runs on port 3000, but if you want to run the server on Port 80 it is quite simple.

Just add below IPTables rule to redirect traffic on port 80 to 3000

sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 3000
sudo iptables-save

This is the most efficient way to redirect your traffic, another way is to put a webserver like Nginx or Apache in front of Grafana and have them proxy requests to Grafana.