How to install and configure Grafana OSS in Debian 11

In this guide, we are going to learn how to install and set up Grafana OSS in Debian 11.

Grafana is a multi-platform open source analytics and interactive visualization web application. It provides charts, graphs, and alerts for the web when connected to supported data sources.

Table of Content

  1. Esuring the server is up to date
  2. Installing Grafana OSS in Debian 11
  3. Starting and enabling Grafana Service
  4. Open Grafana Service port on Firewall
  5. Optional: Configure Nginx to proxy traffic to Grafana

1. Esuring the server is up to date

Before proceeding let us ensure that our server packages are updated. Use this command to achieve this

sudo apt update
sudo apt -y upgrade

Let us also ensure that some dependant packages are installed

sudo apt install -y wget gnupg2 vim

2. Installing Grafana Grafana OSS in Debian 11

Grafana is not available in the default Debian 11 repos. To add the Grafana OSS Repo, We will install some dependencies, install gpg then add the repository and install grafana.

First install some dependencies and add gpg key

sudo apt install -y apt-transport-https
sudo apt install -y software-properties-common wget
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -

Then add this repository for stable releases:

echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list

Finally update repos and install grafana

sudo apt update
sudo apt install -y grafana

Once the installation is installed, confirm it with this command:

$ apt-cache policy grafana
grafana:
  Installed: 8.3.0
  Candidate: 8.3.0
  Version table:

Grafana OSS is now installed in the system.

3. Starting and enabling the Grafana Service

Once the installation is done, we need to start the service. In Debian 11 systems, the service is not started by default. Start it using this command:

sudo systemctl start grafana-server

Confirm that the service was started successfully using this command:

$ sudo systemctl status grafana-server
● grafana-server.service - Grafana instance
     Loaded: loaded (/lib/systemd/system/grafana-server.service; disabled; vendor preset: enabled)
     Active: active (running) since Mon 2021-12-06 18:57:04 UTC; 1min 22s ago
       Docs: http://docs.grafana.org
   Main PID: 21938 (grafana-server)
      Tasks: 8 (limit: 4626)
     Memory: 38.2M
        CPU: 777ms
     CGroup: /system.slice/grafana-server.service
             └─21938 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile=/run/grafana/grafana-server.pid --packaging=deb cfg:default.paths.logs=/var/log/grafana cfg:default.paths.data=/var/lib/grafana c>

Dec 06 18:57:06 ip-10-2-40-122 grafana-server[21938]: t=2021-12-06T18:57:06+0000 lvl=info msg="migrations completed" logger=migrator performed=381 skipped=0 duration=2.462612478s
Dec 06 18:57:06 ip-10-2-40-122 grafana-server[21938]: t=2021-12-06T18:57:06+0000 lvl=info msg="Created default admin" logger=sqlstore user=admin
Dec 06 18:57:06 ip-10-2-40-122 grafana-server[21938]: t=2021-12-06T18:57:06+0000 lvl=info msg="Created default organization" logger=sqlstore
Dec 06 18:57:06 ip-10-2-40-122 grafana-server[21938]: t=2021-12-06T18:57:06+0000 lvl=info msg="Initialising plugins" logger=plugin.manager
Dec 06 18:57:06 ip-10-2-40-122 grafana-server[21938]: t=2021-12-06T18:57:06+0000 lvl=info msg="Plugin registered" logger=plugin.manager pluginId=input
Dec 06 18:57:06 ip-10-2-40-122 grafana-server[21938]: t=2021-12-06T18:57:06+0000 lvl=info msg="Live Push Gateway initialization" logger=live.push_http
Dec 06 18:57:06 ip-10-2-40-122 grafana-server[21938]: t=2021-12-06T18:57:06+0000 lvl=info msg="Writing PID file" logger=server path=/run/grafana/grafana-server.pid pid=21938
Dec 06 18:57:06 ip-10-2-40-122 grafana-server[21938]: t=2021-12-06T18:57:06+0000 lvl=info msg="HTTP Server Listen" logger=http.server address=[::]:3000 protocol=http subUrl= socket=
Dec 06 18:57:06 ip-10-2-40-122 grafana-server[21938]: t=2021-12-06T18:57:06+0000 lvl=info msg="warming cache for startup" logger=ngalert
Dec 06 18:57:06 ip-10-2-40-122 grafana-server[21938]: t=2021-12-06T18:57:06+0000 lvl=info msg="starting MultiOrg Alertmanager" logger=ngalert.multiorg.alertmanager

The Active: active (running) in the output confirms that the service was started successfully.

To enable the service to start on boot, use this command:

sudo systemctl enable grafana-server

4. Accessing the service using IP and port

Once the service starts and the port is opened, we can access the service on the server ip port 3000. If Grafana is installed on a local system, use the address http://127.0.0.1:3000 otherwise use the server public ip instead of 127.0.0.1, i.e. http://[server_ip]:3000.

Once you access the URL you should see the Grafana login page.

Citizix - Grafana login page

Citizix – Grafana login page

The initial username and password is admin and admin. You will be asked to change the password the first time you access Grafana.

5. Optional: Configure Nginx to proxy traffic to Grafana Service

To configure Nginx, we first need to install it. For Nginx to work, we need a registered domain with its record mapped to the Server IP.

Install Nginx using this command:

sudo apt install -y nginx

Then add nginx proxy. Open the nginx conf file where the config will exist using this command:

sudo vim /etc/nginx/conf.d/grafana.conf

Then add this content:

server {
    listen 80;
    server_name grafana.citizix.com;

    proxy_set_header X-Real-IP $remote_addr;

    location / {
        proxy_redirect     off;
        proxy_set_header   Host $host;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Host $server_name;
        proxy_pass http://127.0.0.1:3000;
    }
}

Confirm that the nginx configuration we added is valid using this command:

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

We can now start and enable nginx service

sudo systemctl start nginx
sudo systemctl enable nginx

You can now access the service in the url you set up in your nginx script – http://grafana.citizix.com in my case.

Conclusion

We managed to install and configured Grafana OSS in this guide. We went an extra step of adding nginx to proxy request to our service.

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy