How to Install InfluxDB and Grafana with Docker Compose and Let’s Encrypt on Ubuntu
Introduction
In this guide, I’ll show you how to install InfluxDB and Grafana on an Ubuntu server using Docker Compose and set up HTTPS with Let’s Encrypt. Docker Compose simplifies managing multiple Docker containers with a single configuration file (docker-compose.yml). This file defines how containers interact, including their networks and storage. With Docker Compose, you can easily set up, manage, and scale complex applications with a single command (docker-compose up).
What is InfluxDB?
InfluxDB is a powerful time-series database designed for storing and analyzing time-based data, such as temperature readings or system performance metrics. It’s user-friendly, flexible, and integrates well with various data visualization and collection tools. InfluxDB is ideal for system monitoring, IoT projects, and handling large amounts of time-series data.
What is Grafana?
Grafana is an open-source platform for visualizing and analyzing metrics data, such as those stored in InfluxDB. It offers beautiful, customizable dashboards for monitoring and analyzing data. Grafana works seamlessly with InfluxDB, allowing you to create rich, interactive visualizations easily.
Steps to Install InfluxDB, Grafana, and Let’s Encrypt with Docker Compose
Step 1: Open Terminal with Administrative Privileges
Open the Terminal application. To execute commands with administrative privileges, type:
sudo -i
Step 2: Update Ubuntu and Install Docker and Docker Compose
Run the following commands to update your system’s package index, upgrade installed packages, and install Docker and Docker Compose:
apt-get update apt-get upgrade apt-get install docker.io apt install docker-compose
Step 3: Install Certbot for Let’s Encrypt
Install Certbot, a tool for automatically obtaining and renewing Let’s Encrypt certificates:
apt-get install certbot apt-get install python3-certbot-dns-cloudflare # For Cloudflare DNS validation, if you use Cloudflare
Step 4: Create a Docker Compose Configuration File
Create a docker-compose.yml file using a text editor like nano:
nano docker-compose.yml
Step 5: Add Configuration to the Docker Compose File
Copy and paste the following configuration into the docker-compose.yml file:
version: '3'
services:
influxdb:
image: influxdb:latest
container_name: influxdb
volumes:
- influxdb-storage:/var/lib/influxdb
ports:
- '8086:8086'
chronograf:
image: chronograf:latest
container_name: chronograf
ports:
- '8888:8888'
volumes:
- chronograf-storage:/var/lib/chronograf
depends_on:
- influxdb
environment:
- INFLUXDB_URL=http://influxdb:8086
- INFLUXDB_ADMIN_USER=admin
- INFLUXDB_ADMIN_PASSWORD=admin
grafana:
image: grafana/grafana:latest
container_name: grafana
ports:
- '3000:3000'
volumes:
- grafana-storage:/var/lib/grafana
depends_on:
- influxdb
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=admin
nginx:
image: nginx:latest
container_name: nginx
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf- /etc/letsencrypt:/etc/letsencrypt
- /var/lib/letsencrypt:/var/lib/letsencrypt
ports:
- '80:80'
- '443:443'
depends_on:
- grafana
volumes:
influxdb-storage:
chronograf-storage:
grafana-storage:
Step 6: Configure Nginx for HTTPS
Create an Nginx configuration file (nginx.conf):
nano nginx.conf
Add the following configuration to nginx.conf:
events { }
http {
server {
listen 80;
server_name your_domain.com;
location / {
proxy_pass http://grafana:3000;
}
}
server {
listen 443 ssl;
server_name your_domain.com;
ssl_certificate
/etc/letsencrypt/live/your_domain.com/fullchain.pem;
ssl_certificate_key
/etc/letsencrypt/live/your_domain.com/privkey.pem;
location / {
proxy_pass http://grafana:3000;
}
}
}
Replace your_domain.com with your actual domain name.
Step 7: Obtain a Let’s Encrypt Certificate
Run Certbot to obtain a Let’s Encrypt certificate:
certbot certonly --standalone -d your_domain.com
If you use Cloudflare for DNS validation, the command will look like this:
certbot certonly --dns-cloudflare --dns-cloudflare-credentials /path/to/credentials.ini -d your_domain.com
For testing purposes with a self-signed certificate, use:
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/letsencrypt/live/your_domain.com/privkey.pem -out /etc/letsencrypt/live/your_domain.com/fullchain.pem -subj "/CN=your_domain.com"
Step 8: Start Docker Compose
Save and close all files. Then run the following command to start the services defined in
the docker-compose.yml file:
docker-compose up -d
Step 9: Access InfluxDB, Chronograf, and Grafana
If everything is set up correctly, you can access the web interfaces of the applications
at the following URLs:
• InfluxDB: http://localhost:8086
• Chronograf: http://localhost:8888
• Grafana: https://your_domain.com
The login credentials for Grafana are specified in the environment variables in the
Docker Compose file:
• Username: admin
• Password: admin
Conclusion
Congratulations! You have successfully installed and configured InfluxDB, Grafana, and Nginx with Docker Compose on your Ubuntu server and set up HTTPS with Let’s Encrypt. You can now log in to the web interfaces and start using InfluxDB, Chronograf, and Grafana for your time-series data and visualization needs.
Next Steps
Next, you can start configuring your dashboards in Grafana and adding data sourcesand graphs. Grafana offers a rich set of plugins and capabilities to take your monitoring and data visualization to the next level. Also, don’t forget to set up a cron job for automatically renewing your Let’s Encrypt certificate:
echo "0 0 * * * certbot renew --quiet" | crontab -
This guide provides a clear, step-by-step explanation for installing InfluxDB, Grafana, and setting up HTTPS with Let’s Encrypt on an Ubuntu server.
Leave a Reply
Want to join the discussion?Feel free to contribute!