Skip to content

Set Up Grafana on a Linux Server – Dashboards and Monitoring in Your Browser

Set up Grafana on your Linux server: use a One-Click App with HTTPS or install it manually with Docker Compose. Connect a data source such as Prometheus and import dashboards.

27 November 202611 min read2 Views0 helpful

Introduction

Grafana is an open-source interface for dashboards and analytics. Grafana does not store metrics itself; instead, it retrieves them from data sources such as Prometheus, InfluxDB, MySQL, or PostgreSQL and displays them as charts, tables, and metrics. It also includes alerts that notify you when a value exceeds a threshold. In this guide, we’ll show you two ways to get started: the easy way, using a One-Click App that makes Grafana available over HTTPS in just a few clicks, and the manual installation of Grafana OSS with Docker Compose. Then you’ll connect your first data source and import a ready-made dashboard.

When Grafana Makes Sense on a VPS

Running your own Grafana server is especially useful if you want to see data from multiple sources in one place. Grafana is a good fit on a VPS if:

  • You want to monitor servers and services, such as CPU, RAM, disk space, or response times, collected by Prometheus.
  • You want to analyze data from a database, such as orders, players, or metrics from MySQL or PostgreSQL, without writing your own analytics software.
  • You want dashboards to be available around the clock, so you and your team can open them in a browser from anywhere.
  • You need alerts that notify you before an issue becomes noticeable.

Grafana is less suitable if you aren’t collecting any data yet. Grafana only displays what a data source provides. So first plan where your metrics will come from, for example, a Prometheus server.

SQLite or PostgreSQL?

Grafana is available in two versions in the app catalog. The difference is the database where Grafana stores its own data: users, dashboards, data sources, and alert rules. In both cases, your metrics are stored in the data source, not in this database.

GrafanaGrafana with PostgreSQL
DatabaseSQLite file in Grafana’s data volumeSeparate PostgreSQL container
Containers12
Automatically generated valuesAdmin passwordAdmin password, database username and password
Suitable forIndividual users and small teamsMultiple users, many dashboards, production use

The official Grafana documentation lists SQLite as the default, but recommends MySQL or PostgreSQL for production use. The Grafana version is enough to get started and run a few dashboards. If you plan to use Grafana long-term with multiple people, choose Grafana with PostgreSQL from the start, since switching databases later is complicated.

The Easy Way: Grafana as a One-Click App

The fastest way to get Grafana is through the One-Click Apps on your VPS. The app installs Grafana OSS, makes it available over HTTPS directly through a domain, and creates an administrator account with a secure, automatically generated password on first startup. You don’t need a reverse proxy, certificate, or firewall rules.

Requirements

  • A Linux VPS (Debian or Ubuntu) with One-Click Apps set up. See Set up One-Click Apps for instructions.
  • A data source Grafana can reach, such as Prometheus. Prometheus is also available as a One-Click App in the app catalog.

Install

  1. Open your VPS in the ZapX dashboard and go to the One-Click Apps tab.
  2. Search the app catalog for Grafana, choose the right version, and click Install app.
  3. Use a custom subdomain or zap.cloud is already selected, with a random name. Leave this option enabled or enter your own name: you’ll use the domain to access Grafana over HTTPS.
  4. You don’t need to enter anything under App configuration. The admin password (SERVICE_PASSWORD_GRAFANA) is generated automatically. With Grafana with PostgreSQL, the database username and password are also generated. You can leave the database name POSTGRES_DB (default grafana) as is.
  5. Click Queue installation. After one or two minutes, Grafana will show as online on the app card.

First Login

Grafana uses the username admin to log you in. You can find the password in the app settings (gear icon), under App environment > Automatically generated values, in the SERVICE_PASSWORD_GRAFANA entry. Click the eye icon to show it, or the icon next to it to copy it.

  1. Open the app’s Access link. Grafana displays the “Welcome to Grafana” page.
  2. Enter admin under Email or username and paste the copied password under Password.
  3. Click Log in. You’ll go straight to the Grafana home page.
Info

Change your password You can change your password in Grafana by clicking your profile picture in the top right and going to Profile > Change password. Grafana only uses the password from the app environment on its very first startup. If you change it in Grafana, the value in App environment becomes outdated. Be sure to save your new password in your password manager.

Add More Users

Don’t use the admin account permanently. Go to Administration > Users and access > Users and click New user to create separate accounts. The Viewer role is enough for users who only need to view dashboards. Give the Editor role to anyone who creates dashboards. Only people who manage data sources, users, and settings need the Admin role.

Updates and Backups

You can update Grafana in the app settings (gear icon), under App update. Click Check for updates, then install a new version by clicking Apply update. If the page says the app is up to date, there isn’t a newer version in the app catalog yet.

