sherifabdlnaby / elastdocker

🐳 Elastic Stack (ELK) v8+ on Docker with Compose. Pre-configured out of the box to enable Logging, Metrics, APM, Alerting, ML, and SIEM features. Up with a Single Command.
https://towardsdatascience.com/running-securing-and-deploying-elastic-stack-on-docker-f1a8ebf1dc5b
MIT License
1.8k stars 313 forks source link
docker docker-compos-template docker-compose elasticsearch elasticstack elk elk-stack kibana logstash observability siem

Elastic Stack on Docker

Preconfigured Security, Tools, and Self-Monitoring

Configured to be ready to be used for Log, Metrics, APM, Alerting, Machine Learning, and Security (SIEM) usecases.

Elastic Stack Version 7^^ contributions welcome GitHub forks GitHub issues GitHub license

Introduction

Elastic Stack (ELK) Docker Composition, preconfigured with Security, Monitoring, and Tools; Up with a Single Command.

Suitable for Demoing, MVPs and small production deployments.

Stack Version: 8.10.2 🎉 - Based on Official Elastic Docker Images

You can change Elastic Stack version by setting ELK_VERSION in .env file and rebuild your images. Any version >= 8.0.0 is compatible with this template.

Main Features 📜

More points

And comparing Elastdocker and the popular deviantony/docker-elk

Expand...

One of the most popular ELK on Docker repositories is the awesome [deviantony/docker-elk](https://github.com/deviantony/docker-elk). Elastdocker differs from `deviantony/docker-elk` in the following points. - Security enabled by default using Basic license, not Trial. - Persisting data by default in a volume. - Run in Production Mode (by enabling SSL on Transport Layer, and add initial master node settings). - Persisting Generated Keystore, and create an extendable script that makes it easier to recreate it every-time the container is created. - Parameterize credentials in .env instead of hardcoding `elastich:changeme` in every component config. - Parameterize all other Config like Heap Size. - Add recommended environment configurations as Ulimits and Swap disable to the docker-compose. - Make it ready to be extended into a multinode cluster. - Configuring the Self-Monitoring and the Filebeat agent that ship ELK logs to ELK itself. (as a step to shipping it to a monitoring cluster in the future). - Configured Prometheus Exporters. - The Makefile that simplifies everything into some simple commands.


Requirements

Setup

  1. Clone the Repository
     git clone https://github.com/sherifabdlnaby/elastdocker.git
  2. Initialize Elasticsearch Keystore and TLS Self-Signed Certificates
    $ make setup

    For Linux's docker hosts only. By default virtual memory is not enough so run the next command as root sysctl -w vm.max_map_count=262144

  3. Start Elastic Stack
    $ make elk           <OR>         $ docker-compose up -d        <OR>        $ docker compose up -d
  4. Visit Kibana at https://localhost:5601 or https://<your_public_ip>:5601

    Default Username: elastic, Password: changeme

    • Notice that Kibana is configured to use HTTPS, so you'll need to write https:// before localhost:5601 in the browser.
    • Modify .env file for your needs, most importantly ELASTIC_PASSWORD that setup your superuser elastic's password, ELASTICSEARCH_HEAP & LOGSTASH_HEAP for Elasticsearch & Logstash Heap Size.

Whatever your Host (e.g AWS EC2, Azure, DigitalOcean, or on-premise server), once you expose your host to the network, ELK component will be accessible on their respective ports. Since the enabled TLS uses a self-signed certificate, it is recommended to SSL-Terminate public traffic using your signed certificates.

🏃🏻‍♂️ To start ingesting logs, you can start by running make collect-docker-logs which will collect your host's container logs.

Additional Commands

Expand

#### To Start Monitoring and Prometheus Exporters ```shell $ make monitoring ``` #### To Ship Docker Container Logs to ELK ```shell $ make collect-docker-logs ``` #### To Start **Elastic Stack, Tools and Monitoring** ``` $ make all ``` #### To Start 2 Extra Elasticsearch nodes (recommended for experimenting only) ```shell $ make nodes ``` #### To Rebuild Images ```shell $ make build ``` #### Bring down the stack. ```shell $ make down ``` #### Reset everything, Remove all containers, and delete **DATA**! ```shell $ make prune ```

Configuration

Setting Up Keystore

You can extend the Keystore generation script by adding keys to ./setup/keystore.sh script. (e.g Add S3 Snapshot Repository Credentials)

To Re-generate Keystore:

make keystore

Notes


Intro Alerting Maps ML

Working with Elastic APM

After completing the setup step, you will notice a container named apm-server which gives you deeper visibility into your applications and can help you to identify and resolve root cause issues with correlated traces, logs, and metrics.

Authenticating with Elastic APM

In order to authenticate with Elastic APM, you will need the following:

const apm = require('elastic-apm-node').start({
  serviceName: 'foobar',
  secretToken: process.env.ELASTIC_APM_SECRET_TOKEN,

  // https is enabled by default as per elastdocker configuration
  serverUrl: 'https://localhost:8200',
})

Make sure that the agent is started before you require any other modules in your Node.js application - i.e. before express, http, etc. as mentioned in Elastic APM Agent - NodeJS initialization

For more details or other languages you can check the following:

Monitoring The Cluster

Via Self-Monitoring

Head to Stack Monitoring tab in Kibana to see cluster metrics for all stack components.

Overview Moniroting

In Production, cluster metrics should be shipped to another dedicated monitoring cluster.

Via Prometheus Exporters

If you started Prometheus Exporters using make monitoring command. Prometheus Exporters will expose metrics at the following ports.

Prometheus Exporter Port Recommended Grafana Dashboard
elasticsearch-exporter 9114 Elasticsearch by Kristian Jensen
logstash-exporter 9304 logstash-monitoring by dpavlos

Metrics

License

MIT License Copyright (c) 2022 Sherif Abdel-Naby

Contribution

PR(s) are Open and Welcomed.