# Graylog Log Management

> Graylog centralized log management with MongoDB and OpenSearch.

- Category: Monitoring & Observability
- Difficulty: intermediate
- Components: graylog, mongodb, opensearch
- Tags: graylog, logging, centralized, opensearch, siem
- Source: https://docker.recipes/monitoring/graylog-logging

## Overview

Graylog is an enterprise-grade centralized log management platform that emerged from the need for comprehensive logging solutions in complex IT environments. Originally developed to address the challenges of log aggregation, analysis, and alerting across distributed systems, Graylog has evolved into a powerful Security Information and Event Management (SIEM) tool that combines log collection, parsing, indexing, and visualization capabilities. The platform excels at handling massive volumes of log data while providing real-time analysis and alerting functionality. This stack combines Graylog with OpenSearch for distributed search and analytics capabilities, while MongoDB serves as the metadata store for configuration data, user information, and dashboard definitions. OpenSearch acts as the primary data engine, storing and indexing log messages for fast retrieval and complex queries, while MongoDB maintains the operational state and configuration of the Graylog cluster. This architecture separates concerns effectively, allowing each component to excel at its specialized function. Organizations implementing centralized logging strategies, security operations centers, and DevOps teams monitoring distributed applications will find this combination particularly valuable. The stack provides enterprise-level log management capabilities without the licensing costs of commercial solutions, making it attractive for mid-sized companies and growing startups that need professional logging infrastructure but want to maintain control over their data and costs.

## Features

- Real-time log processing with customizable parsing rules and extractors for structured data extraction
- OpenSearch integration providing distributed full-text search across billions of log entries
- Stream-based log routing and processing with conditional message filtering and transformation
- MongoDB-backed configuration management ensuring persistent storage of dashboards, users, and alerts
- Multi-protocol log ingestion supporting Syslog, GELF, and custom input plugins
- Role-based access control with granular permissions for different user groups and data streams
- Alerting system with customizable conditions, notifications, and escalation workflows
- Geolocation enrichment and IP reputation lookup for security analysis

## Use cases

- Security Operations Centers monitoring network intrusions and analyzing security events
- DevOps teams centralizing application logs from microservices and container environments
- Compliance reporting for industries requiring audit trails and log retention policies
- Network operations monitoring infrastructure logs from routers, switches, and firewalls
- Web application monitoring tracking user behavior, errors, and performance metrics
- IoT device management collecting and analyzing telemetry data from connected devices
- Database activity monitoring for tracking queries, connections, and performance issues

## Prerequisites

- Minimum 4GB RAM available (2GB for OpenSearch, 1GB for Graylog, 512MB for MongoDB)
- Generate ROOT_PASSWORD_SHA2 using 'echo -n yourpassword | sha256sum' command
- Create PASSWORD_SECRET with minimum 16 characters for encryption operations
- Ports 9000, 1514, and 12201 available on the host system
- Basic understanding of log formats and network protocols for input configuration
- Docker host with at least 10GB available disk space for log data storage

## docker-compose.yml

```yaml
services:
  mongodb:
    image: mongo:6
    container_name: graylog-mongo
    restart: unless-stopped
    volumes:
      - mongo_data:/data/db
    networks:
      - graylog-network

  opensearch:
    image: opensearchproject/opensearch:latest
    container_name: graylog-opensearch
    restart: unless-stopped
    environment:
      - cluster.name=graylog
      - discovery.type=single-node
      - bootstrap.memory_lock=true
      - plugins.security.disabled=true
      - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - opensearch_data:/usr/share/opensearch/data
    networks:
      - graylog-network

  graylog:
    image: graylog/graylog:5.2
    container_name: graylog
    restart: unless-stopped
    ports:
      - "${GRAYLOG_PORT:-9000}:9000"
      - "1514:1514"
      - "1514:1514/udp"
      - "12201:12201"
      - "12201:12201/udp"
    environment:
      - GRAYLOG_PASSWORD_SECRET=${PASSWORD_SECRET:-somepasswordpepper}
      - GRAYLOG_ROOT_PASSWORD_SHA2=${ROOT_PASSWORD_SHA2}
      - GRAYLOG_HTTP_EXTERNAL_URI=http://localhost:9000/
      - GRAYLOG_MONGODB_URI=mongodb://mongodb:27017/graylog
      - GRAYLOG_ELASTICSEARCH_HOSTS=http://opensearch:9200
    volumes:
      - graylog_data:/usr/share/graylog/data
    depends_on:
      - mongodb
      - opensearch
    networks:
      - graylog-network

volumes:
  mongo_data:
  opensearch_data:
  graylog_data:

networks:
  graylog-network:
    driver: bridge
```

## .env

```bash
# Graylog
GRAYLOG_PORT=9000
PASSWORD_SECRET=somepasswordpeppersomepasswordpepper
# Generate with: echo -n "admin" | sha256sum
ROOT_PASSWORD_SHA2=8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918
```

## Usage notes

- Graylog at http://localhost:9000
- Default login: admin/admin
- Generate PASSWORD_SECRET (min 16 chars)
- Configure inputs to receive logs

## Troubleshooting

- Graylog shows 'Elasticsearch cluster unavailable': Verify OpenSearch container is running and check GRAYLOG_ELASTICSEARCH_HOSTS environment variable
- MongoDB connection errors in Graylog logs: Ensure MongoDB container started successfully and GRAYLOG_MONGODB_URI points to correct hostname
- OpenSearch fails to start with memory errors: Increase Docker memory limits or reduce OPENSEARCH_JAVA_OPTS heap size settings
- Web interface returns 'Invalid credentials': Verify ROOT_PASSWORD_SHA2 matches the SHA256 hash of your intended password
- No logs appearing in Graylog: Check that inputs are properly configured and firewall rules allow traffic on ports 1514 and 12201
- Graylog shows disk space warnings: Monitor volume usage and implement log rotation policies or increase storage allocation

