Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
199 changes: 179 additions & 20 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,41 +55,119 @@ services:
depends_on:
mysql:
condition: service_healthy
rabbitmq:
image: rabbitmq:3-management-alpine
container_name: 'rabbitmq'
# rabbitmq:
# image: rabbitmq:3-management-alpine
# container_name: 'rabbitmq'
# ports:
# - 5672:5672
# - 15672:15672
# volumes:
# - ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/
# - ~/.docker-conf/rabbitmq/log/:/var/log/rabbitmq
# networks:
# - mynet
# prometheus:
# image: prom/prometheus
# ports:
# - 9090:9090
# volumes:
# - ./prometheus.yaml:/etc/prometheus/prometheus.yml:ro
# networks:
# - mynet
# grafana:
# image: grafana/grafana
# ports:
# - 3001:3000
# cadvisor:
# image: gcr.io/cadvisor/cadvisor:latest
# platform: linux/amd64
# container_name: cadvisor
# ports:
# - 8081:8080
# volumes:
# - /:/rootfs:ro
# - /var/run:/var/run:rw
# - /sys:/sys:ro
# - /var/lib/docker/:/var/lib/docker:ro
# - /var/run/docker.sock:/var/run/docker.sock:rw
# networks:
# - mynet

prometheus:
image: prom/prometheus:latest
restart: always
ports:
- 5672:5672
- 15672:15672
- "9090:9090"
links:
- cadvisor
- alertmanager
volumes:
- ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/
- ~/.docker-conf/rabbitmq/log/:/var/log/rabbitmq
- ./monitoring/prometheus/:/etc/prometheus/
user: root
depends_on:
- cadvisor
# 여기에 대해서 설명
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.console.libraries=/usr/share/prometheus/console_libraries'
- '--web.console.templates=/usr/share/prometheus/consoles'
networks:
- mynet
prometheus:
image: prom/prometheus
- mynet

grafana:
build:
context: ./monitoring/grafana
container_name: grafana
ports:
- 9090:9090
- "3001:3000"
depends_on:
- prometheus
networks:
- mynet
# node-exporter 역할이 무엇인가요?
node-exporter:
container_name: node-exporter
image: prom/node-exporter
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /:/rootfs:ro
command:
- '--path.procfs=/host/proc'
- '--path.sysfs=/host/sys'
- --collector.filesystem.ignored-mount-points
- "^/(sys|proc|dev|host|etc|rootfs/var/lib/docker/containers|rootfs/var/lib/docker/overlay2|rootfs/run/docker/netns|rootfs/var/lib/docker/aufs)($$|/)"
ports:
- "9100:9100"
restart: always
networks:
- mynet
grafana:
image: grafana/grafana
# alertmanager가 무엇인가요?
alertmanager:
container_name: alertmanager
image: prom/alertmanager
ports:
- 3001:3000
- "9093:9093"
volumes:
- ./monitoring/alertmanager/:/etc/alertmanager/
restart: always
command:
- '--config.file=/etc/alertmanager/config.yml'
- '--storage.path=/alertmanager'
networks:
- mynet
cadvisor:
image: gcr.io/cadvisor/cadvisor:latest
platform: linux/amd64
container_name: cadvisor
ports:
- 8081:8080
image: gcr.io/cadvisor/cadvisor:v0.46.0
volumes:
- /:/rootfs:ro
- /var/run:/var/run:rw
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
- /var/run/docker.sock:/var/run/docker.sock:rw
ports:
- "8080:8080"
restart: always
networks:
- mynet
nginx:
Expand All @@ -100,8 +178,89 @@ services:
- 443:443
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./nginx/log:/var/log/nginx
networks:
- mynet
elasticsearch:
build:
context: elk/elasticsearch
args:
ELASTIC_VERSION: 8.5.2
volumes:
- ./elk/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro,Z
ports:
- 9200:9200
- 9300:9300
environment:
node.name: elasticsearch
ES_JAVA_OPTS: -Xms512m -Xmx512m
# Bootstrap password.
# Used to initialize the keystore during the initial startup of
# Elasticsearch. Ignored on subsequent runs.
ELASTIC_PASSWORD: changeme
# Use single node discovery in order to disable production mode and avoid bootstrap checks.
# see: https://www.elastic.co/guide/en/elasticsearch/reference/current/bootstrap-checks.html
discovery.type: single-node
restart: unless-stopped
networks:
- mynet

logstash:
build:
context: elk/logstash
args:
ELASTIC_VERSION: 8.5.2
volumes:
- ./elk/logstash/config/logstash.yml:/usr/share/logstash/config/logstash.yml:ro,Z
- ./elk/logstash/pipeline:/usr/share/logstash/pipeline:ro,Z
ports:
- 5044:5044
- 50000:50000/tcp
- 50000:50000/udp
- 9600:9600
environment:
LS_JAVA_OPTS: -Xms256m -Xmx256m
LOGSTASH_INTERNAL_PASSWORD: changeme
depends_on:
- elasticsearch
restart: unless-stopped
networks:
- mynet

kibana:
build:
context: elk/kibana
args:
ELASTIC_VERSION: 8.5.2
volumes:
- ./elk/kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml:ro,Z
ports:
- 5601:5601
environment:
KIBANA_SYSTEM_PASSWORD: changeme
depends_on:
- elasticsearch
restart: unless-stopped
networks:
- mynet