Dashboards, data sources, and users are stored in Grafana’s data volume or, for the PostgreSQL version, in the database. Both are preserved during updates. You can also back up important dashboards as JSON: open a dashboard, click Export > Export as JSON, and download the file. You can restore a dashboard at any time using Import.

Manual Installation

The rest of this guide describes the manual installation of Grafana OSS with Docker Compose on your VPS. This is an option if, for example, you don’t use One-Click Apps on your server or want to run Grafana and Prometheus in a shared network.

Requirements

  • A Linux VPS running Debian or Ubuntu, with SSH access. See First access via SSH.
  • Docker and Docker Compose. See Install Docker. Check the installation with docker --version and docker compose version.
  • For HTTPS: a domain or subdomain whose A record points to your VPS’s IP address (e.g., grafana.example.com).

The official documentation lists 512 MB of RAM and one CPU core as the minimum for testing. For production use, it recommends at least 2 cores and 2 GB of RAM. Data sources such as Prometheus running on the same server need additional resources.

HardwareMinimumRecommended
CPU1 vCPU core2 vCPU cores
RAM512 MB2 GB

Prepare the Firewall

Grafana listens on port 3000. You don’t need to open this port if you use a reverse proxy as described below. With ufw, allow only SSH and the ports used by the reverse proxy:

Code
ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
Warning

Docker bypasses ufw Ports published by Docker with ports: are also reachable from the outside, even if ufw blocks them. Docker adds its own rules before those set by ufw. So, as in the Compose file below, bind Grafana only to 127.0.0.1. See Firewall management on Linux for more about the firewall.

Install with Docker Compose

Create a directory for Grafana and move into it:

Code
mkdir -p /opt/grafana
cd /opt/grafana

Create the Compose file with nano docker-compose.yml. It is based on the example in the official Grafana documentation:

Code
services:
  grafana:
    image: grafana/grafana:13.3.1
    container_name: grafana
    restart: unless-stopped
    environment:
      - GF_SERVER_ROOT_URL=https://grafana.example.com/
    ports:
      - 127.0.0.1:3000:3000
    volumes:
      - grafana-storage:/var/lib/grafana

volumes:
  grafana-storage: {}

Here’s what the entries mean:

  • image: The official open-source image grafana/grafana pinned to a specific version, as used by the One-Click App. The official documentation uses the grafana/grafana-enterprise image in its examples; this guide uses Grafana OSS.
  • GF_SERVER_ROOT_URL: The address where Grafana will be available. Grafana needs it for correct links, redirects, and links in alert messages. Replace grafana.example.com with your domain.
  • 127.0.0.1:3000:3000: The web interface is accessible only from the server itself; external access goes through the reverse proxy.
  • grafana-storage:/var/lib/grafana: The SQLite database grafana.db, which contains users, dashboards, and data sources, as well as installed plugins, are stored in this volume.

You can set any setting from Grafana’s configuration file as an environment variable using the pattern GF_<SECTION>_<KEY>, for example, GF_SMTP_ENABLED=true to send alert emails.

Start the container:

Code
docker compose up -d

Check whether it’s running with docker compose ps.

First Visit

Since Grafana listens only on 127.0.0.1, you’ll access the interface through an SSH tunnel the first time. Run this command on your own computer:

Code
ssh -L 3000:localhost:3000 root@SERVER_IP

Replace SERVER_IP with your VPS’s IP address and open http://localhost:3000 in your browser. Log in with the username admin and the password admin. Grafana will then prompt you to set a new password. Choose a long, unique password before making Grafana accessible through a domain.

Access via HTTPS Through a Reverse Proxy

