Deployment Overview of Grafana on Server¶
Prerequisites and Basic Requirements¶
The deployment requires a Linux server running either Debian/Ubuntu or RHEL-based distributions. The following network ports must be open and accessible through the server's firewall:
- Port
80/tcpfor HTTP traffic. - Port
443/tcpfor HTTPS traffic. - Port
3000/tcpfor internal Grafana communication (exposed via Docker).
Administrative privileges (root or sudo) are required to manage Docker services, configure the firewall, and modify system files.
File and Directory Structure¶
The application utilizes the following directory structure on the host system:
/root/grafana: The primary working directory containing the Docker Compose configuration file (compose.yml)./data/nginx/user_conf.d: Stores custom Nginx configuration files for the reverse proxy./data/nginx/nginx-certbot.env: Environment file containing configuration for the Nginx-Certbot service./data/grafana/datasources: Directory mounted to the Grafana container for provisioning data sources./etc/letsencrypt: Directory mounted to the Nginx container for storing SSL certificates managed by Certbot.
Application Installation Process¶
The application is deployed using Docker Compose. The installation process involves the following steps:
- Ensure Docker is installed and running on the server.
- Create the necessary Docker volumes:
nginx_secrets: An external volume for SSL certificates.grafana-data: An external volume for persistent Grafana data.
- Place the
compose.ymlfile in the/root/grafanadirectory. - Execute the Docker Compose command to start the services.
The deployment utilizes the following container images: - jonasal/nginx-certbot:latest for the reverse proxy and SSL management. - grafana/grafana-oss:<version> for the Grafana application, where <version> is defined by the hk_grafana_ver variable.
Access Rights and Security¶
Firewall rules are configured to allow incoming traffic on ports 80 and 443. The configuration differs based on the operating system:
- Debian/Ubuntu: The
ufwfirewall is used to enable ports80/tcpand443/tcp. - RHEL: The
firewalldservice is used to enable ports80/tcpand443/tcpin thepubliczone.
The Grafana service is not directly exposed to the public internet; instead, traffic is routed through the Nginx reverse proxy which handles SSL termination.
Docker Containers and Their Deployment¶
The deployment consists of two main services defined in the compose.yml file:
-
nginx:
- Image:
jonasal/nginx-certbot:latest - Ports: Maps host ports
80and443to container ports80and443. - Volumes: Mounts
nginx_secretsto/etc/letsencryptand/data/nginx/user_conf.dto/etc/nginx/user_conf.d. - Environment: Uses
[email protected]and loads additional settings from/data/nginx/nginx-certbot.env. - Restart Policy:
unless-stopped.
- Image:
-
grafana:
- Image:
grafana/grafana-oss:<version> - Ports: Maps host port
3000to container port3000. - Volumes: Mounts
/data/grafana/datasourcesto/etc/grafana/provisioning/datasourcesandgrafana-datato/var/lib/grafana. - Restart Policy:
unless-stopped.
- Image:
The services are started using the command docker compose up -d executed from the /root/grafana directory.
Proxy Servers¶
The Nginx container acts as a reverse proxy for Grafana. It handles SSL certificate generation and renewal using Certbot. The proxy configuration is stored in /data/nginx/user_conf.d and is mounted into the Nginx container. The proxy forwards incoming HTTPS traffic to the Grafana container running on port 3000.
Permission Settings¶
The directory /root/grafana is created with the following permissions: - Owner: root - Group: root - Mode: 0644
The compose.yml file within this directory is also owned by root with mode 0644. Docker volumes are managed by the Docker daemon, and file permissions within the containers are handled by the respective container images.
Starting, Stopping, and Updating¶
To manage the Grafana deployment, use the following Docker Compose commands from the /root/grafana directory:
- Start services:
- Stop services:
- Update services: To update the application, modify the
compose.ymlfile to change the image version or configuration, then run:
After the services are started, the administrator password for Grafana is reset using the grafana-cli tool inside the container. The command executed is: