Deployment Overview of Grafana on Server¶
Prerequisites and Basic Requirements¶
To successfully deploy and operate Grafana on the server, the following system prerequisites must be met:
-
Operating System: Compatible with Debian/Ubuntu or RHEL/CentOS distributions.
-
Privileges: Administrative (root) access is required to manage Docker containers, configure firewalls, and handle file permissions.
-
Domain: The system must be configured to serve content on the
hostkey.indomain. -
Ports:
-
80/tcpand443/tcpmust be open on the firewall for HTTPS and HTTP traffic. -
3000/tcpis used internally for the Grafana application container.
FQDN of the Final Panel¶
The Grafana interface is accessible via the following Fully Qualified Domain Name (FQDN) format:
grafana<Server ID>.hostkey.in:443
Replace <Server ID> with the specific identifier assigned to the host instance. The application operates over HTTPS on port 443.
File and Directory Structure¶
The deployment utilizes specific directories for configuration files, application data, and certificates:
-
Application Directory:
/root/grafana -
Contains the
compose.ymlfile used for orchestrating the Docker containers. -
Nginx Configuration:
/data/nginx/user_conf.d -
Stores custom Nginx server block configurations for the Grafana domain.
-
Grafana Data Volume: Mapped to
/var/lib/grafanainside the container. -
Let's Encrypt Certificates: Stored in the
nginx_secretsvolume mounted at/etc/letsencrypt. -
Datasource Provisioning:
/data/grafana/datasourcesmounted to/etc/grafana/provisioning/datasourcesinside the container.
Application Installation Process¶
The application is deployed using Docker Compose. The installation process involves the following steps:
-
Docker Installation: Ensure the Docker engine is installed and running on the host.
-
Directory Setup: Create the
/root/grafanadirectory with root ownership. -
Compose File Generation: The
compose.ymlfile is generated and placed in/root/grafana/compose.yml. -
Volume Creation: A persistent Docker volume named
grafana-datais created to store Grafana's internal data. -
Service Launch: The containers are started using the
docker compose up -dcommand. -
Version: The deployment utilizes Grafana version
8.2.6.
Access Rights and Security¶
Security configurations are applied via the host firewall and container isolation:
-
Firewall Rules:
-
On Debian/Ubuntu systems,
ufw(Uncomplicated Firewall) is configured to allow traffic on ports80and443. -
On RHEL/CentOS systems,
firewalldis configured to allow80/tcpand443/tcpin thepubliczone. -
Container Isolation: Services run within isolated Docker containers with defined port mappings and volume mounts.
-
SSL/TLS: SSL certificates are managed automatically via the Nginx container using Certbot, ensuring encrypted communication over port
443.
Databases¶
The provided configuration does not include an external database deployment. Grafana utilizes its internal SQLite database by default, with all data stored within the grafana-data Docker volume. External data sources are provisioned via the /data/grafana/datasources directory.
Docker Containers and Their Deployment¶
The application consists of two primary services defined in the compose.yml file:
-
nginx:
-
Image:
jonasal/nginx-certbot:latest -
Function: Acts as the reverse proxy and manages SSL certificates via Certbot.
-
Ports: Exposes
80and443to the host. -
Volumes: Mounts
nginx_secretsfor certificates and/data/nginx/user_conf.dfor custom configurations. -
grafana:
-
Image:
grafana/grafana-oss:8.2.6 -
Function: Runs the Grafana monitoring and visualization application.
-
Ports: Maps internal port
3000to host port3000. -
Volumes:
-
grafana-datamapped to/var/lib/grafanafor persistent storage. -
/data/grafana/datasourcesmapped to/etc/grafana/provisioning/datasourcesfor datasource configuration.
-
The restart policy for both containers is set to unless-stopped.
Proxy Servers¶
Access to Grafana is mediated through an Nginx reverse proxy:
-
Software: Nginx with Certbot integration (
jonasal/nginx-certbot). -
SSL/TLS: Automatic SSL certificate management is enabled via Let's Encrypt.
-
Configuration: Custom proxy rules for the Grafana subdomain are located in
/data/nginx/user_conf.d/<prefix><server_id>.hostkey.in.conf. -
Routing: The proxy forwards requests from port
443to the internal Grafana service running on port3000.
Permission Settings¶
File and directory permissions are set to ensure proper access for the Docker containers and system administrators:
-
Compose Directory:
/root/grafanais owned byroot:rootwith0644permissions. -
Compose File:
compose.ymlis owned byroot:rootwith0644permissions. -
Nginx Configs: Custom configurations in
/data/nginx/user_conf.dare managed by the host system and accessed by the Nginx container via volume mount.
Location of Configuration Files and Data¶
Critical configuration and data files are located at the following paths:
| Component | Path | Description |
|---|---|---|
| Docker Compose | /root/grafana/compose.yml | Defines services, networks, and volumes. |
| Nginx Config | /data/nginx/user_conf.d/ | Contains domain-specific server blocks. |
| Grafana Storage | Docker volume grafana-data | Internal application data and plugins. |
| Datasources | /data/grafana/datasources | Provisioned datasource configurations. |
| SSL Certs | Docker volume nginx_secrets | Let's Encrypt certificate storage. |
Available Ports for Connection¶
The following ports are configured for external and internal access:
-
443 (TCP): HTTPS traffic for the Grafana web interface (external access).
-
80 (TCP): HTTP traffic used for SSL certificate validation and redirection (external access).
-
3000 (TCP): Direct internal access to the Grafana container (not intended for direct external production access without the proxy).
Starting, Stopping, and Updating¶
Service management is handled via Docker Compose commands executed from the /root/grafana directory.
-
Start Services:
-
Stop Services:
-
Restart Services:
-
Update Logs:
To update the application version, modify the image tag in the compose.yml file and restart the services.