Skip to content

Commit 3da74ad

Browse files
feat: upgrade the elastic stack (#130)
1 parent 9941f7b commit 3da74ad

File tree

21 files changed

+615
-127
lines changed

21 files changed

+615
-127
lines changed

.github/workflows/ci-cd.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,3 @@ jobs:
1515
- uses: docker/setup-buildx-action@v3
1616
- run: docker-compose -f elastic-stack/docker-compose.yml build
1717
- run: docker-compose -f serilog/docker-compose.yml build
18-
19-
update_readme:
20-
runs-on: ubuntu-latest
21-
steps:
22-
- uses: actions/checkout@v4
23-
with:
24-
fetch-depth: 0
25-
- run: ./scripts/update-readme.sh

README.md

Lines changed: 13 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
<!-- omit from toc -->
12
# Serilog and the Elastic Stack
23

4+
<!-- omit from toc -->
35
## Table of contents
46

57
- [Introduction](#introduction)
68
- [What you will end up with](#what-you-will-end-up-with)
79
- [Requirements](#requirements)
8-
- [Usage on Windows](#usage-on-windows)
9-
- [Usage on Linux and macOS](#usage-on-linux-and-macos)
10+
- [Usage](#usage)
11+
- [Bringing up Elastic Stack](#bringing-up-elastic-stack)
12+
- [Publishing log events using Serilog](#publishing-log-events-using-serilog)
13+
- [Using Kibana to render the log events](#using-kibana-to-render-the-log-events)
1014
- [Credit](#credit)
1115

1216
---
@@ -25,38 +29,28 @@ With a running Elastic Stack and Serilog producing log events you are now ready
2529

2630
- [Docker](https://www.docker.com/community-edition#/download)
2731

28-
## Usage on Windows
32+
## Usage
2933

3034
### Bringing up Elastic Stack
3135

3236
Start the stack using `docker`:
3337

3438
```posh
35-
PS> cd .\elastic-stack\
36-
PS> docker compose up
37-
```
39+
cd .\elastic-stack\
3840
39-
If this is the first time the stack is started, you'll have to create a Logstash index pattern. Give the stack some time to initialize and then run the following commands in PowerShell:
41+
# This command is only necessary the first time the stack is started
42+
docker compose up setup
4043
41-
```posh
42-
PS> $Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
43-
PS> $Headers.Add("Content-Type", "application/json")
44-
PS> $Headers.Add("kbn-version", "7.17.0")
45-
PS> $Auth = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("elastic:changeme"))
46-
PS> $Headers.Add("Authorization", "Basic {0}" -f $Auth)
47-
PS> Invoke-RestMethod "http://localhost:5601/api/saved_objects/index-pattern" `
48-
-Method Post `
49-
-Headers $Headers `
50-
-Body '{"attributes":{"title":"logstash-*","timeFieldName":"@timestamp"}}'
44+
docker compose up
5145
```
5246

5347
### Publishing log events using Serilog
5448

5549
Run the following commands to publish log events to Logstash using Serilog:
5650

5751
```posh
58-
PS> cd .\serilog\
59-
PS> docker compose up
52+
cd .\serilog\
53+
docker compose up
6054
```
6155

6256
If you decide to run the application outside of Docker in your terminal, don't forget to change the request URI to `http://localhost:31311`. More information can be found in `.\serilog\Program.cs`.
@@ -65,42 +59,6 @@ If you decide to run the application outside of Docker in your terminal, don't f
6559

6660
Access the Kibana web UI by hitting [http://localhost:5601](http://localhost:5601) with a web browser, and when prompted enter username `elastic` and password `changeme`.
6761

68-
## Usage on Linux and macOS
69-
70-
### Bringing up Elastic Stack
71-
72-
Start the stack using `docker`:
73-
74-
```bash
75-
$ cd elastic-stack/
76-
$ docker compose up
77-
```
78-
79-
If this is the first time the stack is started, you'll have to create a Logstash index pattern. Give the stack some time to initialize and then run the following commands:
80-
81-
```bash
82-
$ curl -XPOST -D- 'http://localhost:5601/api/saved_objects/index-pattern' \
83-
-H 'Content-Type: application/json' \
84-
-H 'kbn-version: 7.17.0' \
85-
-u elastic:changeme \
86-
-d '{"attributes":{"title":"logstash-*","timeFieldName":"@timestamp"}}'
87-
```
88-
89-
### Publishing log events using Serilog
90-
91-
Run the following commands to publish log events to Logstash using Serilog:
92-
93-
```bash
94-
$ cd serilog/
95-
$ docker compose up
96-
```
97-
98-
If you decide to run the application outside of Docker in your terminal, don't forget to change the request URI to `http://localhost:31311`. More information can be found in `./serilog/Program.cs`.
99-
100-
### Using Kibana to render the log events
101-
102-
Access the Kibana web UI by hitting [http://localhost:5601](http://localhost:5601) with a web browser, and when prompted enter username `elastic` and password `changeme`.
103-
10462
## Credit
10563

10664
The `elastic-stack` directory is a clone of [docker-elk](https://github.com/deviantony/docker-elk) with minor modifications. Credit to [deviantony](https://github.com/deviantony) for publishing the Elastic Stack boilerplate.

elastic-stack/.env

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,22 @@
1-
ELK_VERSION=7.17.0
1+
ELASTIC_VERSION=8.13.2
2+
3+
## Passwords for stack users
4+
#
5+
6+
# User 'elastic' (built-in)
7+
#
8+
# Superuser role, full access to cluster management and data indices.
9+
# https://www.elastic.co/guide/en/elasticsearch/reference/current/built-in-users.html
10+
ELASTIC_PASSWORD='changeme'
11+
12+
# User 'logstash_internal' (custom)
13+
#
14+
# The user Logstash uses to connect and send data to Elasticsearch.
15+
# https://www.elastic.co/guide/en/logstash/current/ls-security.html
16+
LOGSTASH_INTERNAL_PASSWORD='changeme'
17+
18+
# User 'kibana_system' (built-in)
19+
#
20+
# The user Kibana uses to connect and communicate with Elasticsearch.
21+
# https://www.elastic.co/guide/en/elasticsearch/reference/current/built-in-users.html
22+
KIBANA_SYSTEM_PASSWORD='changeme'

elastic-stack/docker-compose.yml

Lines changed: 61 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,100 @@
1-
version: '3.2'
2-
31
services:
2+
# The 'setup' service runs a one-off script which initializes users inside
3+
# Elasticsearch — such as 'logstash_internal' and 'kibana_system' — with the
4+
# values of the passwords defined in the '.env' file. It also creates the
5+
# roles required by some of these users.
6+
#
7+
# This task only needs to be performed once, during the *initial* startup of
8+
# the stack. Any subsequent run will reset the passwords of existing users to
9+
# the values defined inside the '.env' file, and the built-in roles to their
10+
# default permissions.
11+
#
12+
# By default, it is excluded from the services started by 'docker compose up'
13+
# due to the non-default profile it belongs to. To run it, either provide the
14+
# '--profile=setup' CLI flag to Compose commands, or "up" the service by name
15+
# such as 'docker compose up setup'.
16+
setup:
17+
profiles:
18+
- setup
19+
build:
20+
context: setup/
21+
args:
22+
ELASTIC_VERSION: ${ELASTIC_VERSION}
23+
init: true
24+
volumes:
25+
- ./setup/entrypoint.sh:/entrypoint.sh:ro,Z
26+
- ./setup/lib.sh:/lib.sh:ro,Z
27+
- ./setup/roles:/roles:ro,Z
28+
environment:
29+
ELASTIC_PASSWORD: ${ELASTIC_PASSWORD:-}
30+
LOGSTASH_INTERNAL_PASSWORD: ${LOGSTASH_INTERNAL_PASSWORD:-}
31+
KIBANA_SYSTEM_PASSWORD: ${KIBANA_SYSTEM_PASSWORD:-}
32+
networks:
33+
- elk
34+
depends_on:
35+
- elasticsearch
36+
437
elasticsearch:
538
build:
639
context: elasticsearch/
740
args:
8-
ELK_VERSION: $ELK_VERSION
41+
ELASTIC_VERSION: ${ELASTIC_VERSION}
942
volumes:
10-
- ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro,z
11-
- elasticsearch:/usr/share/elasticsearch/data:z
43+
- ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro,Z
44+
- elasticsearch:/usr/share/elasticsearch/data:Z
1245
ports:
13-
- "9200:9200"
14-
- "9300:9300"
46+
- 9200:9200
47+
- 9300:9300
1548
environment:
16-
ES_JAVA_OPTS: "-Xmx256m -Xms256m"
17-
ELASTIC_PASSWORD: changeme
49+
node.name: elasticsearch
50+
ES_JAVA_OPTS: -Xms512m -Xmx512m
51+
# Bootstrap password.
52+
# Used to initialize the keystore during the initial startup of
53+
# Elasticsearch. Ignored on subsequent runs.
54+
ELASTIC_PASSWORD: ${ELASTIC_PASSWORD:-}
1855
# Use single node discovery in order to disable production mode and avoid bootstrap checks.
1956
# see: https://www.elastic.co/guide/en/elasticsearch/reference/current/bootstrap-checks.html
2057
discovery.type: single-node
2158
networks:
2259
- elk
60+
restart: unless-stopped
2361

2462
logstash:
2563
build:
2664
context: logstash/
2765
args:
28-
ELK_VERSION: $ELK_VERSION
66+
ELASTIC_VERSION: ${ELASTIC_VERSION}
2967
volumes:
30-
- ./logstash/config/logstash.yml:/usr/share/logstash/config/logstash.yml:ro,z
31-
- ./logstash/pipeline:/usr/share/logstash/pipeline:ro,z
68+
- ./logstash/config/logstash.yml:/usr/share/logstash/config/logstash.yml:ro,Z
69+
- ./logstash/pipeline:/usr/share/logstash/pipeline:ro,Z
3270
ports:
33-
- "9600:9600"
34-
- "31311:31311"
71+
- 9600:9600
72+
- 31311:31311
3573
environment:
36-
LS_JAVA_OPTS: "-Xmx256m -Xms256m"
74+
LS_JAVA_OPTS: -Xms256m -Xmx256m
75+
LOGSTASH_INTERNAL_PASSWORD: ${LOGSTASH_INTERNAL_PASSWORD:-}
3776
networks:
3877
- elk
3978
depends_on:
4079
- elasticsearch
80+
restart: unless-stopped
4181

4282
kibana:
4383
build:
4484
context: kibana/
4585
args:
46-
ELK_VERSION: $ELK_VERSION
86+
ELASTIC_VERSION: ${ELASTIC_VERSION}
4787
volumes:
48-
- ./kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml:ro,z
88+
- ./kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml:ro,Z
4989
ports:
50-
- "5601:5601"
90+
- 5601:5601
91+
environment:
92+
KIBANA_SYSTEM_PASSWORD: ${KIBANA_SYSTEM_PASSWORD:-}
5193
networks:
5294
- elk
5395
depends_on:
5496
- elasticsearch
97+
restart: unless-stopped
5598

5699
networks:
57100
elk:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Ignore Docker build files
2+
Dockerfile
3+
.dockerignore
4+
5+
# Ignore OS artifacts
6+
**/.DS_Store
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
ARG ELK_VERSION
1+
ARG ELASTIC_VERSION
22

33
# https://www.docker.elastic.co/
4-
FROM docker.elastic.co/elasticsearch/elasticsearch:${ELK_VERSION}
4+
FROM docker.elastic.co/elasticsearch/elasticsearch:${ELASTIC_VERSION}
55

66
# Add your elasticsearch plugins setup here
77
# Example: RUN elasticsearch-plugin install analysis-icu
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
---
22
## Default Elasticsearch configuration from Elasticsearch base image.
3-
## https://github.com/elastic/elasticsearch/blob/master/distribution/docker/src/docker/config/elasticsearch.yml
3+
## https://github.com/elastic/elasticsearch/blob/main/distribution/docker/src/docker/config/elasticsearch.yml
44
#
5-
cluster.name: "docker-cluster"
5+
cluster.name: docker-cluster
66
network.host: 0.0.0.0
77

88
## X-Pack settings
9-
## see https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-xpack.html
9+
## see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-settings.html
1010
#
1111
xpack.license.self_generated.type: trial
1212
xpack.security.enabled: true
13-
xpack.monitoring.collection.enabled: true

elastic-stack/kibana/.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Ignore Docker build files
2+
Dockerfile
3+
.dockerignore
4+
5+
# Ignore OS artifacts
6+
**/.DS_Store

elastic-stack/kibana/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
ARG ELK_VERSION
1+
ARG ELASTIC_VERSION
22

33
# https://www.docker.elastic.co/
4-
FROM docker.elastic.co/kibana/kibana:${ELK_VERSION}
4+
FROM docker.elastic.co/kibana/kibana:${ELASTIC_VERSION}
55

66
# Add your kibana plugins setup here
77
# Example: RUN kibana-plugin install <name|url>

0 commit comments

Comments
 (0)