filebeat:
build:
context: elk/filebeat
args:
ELASTIC_VERSION: 8.5.2
entrypoint: "filebeat -e -strict.perms=false"
volumes:
- ./elk/filebeat/config/filebeat.yml:/usr/share/filebeat/filebeat.yml
- ./nginx/log:/var/log/nginx # nginx log path (require same option on nginx container)
depends_on:
- logstash
- elasticsearch
- kibana
restart: unless-stopped
networks:
- mynet

volumes:
mysql_data_dev: null

Expand Down
2 changes: 2 additions & 0 deletions elk/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Declare files that will always have LF line endings on checkout.
*.sh text eol=lf
21 changes: 21 additions & 0 deletions elk/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 Anthony Lapenna

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
67 changes: 67 additions & 0 deletions elk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# docker-example Repo용 로깅 예제

[![Elastic Stack version](https://img.shields.io/badge/Elastic%20Stack-8.5.3-00bfb3?style=flat&logo=elastic-stack)](https://www.elastic.co/blog/category/releases)

https://github.com/litsynp/docker-example 프로젝트를 위한 로깅 세팅입니다.

## ELK 로깅

- *단일 compose 파일 실행시 동작하지 않습니다.*

### 동작 방식
1. NGINX의 로그파일을 Filebeat로 수집
2. 수집한 로그를 Logstash에 전달
3. 전달 받은 로그를 Elasticsearch에 저장
4. 저장된 로그를 Kibana를 통해 분석

### 사용법

```sh
$ docker compose -f docker-compose.yml -f docker-compose.logging.yml up --build
```

### Kibana를 통한 로그 시각화 방법
1. localhost:5601 접속
2. 상단 메뉴에서 index management 검색
3. 수집된 로그 인덱스 확인 weblogs-yyyy.MM.dd 형식
4. 좌측 메뉴의 Analytics의 Dashboard 클릭
5. Create data view를 통해 인덱스 선택
- 전체 조회 : Index Pattern에 `weblogs-*` 입력 및 저장
- 선택 조회 : Index Pattern에 보고싶은 날짜입력 (eg. `weblogs-2023.01.01`)
6. Create Visualization 클릭
7. 보고 싶은 필드를 화면에 드롭다운 하여 시각화

### 필수 파일
```
docker-example
├── backend
│ └── ...
├── frontend
│ └── ...
├── logging-example
│ ├── elasticsearch
│ │ ├── config
│ │ │ └── elasticsearch.yml
│ │ └── Dockerfile
│ ├── filebeat
│ │ ├── config
│ │ │ └── filebeat.yml
│ │ └── Dockerfile
│ ├── kibana
│ │ ├── config
│ │ │ └── kibana.yml
│ │ └── Dockerfile
│ └── logstash
│ ├── config
│ │ └── logstash.yml
│ ├── pipeline
│ │ └── logstash.conf
│ └── Dockerfile
├── nginx
│ ├── nginx.conf
│ └── log # 실행시 자동 생성
│ ├── access.log
│ └── error.log
├── docker-compose.logging.yml
└── docker-compose.prod.yml
```
6 changes: 6 additions & 0 deletions elk/elasticsearch/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Ignore Docker build files
Dockerfile
.dockerignore

# Ignore OS artifacts
**/.DS_Store
7 changes: 7 additions & 0 deletions elk/elasticsearch/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ARG ELASTIC_VERSION

# https://www.docker.elastic.co/
FROM docker.elastic.co/elasticsearch/elasticsearch:${ELASTIC_VERSION}

# Add your elasticsearch plugins setup here
# Example: RUN elasticsearch-plugin install analysis-icu
12 changes: 12 additions & 0 deletions elk/elasticsearch/config/elasticsearch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
## Default Elasticsearch configuration from Elasticsearch base image.
## https://github.com/elastic/elasticsearch/blob/main/distribution/docker/src/docker/config/elasticsearch.yml
#
cluster.name: docker-cluster
network.host: 0.0.0.0

## X-Pack settings
## see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-settings.html
#
xpack.license.self_generated.type: basic
xpack.security.enabled: false
6 changes: 6 additions & 0 deletions elk/filebeat/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Ignore Docker build files
Dockerfile
.dockerignore

# Ignore OS artifacts
**/.DS_Store
3 changes: 3 additions & 0 deletions elk/filebeat/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ARG ELASTIC_VERSION

FROM docker.elastic.co/beats/filebeat:${ELASTIC_VERSION}
14 changes: 14 additions & 0 deletions elk/filebeat/config/filebeat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/*.log

output.logstash:
enabled: true
hosts: ["logstash:5044"]

setup.kibana:
host: "http://kibana:5601"
username: "elastic"
password: "changeme"
6 changes: 6 additions & 0 deletions elk/kibana/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Ignore Docker build files
Dockerfile
.dockerignore

# Ignore OS artifacts
**/.DS_Store
7 changes: 7 additions & 0 deletions elk/kibana/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ARG ELASTIC_VERSION

# https://www.docker.elastic.co/
FROM docker.elastic.co/kibana/kibana:${ELASTIC_VERSION}

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