Redis Setup
Redis Setup
Section titled “Redis Setup”Configure Redis for Mantis cluster coordination, target affinity, and session management.
Overview
Section titled “Overview”Purpose
Section titled “Purpose”Redis provides essential services for multi-instance Mantis deployments:
| Feature | Component | Description |
|---|---|---|
| Instance Registry | Thorax | Track live Thorax instances |
| Target Affinity | Thorax | Prevent duplicate command dispatch |
| Cluster Health | Thorax | Heartbeat coordination |
| Session Management | Mandible | Track SSE subscriptions |
| Token Revocation | Mandible | JWT blocklist (fail-closed when Redis is down) |
Requirements
Section titled “Requirements”| Requirement | Minimum | Recommended |
|---|---|---|
| Redis | 6.0 | 7.0+ |
| Memory | 256 MB | 1+ GB |
| Storage | Optional | SSD for persistence |
Installation
Section titled “Installation”Ubuntu/Debian
Section titled “Ubuntu/Debian”# Install Redissudo apt updatesudo apt install redis-server -y
# Enable and startsudo systemctl enable redis-serversudo systemctl start redis-server
# Verifyredis-cli pingRHEL/Rocky/Alma
Section titled “RHEL/Rocky/Alma”# Install Redissudo dnf install redis -y
# Enable and startsudo systemctl enable redissudo systemctl start redis
# Verifyredis-cli pingDocker
Section titled “Docker”services: redis: image: redis:7-alpine hostname: redis command: redis-server --appendonly yes volumes: - redis_data:/data ports: - '6379:6379' healthcheck: test: ['CMD', 'redis-cli', 'ping'] interval: 10s timeout: 5s retries: 3
volumes: redis_data:Configuration
Section titled “Configuration”Basic Configuration
Section titled “Basic Configuration”Create /etc/redis/redis.conf:
# Networkbind 0.0.0.0port 6379protected-mode yes
# Securityrequirepass your-secure-password
# Memorymaxmemory 256mbmaxmemory-policy allkeys-lru
# Persistence (optional for cluster coordination)appendonly yesappendfsync everysec
# Loggingloglevel noticelogfile /var/log/redis/redis-server.logMemory Configuration
Section titled “Memory Configuration”For cluster coordination (small footprint):
# Minimal memory for coordination onlymaxmemory 256mbmaxmemory-policy allkeys-lruFor larger deployments with session state:
# More memory for sessionsmaxmemory 1gbmaxmemory-policy volatile-lruPersistence Options
Section titled “Persistence Options”| Mode | Use Case | Config |
|---|---|---|
| No persistence | Ephemeral data only | appendonly no, save "" |
| AOF | Cluster coordination | appendonly yes |
| RDB | Point-in-time backups | save 900 1 |
| Both | Maximum durability | AOF + RDB |
For Mantis cluster coordination:
# AOF persistence (recommended)appendonly yesappendfsync everysec
# Disable RDB snapshotssave ""Security
Section titled “Security”Password Authentication
Section titled “Password Authentication”requirepass your-secure-passwordACL Configuration (Redis 6+)
Section titled “ACL Configuration (Redis 6+)”user default offuser mantis on >secure-password ~mantis:* +@allOr via ACL file:
user mantis on >secure-password ~mantis:* +@all -@dangerousTLS Configuration (Redis 6+)
Section titled “TLS Configuration (Redis 6+)”tls-port 6379port 0
tls-cert-file /etc/redis/ssl/redis.crttls-key-file /etc/redis/ssl/redis.keytls-ca-cert-file /etc/redis/ssl/ca.crt
tls-auth-clients yesNetwork Security
Section titled “Network Security”# Bind to specific interfacesbind 127.0.0.1 10.0.0.1
# Or use firewall rules# ufw allow from 10.0.0.0/24 to any port 6379Mantis Configuration
Section titled “Mantis Configuration”Thorax Cluster Configuration
Section titled “Thorax Cluster Configuration”[cluster]enabled = trueredis_url = "redis://:password@redis:6379"namespace = "mantis"heartbeat_interval_secs = 10liveness_timeout_secs = 30Environment Variables
Section titled “Environment Variables”# ThoraxTHORAX__CLUSTER__ENABLED=trueTHORAX__CLUSTER__REDIS_URL="redis://:password@redis:6379"THORAX__CLUSTER__NAMESPACE="mantis"THORAX__CLUSTER__HEARTBEAT_INTERVAL_SECS=10THORAX__CLUSTER__LIVENESS_TIMEOUT_SECS=30
# Mandible (SSE session/event fan-out)SSE_REDIS_URL="redis://:password@redis:6379"# Or the prefixed config-loader form:# MANDIBLE__SSE__REDIS_URL="redis://:password@redis:6379"Redis URL Format
Section titled “Redis URL Format”redis://[username:password@]host[:port][/database]
# Examplesredis://localhost:6379redis://:password@redis:6379redis://user:password@redis:6379/0rediss://redis:6379 # TLSDocker Compose Integration
Section titled “Docker Compose Integration”Complete Stack
Section titled “Complete Stack”services: redis: image: redis:7-alpine hostname: redis command: redis-server --appendonly yes --requirepass ${REDIS_PASSWORD} volumes: - redis_data:/data networks: - mantis healthcheck: test: ['CMD', 'redis-cli', '-a', '${REDIS_PASSWORD}', 'ping'] interval: 10s timeout: 5s retries: 3
thorax: image: ghcr.io/mantisplatform/mantis-thorax:latest environment: THORAX__CLUSTER__ENABLED: 'true' THORAX__CLUSTER__REDIS_URL: 'redis://:${REDIS_PASSWORD}@redis:6379' depends_on: redis: condition: service_healthy networks: - mantis
volumes: redis_data:
networks: mantis:Kubernetes Deployment
Section titled “Kubernetes Deployment”Redis Deployment
Section titled “Redis Deployment”apiVersion: apps/v1kind: Deploymentmetadata: name: redisspec: replicas: 1 selector: matchLabels: app: redis template: metadata: labels: app: redis spec: containers: - name: redis image: redis:7-alpine command: - redis-server - --appendonly - 'yes' - --requirepass - $(REDIS_PASSWORD) ports: - containerPort: 6379 env: - name: REDIS_PASSWORD valueFrom: secretKeyRef: name: redis-secret key: password volumeMounts: - name: data mountPath: /data resources: requests: memory: '256Mi' cpu: '100m' limits: memory: '512Mi' cpu: '500m' volumes: - name: data persistentVolumeClaim: claimName: redis-pvc---apiVersion: v1kind: Servicemetadata: name: redisspec: selector: app: redis ports: - port: 6379Redis Secret
Section titled “Redis Secret”apiVersion: v1kind: Secretmetadata: name: redis-secrettype: Opaquedata: password: <base64-encoded-password> url: <base64-encoded-url> # redis://:password@redis:6379High Availability
Section titled “High Availability”Redis Sentinel
Section titled “Redis Sentinel”For automatic failover:
services: redis-master: image: redis:7-alpine command: redis-server --appendonly yes
redis-replica: image: redis:7-alpine command: redis-server --replicaof redis-master 6379
sentinel: image: redis:7-alpine command: redis-sentinel /etc/sentinel.conf volumes: - ./sentinel.conf:/etc/sentinel.confSentinel configuration:
# sentinel.confsentinel monitor mymaster redis-master 6379 2sentinel down-after-milliseconds mymaster 5000sentinel failover-timeout mymaster 60000sentinel parallel-syncs mymaster 1Redis Cluster
Section titled “Redis Cluster”For horizontal scaling:
services: redis-node-1: image: redis:7-alpine command: redis-server --cluster-enabled yes --cluster-config-file nodes.conf
redis-node-2: image: redis:7-alpine command: redis-server --cluster-enabled yes --cluster-config-file nodes.conf
redis-node-3: image: redis:7-alpine command: redis-server --cluster-enabled yes --cluster-config-file nodes.confMonitoring
Section titled “Monitoring”Redis Info
Section titled “Redis Info”# Connection inforedis-cli -a password INFO clients
# Memory usageredis-cli -a password INFO memory
# Key statisticsredis-cli -a password INFO keyspaceMantis Keys
Section titled “Mantis Keys”All Thorax Redis keys are prefixed with the configured namespace (default: thorax). The
examples below use mantis to match the namespace = "mantis" value in the
Thorax Cluster Configuration example above — substitute
your actual namespace if it differs.
# List all Thorax cluster keysredis-cli -a password KEYS "mantis:*"
# Check instance registryredis-cli -a password SMEMBERS "mantis:instances:index"
# View instance inforedis-cli -a password GET "mantis:instances:thorax-node-1"
# Check target affinityredis-cli -a password KEYS "mantis:affinity:*"Prometheus Metrics
Section titled “Prometheus Metrics”Use Redis Exporter:
services: redis-exporter: image: oliver006/redis_exporter:latest environment: REDIS_ADDR: 'redis://redis:6379' REDIS_PASSWORD: '${REDIS_PASSWORD}' ports: - '9121:9121'Verification
Section titled “Verification”Test Connection
Section titled “Test Connection”# Basic pingredis-cli -h redis -p 6379 -a password ping
# With TLSredis-cli --tls -h redis -p 6379 -a password pingCheck Mantis Integration
Section titled “Check Mantis Integration”Replace mantis below with your configured namespace (default: thorax).
# After starting Thorax, check registrationredis-cli -a password SMEMBERS "mantis:instances:index"
# Check instance inforedis-cli -a password GET "mantis:instances:thorax-$(hostname)"Health Endpoint
Section titled “Health Endpoint”Thorax reports Redis status in health check:
The HTTP health endpoint is served on port 9090 (port 50051 is the gRPC port and is not curl-able as JSON):
curl -s http://localhost:9090/health | jq '.cluster'Response:
{ "healthy": true, "active_instances": 2, "active_deployments": 5}Troubleshooting
Section titled “Troubleshooting”Connection Refused
Section titled “Connection Refused”Error: Connection refused (os error 111)Solutions:
- Check Redis is running:
systemctl status redis - Verify bind address:
redis-cli CONFIG GET bind - Check firewall:
ufw status
Authentication Error
Section titled “Authentication Error”Error: NOAUTH Authentication requiredSolutions:
- Verify password in URL:
redis://:password@host:6379 - Check Redis password:
redis-cli CONFIG GET requirepass
Memory Full
Section titled “Memory Full”Error: OOM command not allowed when used memory > maxmemorySolutions:
- Increase maxmemory:
redis-cli CONFIG SET maxmemory 512mb - Check memory policy:
redis-cli CONFIG GET maxmemory-policy - Clear old keys (substitute your namespace for
mantis):redis-cli KEYS "mantis:*" | xargs redis-cli DEL
Key TTL Issues
Section titled “Key TTL Issues”Replace mantis below with your configured namespace (default: thorax).
# Check TTL on instance keyredis-cli -a password TTL "mantis:instances:thorax-node-1"
# If TTL is -1 (no expiry), it may be a bug# Manually set expiryredis-cli -a password EXPIRE "mantis:instances:thorax-node-1" 30Next Steps
Section titled “Next Steps”- Cluster Coordination - Instance registry details
- Session Management - SSE session handling
- Multi-Thorax Deployment - Scaling Thorax
