Aug 20, 2024 3 min read

Redash: Self-Hosting Made Simple

Redash: Self-Hosting Made Simple
Table of Contents

Redash is an open-source platform designed for data visualization and analytics, making it an excellent tool for developers and organizations that need full control over their data. With support for multiple database integrations, customizable visualizations, and robust query capabilities, Redash empowers teams to share insights efficiently. In this guide, we will walk you through deploying, configuring, and managing a self-hosted Redash instance, enabling you to maximize its potential.

Installing Redash

Let’s begin by installing Redash. This section covers two popular methods: Docker Compose and manual installation.

πŸ“¦ Docker/Docker Compose Setup

Docker Compose simplifies Redash deployment by containerizing its services. Here’s a step-by-step guide:

  1. Create and navigate to the Redash directory:

mkdir redash && cd redash

  1. Generate a docker-compose.yml file with the following content:

version: "3.7"

services:

server:

image: redash/redash:latest

container_name: redash_server

ports:

- "5000:5000"

environment:

REDASH_LOG_LEVEL: "INFO"

REDASH_REDIS_URL: "redis://redis:6379/0"

REDASH_DATABASE_URL: "postgresql://postgres:password@postgres/postgres"

depends_on:

- postgres

- redis

volumes:

- ./data:/app/data

redis:

image: redis:alpine

container_name: redash_redis

postgres:

image: postgres:12-alpine

container_name: redash_postgres

environment:

POSTGRES_USER: postgres

POSTGRES_PASSWORD: password

POSTGRES_DB: postgres

volumes:

- ./postgres-data:/var/lib/postgresql/data

  1. Deploy Redash using the following commands:

docker-compose up -d

This command spins up the server, Redis, and PostgreSQL containers.

  1. Access Redash at http://<your_server_ip>:5000 to complete the setup.

πŸš€ Manual Installation

For those who prefer a custom setup on a Linux server, here’s how to install Redash manually:

  1. Install system dependencies:

sudo apt update && sudo apt install -y python3 python3-pip python3-dev build-essential libffi-dev libssl-dev

  1. Install PostgreSQL and Redis:

sudo apt install -y postgresql redis

  1. Clone the Redash repository and set up the environment:

git clone https://github.com/getredash/redash.git

cd redash

pip3 install -r requirements.txt

  1. Configure the app by setting environment variables in .env:

echo "REDASH_DATABASE_URL=postgresql://user:password@localhost/dbname" >> .env

echo "REDASH_REDIS_URL=redis://localhost:6379/0" >> .env

  1. Start the application:

python3 manage.py runserver

Configuring Nginx as a Reverse Proxy

To enable secure access to Redash, we’ll set up Nginx as a reverse proxy.

🌐 Nginx Configuration

  1. Install Nginx:

sudo apt install -y nginx

  1. Create an Nginx server block for Redash:

sudo nano /etc/nginx/sites-available/redash

Add the following configuration:


server {

listen 80;

server_name yourdomain.com;

location / {

proxy_pass http://localhost:5000;

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

}

  1. Enable the configuration and restart Nginx:

sudo ln -s /etc/nginx/sites-available/redash /etc/nginx/sites-enabled/

sudo systemctl restart nginx

πŸ”’ SSL/TLS Setup

  1. Install Certbot:

sudo apt install -y certbot python3-certbot-nginx

  1. Obtain and install a free SSL certificate:

sudo certbot --nginx -d yourdomain.com

  1. Verify automatic renewal:

sudo systemctl status certbot.timer

Logging and Debugging Redash

Effective logging is critical for maintaining Redash.

πŸ—ƒοΈ Enabling Debug Logs

To activate debug logs, edit the environment variables in your Redash configuration:


echo "REDASH_LOG_LEVEL=DEBUG" >> .env

Restart the application to apply changes:


docker-compose restart

πŸ“„ Viewing Logs

For Docker deployments, view logs with:


docker logs redash_server

For manual installations, check application logs in /app/logs.

πŸ› οΈ Troubleshooting Common Issues

  1. Database Connection Errors: Ensure PostgreSQL is running and the REDASH_DATABASE_URL is correct.

  2. Redis Connection Errors: Confirm Redis is running and accessible at the configured address.

πŸ“€ Exporting Logs

To ship logs to an ELK stack, configure Filebeat to monitor Redash log files and forward them to Elasticsearch.

Backup and Restore

Backups ensure data safety in case of failures.

πŸ—‚οΈ File-Based Backups

Create a snapshot of critical files:


tar -czf redash-backup.tar.gz ./data ./postgres-data

πŸ”„ Database Backups

Export the PostgreSQL database:


docker exec redash_postgres pg_dump -U postgres postgres > backup.sql

Restore it with:


docker exec -i redash_postgres psql -U postgres postgres < backup.sql

πŸ“… Automated Backup Scripts

Set up a cron job for periodic backups:


0 2 * * * docker exec redash_postgres pg_dump -U postgres postgres > /path/to/backup-$(date +\%F).sql

Updating and Upgrading Redash

Keep Redash up-to-date for new features and security fixes.

⬆️ Updating Docker Images

Pull the latest image and redeploy:


docker-compose pull

docker-compose up -d

πŸ› οΈ Manual Updates

For manual installations, pull the latest code, update dependencies, and restart the server:


git pull origin master

pip3 install -r requirements.txt

python3 manage.py runserver

Leveraging Redash’s Unique Features

Make the most of Redash by enabling its powerful features.

πŸ”§ Enabling APIs

Activate the API by ensuring your user tokens are enabled. Use the API to create queries:


curl -H "Authorization: Key YOUR_API_KEY" -X POST -d '{"query": "SELECT * FROM table;"}' http://yourdomain.com/api/queries

🌟 Advanced Configurations

Integrate Redash with third-party tools like Slack for notifications or use custom scripts to automate query execution.

Wrapping Up

Self-hosting Redash provides a powerful and flexible platform for data visualization and control. By following this guide, you’ve deployed, secured, and configured Redash while learning how to maintain its performance. Start building dashboards, sharing insights, and unlocking the full potential of your data with Redash!

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Selfhosted Ninja.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.