Graylog is a handy, free log aggregator. This is a simple way to start using their open source offering in a hurry. We’ll start with the assumption that you have a system with docker installed, and that you have access to use it.
Use the following command to create your GRAYLOG_DATANODE_PASSWORD_SECRET
:
$ < /dev/urandom tr -dc A-Z-a-z-0-9 | head -c${1:-96};echo;
This will ultimately output 96 random characters that consist of A-Z, a-z, 0-9, and the literal “-” character…
(What’s really going on here? If you try the command to the left of the pipe, you’ll find that it spits random text out to your terminal until you hit CTRL-C. The command to the right of the pipe takes 96 characters from that output and prints them to the terminal for you.)
Then, create your GRAYLOG_DATANODE_ROOT_PASSWORD_SHA2
:
$ echo -n "Enter Password: " && head -1 </dev/stdin | tr -d '\n' | sha256sum | cut -d" " -f1
This will prompt you for a password (which will appear in your terminal session, but not in your history), which it will convert into a SHA256 hash and print to the console.
Now create your docker-compose.yml file:
services:
# MongoDB: https://hub.docker.com/_/mongo/
mongodb:
image: "mongo:6.0.18"
restart: "on-failure"
networks:
- graylog
volumes:
- "mongodb_data:/data/db"
- "mongodb_config:/data/configdb"
# Graylog Data Node: https://hub.docker.com/r/graylog/graylog-datanode
datanode:
image: "graylog/graylog-datanode:6.1"
hostname: "datanode"
environment:
GRAYLOG_DATANODE_NODE_ID_FILE: "/var/lib/graylog-datanode/node-id"
GRAYLOG_DATANODE_PASSWORD_SECRET: "GENERATEME"
GRAYLOG_DATANODE_ROOT_USERNAME: "admin"
GRAYLOG_DATANODE_ROOT_PASSWORD_SHA2: "GENERATEME"
GRAYLOG_DATANODE_MONGODB_URI: "mongodb://mongodb:27017/graylog"
ulimits:
memlock:
hard: -1
soft: -1
nofile:
soft: 65536
hard: 65536
networks:
- graylog
volumes:
- "graylog-datanode:/var/lib/graylog-datanode"
restart: "on-failure"
# Graylog: https://hub.docker.com/r/graylog/graylog/
graylog:
hostname: "server"
image: "graylog/graylog:6.1"
depends_on:
mongodb:
condition: "service_started"
datanode:
condition: "service_started"
entrypoint: "/usr/bin/tini -- /docker-entrypoint.sh"
environment:
GRAYLOG_NODE_ID_FILE: "/usr/share/graylog/data/config/node-id"
GRAYLOG_HTTP_BIND_ADDRESS: "0.0.0.0:9000"
GRAYLOG_MONGODB_URI: "mongodb://mongodb:27017/graylog"
# To make reporting (headless_shell) work inside a Docker container
GRAYLOG_REPORT_DISABLE_SANDBOX: "true"
# CHANGE ME (must be at least 16 characters)!
GRAYLOG_PASSWORD_SECRET: "USE GRAYLOG_DATANODE_PASSWORD_SECRET"
# Password: "admin"
GRAYLOG_ROOT_PASSWORD_SHA2: "USE GRAYLOG_DATANODE_ROOT_PASSWORD_SHA2"
GRAYLOG_HTTP_EXTERNAL_URI: "http://127.0.0.1:9000/"
ports:
# Graylog web interface and REST API
- "9000:9000/tcp"
# Beats
- "5044:5044/tcp"
# Syslog TCP
- "5140:5140/tcp"
# Syslog UDP
- "5140:5140/udp"
# GELF TCP
- "12201:12201/tcp"
# GELF UDP
- "12201:12201/udp"
# Forwarder data
- "13301:13301/tcp"
# Forwarder config
- "13302:13302/tcp"
restart: "on-failure"
networks:
- graylog
volumes:
- "graylog_data:/usr/share/graylog/data"
networks:
graylog:
driver: "bridge"
volumes:
mongodb_data:
mongodb_config:
graylog-datanode:
graylog_data:
Now all you have to do is bring the containers up and wait for them to initialize:
$ docker compose up -d && docker compose logs -f
This will pull the images (if you haven’t already), build the containers, and start them, then it will stream the logs from your containers to the console so you can watch them come up. When you are satisfied, you can press CTRL-C to stop the log stream; your containers will still be running in the background, you can use the command docker compose ps
to see the current status of your pods and the network ports they are using.
Regarding network ports, entries that look like “27017/tcp” indicate that the port is only open to other docker containers and not to the host machine. Entries that look like “0.0.0.0:9000->9000/tcp” (IPv4) or “:::9000->9000/tcp” (IPv6) indicate that these ports can be seen by the host.
To bring everything down, simply type:
$ docker compose down