Example of an elastic stack configuration in docker 🐳
log -> filebeat -> logstash -> elasticsearch <- kibana
- Security enabled by default.
- Example of reading data from log file.
- Example of reading postgresql data.
- Docker 20.05 or higher
- Docker-Compose 1.29 or higher
- 4GB RAM (For Windows and MacOS make sure Docker's VM has more than 4GB+ memory.)
docker run -d --name elasticsearch elasticsearch:8.4.3
docker exec -it elasticsearch sh
mkdir certs && cd certs
Create a self-signed certificate for Elasticsearch
/usr/share/elasticsearch/bin/elasticsearch-certutil ca
/usr/share/elasticsearch/bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12 --dns elasticsearch,logstash
/usr/share/elasticsearch/bin/elasticsearch-certutil cert --pem -ca elastic-stack-ca.p12 --dns kibana
openssl pkcs12 -in elastic-certificates.p12 -out logstash.pem -clcerts -nokeys
openssl pkcs12 -in elastic-certificates.p12 -nocerts -nodes | sed -ne '/-BEGIN PRIVATE KEY-/,/-END PRIVATE KEY-/p' > logstash-ca.key
openssl pkcs12 -in elastic-certificates.p12 -cacerts -nokeys -chain | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > logstash-ca.crt
openssl pkcs12 -in elastic-certificates.p12 -clcerts -nokeys | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > logstash.crt
/usr/share/elasticsearch/bin/elasticsearch-certutil cert --ca-cert logstash-ca.crt --ca-key logstash-ca.key --dns logstash --pem
openssl pkcs8 -in logstash-ca.key -topk8 -nocrypt -out logstash.pkcs8.key
exit
docker cp elasticsearch:/usr/share/elasticsearch/certs ./certs
/usr/share/elasticsearch/bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password
/usr/share/elasticsearch/bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password
/usr/share/elasticsearch/bin/elasticsearch-keystore add xpack.security.http.ssl.keystore.secure_password
/usr/share/elasticsearch/bin/elasticsearch-keystore add xpack.security.http.ssl.truststore.secure_password
Run the next command to generate passwords for all the built-in users:
bin/elasticsearch-setup-passwords auto
- templates/custom-logs.template.json : Change it to your log index
# Make your own log index
{
...
"mappings": {
"properties": {
"name": {
"type": "keyword"
},
"class": {
"type": "keyword"
},
"state": {
"type": "integer"
},
"@timestamp": {
"type": "date"
}
}
}
}
- logstash.conf
# Change 'timestamp' to your log custom timestamp key
filter {
...
date{
match => ["timestamp", "UNIX_MS"]
target => "@timestamp"
}
}
# Change 'time.localtime' to your location time
filter {
...
ruby {
code => "event.set('indexDay', event.get('[@timestamp]').time.localtime('+09:00').strftime('%Y%m%d'))"
}
}
To run the entire stack
docker-compose up
To down the stack
docker-compose down
sendCommand(SecurityInterstitialCommandId.CMD_PROCEED)
https://localhost:9200/_cluster/health/?pretty
https://localhost:9200/_cat/indices?v
https://localhost:9200/_aliases
- [] Automatic self-signed certificate generation
- []
- []
MIT License Copyright (c) 2023 Julian Henao Marin
PR(s) are Open and Welcomed.