To access Grafana without a tunnel, put a reverse proxy with a valid certificate in front of it. For the basics, see Set up a reverse proxy with nginx and Create an SSL certificate (Let's Encrypt).

Grafana uses WebSockets for live updates. The nginx server block needs to pass them through:

Code
server {
    listen 80;
    server_name grafana.example.com;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $host;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Then get the certificate with certbot --nginx -d grafana.example.com. Certbot adds HTTPS and HTTP redirection to the block. Make sure GF_SERVER_ROOT_URL in the Compose file matches this address exactly. If you change it, apply the change with docker compose up -d.

Tip

Shorter with Caddy If you use Caddy instead of nginx, the proxy obtains the certificate itself and passes WebSockets through automatically. In the Caddyfile, you only need the entry grafana.example.com { reverse_proxy 127.0.0.1:3000 }.

For more tips on securing your server, see Linux security tips.

Back Up Your Data

Everything that makes up Grafana is stored in the grafana-storage volume. The official documentation recommends stopping Grafana before copying the SQLite database. Here’s how to back up the volume:

Code
cd /opt/grafana
docker compose stop
docker run --rm -v grafana_grafana-storage:/data -v "$(pwd)":/backup alpine tar -czf /backup/grafana-backup-$(date +%F).tar.gz -C /data .
docker compose start

Docker Compose prefixes the volume with the project name, which is grafana_ in this case. You can see the exact name by running docker volume ls. Your data source metrics aren’t included, so back them up where they’re stored.

Update Grafana

Back up the volume first, then read the release notes or the upgrade guide for the new version. Then enter the new version number in docker-compose.yml and restart Grafana:

Code
cd /opt/grafana
docker compose pull
docker compose up -d

Grafana updates the database to the new version on startup. Don’t simply start an older version afterward: to downgrade, restore the backup from before the update. Remove old images with docker image prune.

Connect a Data Source and Create Your First Dashboard

Once Grafana is set up, connect it to a data source. The example below uses Prometheus to show the full process; it’s the same for other data sources, such as InfluxDB, MySQL, or PostgreSQL.

Add Prometheus as a Data Source

  1. In Grafana, go to Connections > Data sources and click Add data source.
  2. Select Prometheus.
  3. Enter your Prometheus address under Prometheus server URL:
    • If you’re using Prometheus as a One-Click App, enter the Prometheus app’s Access link, for example, https://prometheus.example.com.
    • If Grafana and Prometheus are running manually in the same Compose file, use the service name: http://prometheus:9090.
  4. Click Save & test at the bottom. If successful, Grafana displays “Successfully queried the Prometheus API.”
Tip

“no such host” error right after installation If you’ve just installed the Prometheus app, the network may not know about the new subdomain yet. Grafana will then show “no such host.” Wait a few minutes and click Save & test again.

Warning

Prometheus doesn’t have its own login Prometheus doesn’t include authentication by default. If Prometheus is accessible through a domain, anyone who knows the address can access the collected metrics. If you’re collecting sensitive data, run Grafana and Prometheus manually in a shared Docker network without publishing the Prometheus port, or put a reverse proxy with authentication in front of it.

Import a Ready-Made Dashboard

Ready-made dashboards are available for many applications in the Grafana dashboard library:

  1. Find a suitable dashboard and copy its ID.
  2. In Grafana, go to Dashboards > New > Import.
  3. Enter the ID under Grafana.com dashboard URL or ID and click Load.
  4. Select your data source in the field below and click Import.

A well-known example is Node Exporter Full (ID 1860), which shows a server’s CPU, RAM, storage, and network. It requires Prometheus to collect metrics from a Node Exporter.

Info

Panels show “N/A” or “No data” Older dashboards from the library don’t always work with current versions of Prometheus and Grafana because metric names have changed. Check the date of the last update when choosing a dashboard. Also make sure your data source is collecting the values the dashboard expects.

Build Your Own Dashboard

Under Explore, you can try out queries. With Prometheus, for example, up shows whether each target is reachable. Once a query works, create a dashboard under Dashboards > New > New dashboard, add a visualization, and save it.

Limitations

  • Grafana doesn’t collect data: Without a data source, every dashboard will be empty. You’ll need to set up Prometheus, Node Exporter, and other tools separately.
  • Alert emails require a mail server: To have Grafana send email notifications, enter your mail server details using the GF_SMTP_* settings. Alternatively, use contact points such as Discord, Slack, or webhooks.
  • Image exports require a renderer: Exporting dashboards as images or PDFs requires the additional Grafana Image Renderer, which runs as a separate service. It isn’t included with the One-Click App.

Conclusion

You’ve set up Grafana on your VPS, logged in as an administrator, connected a data source, and imported your first dashboard. From now on, you can view your server and application metrics in your browser and get alerts when problems arise.

Prefer not to work with Docker? Choose the easy One-Click App option described above under “The Easy Way: Grafana as a One-Click App.”

Free tools

Related tools for servers and developers

View all

FAQ

Frequently asked questions

The One-Click App is the fastest option: Grafana is available over HTTPS on your domain within minutes, the admin password is generated automatically, and you can install updates through the dashboard. Manual installation with Docker Compose is useful if you don’t use One-Click Apps on your server, want to manage the version yourself, or want to run Grafana and Prometheus in a shared Docker network without exposing the Prometheus port.
The username is admin. For the One-Click App, find the password in the app settings (gear icon), under App environment, in the SERVICE_PASSWORD_GRAFANA entry. With a manual installation, log in the first time using admin for both the username and password, then set a new password.
Grafana only uses the admin password from the app environment on its very first startup. If you change it in Grafana afterward, only the new password works, and the value in the app environment is outdated. Save changed passwords in your password manager.

Feedback

Was this article helpful?

Your feedback helps us prioritize and improve content.

0 of 0 people found this article helpful.

Personal support

Need more help than the guide provides?

Our ZAP-Hosting support team knows your product — briefly describe your issue and we'll help you personally.

Zappy knows this guide and answers you right in the chat.