How to Install Grafana on Linux Servers

Grafana is an open source data visualization and monitoring suite. It offers support for Graphite, Elasticsearch, Included, Prometheus, and many more databases. The tool provides a beautiful dashboard and metric analytics, with ability to manage and create your own dashboard for your apps or infrastructure performance monitoring.

In this tutorial, we will show you how to install and configure Grafana on Linux servers (Ubuntu 16.04 and CentOS 7). We'll be installing Grafana on both servers using the Grafana repository, and after the installation, we will guide you how to add and install Grafana plugins.

Prerequisites

  • Ubuntu Server 16.04 or CentOS 7.
  • Root privileges

What we will do

  1. Install Grafana on Ubuntu 16.04
  2. Install Grafana on CentOS 7
  3. Change Grafana admin password
  4. Install Grafana plugins

Step 1 - Install Grafana on Ubuntu 16.04

Grafana provides two ways for installation - using the downloaded Debian package and using the apt repository. In this tutorial, we will be using apt repository installation. So let's begin.

First up, connect to the server with your ssh login.

ssh [email protected]

Add new Grafana repository to the 'sources.list.d' directory and then add the repository gpg key using the following commands.

echo 'deb https://packagecloud.io/grafana/stable/debian/ jessie main' > /etc/apt/sources.list.d/grafana.list
curl https://packagecloud.io/gpg.key | sudo apt-key add -

Now, update repository and install Grafana using the following apt commands.

sudo apt update
sudo apt install grafana

After the installation is complete, you will get the result as shown below.

As you might know, Ubuntu 16.04 uses systemd as the init system. So, after the Grafana installation we need to reload systemd manager configuration, in order to start Grafana service.

systemctl daemon-reload

Start Grafana and enable it to run automatically at system boot everytime.

systemctl start grafana-server
systemctl enable grafana-server

By default, Grafana will run under port 3000. Check it using the netstat command and make sure that the port 3000 is on the 'LISTEN' state list.

netstat -plntu

If you have the UFW firewall installed on the server, open the ssh service port, grafana port 3000, and then start the firewall using the following commands.

ufw allow ssh
ufw allow 3000/tcp
ufw enable

Type 'y' to continue to start and add UFW to run automatically at boot time.

To see the firewall status, run the command below.

ufw status

Grafana has been installed on Ubuntu 16.04 server, and it's running under the UFW Firewall Ubuntu on port 3000.

Step 2 - Install Grafana on CentOS 7

In this step, we will show you how to install Grafana from the repository on a CentOS 7 server. We can install Grafana through the rpm package or the repository. For this guide, we will be using the Grafana repository.

Add new Grafana repository by creating a new .repo file in the 'yum.repos.d' directory. Go to the directory and create a new file dubbed 'grafana.repo' using the vim editor.

cd /etc/yum.repos.d/
vim grafana.repo

Paste the following information there.

[grafana]
name=grafana
baseurl=https://packagecloud.io/grafana/stable/el/7/$basearch
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packagecloud.io/gpg.key https://grafanarel.s3.amazonaws.com/RPM-GPG-KEY-grafana
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt

Save the change and the exit the editor.

Now install Grafana using the following yum command.

yum -y install grafana

After the installation, we need to reload the systemd manager configuration before starting the Grafana service.

Run the following systemctl command.

systemctl daemon-reload

Next, start Grafana and then enable it to run automatically everytime the system boots up.

systemctl start grafana-server
systemctl enable grafana-server

By default, Grafana is running on port 3000. In case your server is using a firewall, open the port using the firewall-cmd command as shown below.

firewall-cmd --add-port=3000/tcp --permanent
firewall-cmd --reload

Grafana installation on CentOS 7 server has been successful.

Step 3 - Change Grafana admin password

After Grafanais  installed on your server, open your web-browser and type the grafana server IP address (with port 3000) in the following way.

http://192.168.1.11:3000/

Log in to the Grafana Dashboard using default user 'admin' and password 'admin'.

You will see Grafana Dashboard as shown below.

To change the default username and password for Grafana, click on the Grafana logo on the top left and then click the 'Admin' menu, then choose the 'Global Users'.

You will see the list of users. Click on 'Edit' menu to edit the username and password.

Type your new username and password, click on the green 'Update' button to confirm.

Grafana default user and password has been changed.

Step 4 - Install plugins

In this step, we will guide you how to install Grafana plugins. There are three type of Grafana plugins we need to know:

  1. Panel plugins - These allow new data visualization to be added to Grafana.
  2. Data Source - These are Grafana Data Source plugins.
  3. App - These are bundles of panels, data source, dashboard with new UI.

For plugin installation, Grafana provides a command line tool dubbed 'grafana-cli'. Run it to see the instruction.

grafana-cli

To get a list of all available plugins in the repository, use the following command.

grafana-cli plugins list-remote

To install a plugin, use 'plugins install' option as shown below.

grafana-cli plugins install grafana-clock-panel

After the plugin installed, restart the Grafana service.

systemctl restart grafana-server

To get a list of all installed plugins on your system, use the following command.

grafana-cli plugins ls

And if you want to remove a plugin, use 'plugins remove' option as below.

grafana-cli plugins remove grafana-clock-panel

Conclusion

So, in this tutorial, we are able to install Grafana on Linux servers through both Debian and rpm packages. In the next tutorial, we will try to add the data source. For the record, Grafana supports many data sources including Influxdb, Elasticsearch, Graphite, and Prometheus.

Reference

Share this page:

5 Comment(s)