Search
🙉

ELK + filebeat 모니터링 구축

Intro::

ELK + filebeat 모니터링 구축 예제입니다.

docker-compose 파일

services: es01: image: docker.elastic.co/elasticsearch/elasticsearch:8.14.0 container_name: es01 environment: - cluster.name=elastic - node.name=es01 - network.host=0.0.0.0 - http.port=9200 - cluster.initial_master_nodes=es01 - bootstrap.memory_lock=true - "ES_JAVA_OPTS=-Xms512m -Xmx512m" - xpack.security.enabled=false ulimits: memlock: soft: -1 hard: -1 volumes: - data01:/usr/share/elasticsearch/data ports: - 9200:9200 - 9300:9300 healthcheck: test: [ "CMD-SHELL", "curl -fsSL http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=5s >/dev/null" ] interval: 10s timeout: 5s retries: 5 start_period: 20s networks: - elastic kibana: image: docker.elastic.co/kibana/kibana:8.14.0 container_name: kibana restart: always environment: ELASTICSEARCH_HOSTS: http://es01:9200 ports: - 5601:5601 depends_on: es01: condition: service_healthy healthcheck: test: [ "CMD-SHELL", "curl -fsSL http://localhost:5601/api/status | grep -q '\"overall\"' || exit 1" ] interval: 10s timeout: 5s retries: 5 start_period: 20s networks: - elastic filebeat: image: docker.elastic.co/beats/filebeat:8.14.0 container_name: filebeat user: root volumes: # Filebeat 설정 파일을 컨테이너 내부로 마운트 - ./filebeat.yml:/usr/share/filebeat/filebeat.yml:ro # 호스트의 로그 디렉터리를 컨테이너 내부 로그 경로로 마운트 - ./log:/usr/share/filebeat/logs:ro # Filebeat 자체 로그 저장소 - filebeat_data:/usr/share/filebeat/log-data depends_on: es01: condition: service_healthy # Elasticsearch가 헬시 상태일 때까지 대기 kibana: condition: service_healthy networks: - elastic metricbeat: image: docker.elastic.co/beats/metricbeat:8.14.0 container_name: metricbeat user: root volumes: # Metricbeat 설정 파일 마운트 - ./metricbeat.yml:/usr/share/metricbeat/metricbeat.yml:ro # 호스트의 /proc, /sys 등을 참조하기 위한 마운트 - /proc:/hostfs/proc:ro - /sys/fs/cgroup:/hostfs/sys/fs/cgroup:ro - /:/hostfs:ro # Docker 모듈을 사용하기 위한 소켓 볼륨(선택 사항) - /var/run/docker.sock:/var/run/docker.sock:ro environment: - ELASTICSEARCH_HOSTS=http://es01:9200 - KIBANA_HOST=http://kibana:5601 depends_on: es01: condition: service_healthy kibana: condition: service_healthy networks: - elastic volumes: data01: driver: local filebeat_data: driver: local networks: elastic: driver: bridge
Java
복사

filebeat.yml

# ────────────────────────────────────────────────────────────────────── # 1) 로그 입력(input) 설정 # ────────────────────────────────────────────────────────────────────── filebeat.inputs: - type: log enabled: true # 호스트(또는 컨테이너) 내 로그 디렉터리 paths: - /usr/share/filebeat/logs/*.log # 멀티라인 로그(예: 스택 트레이스) 처리 예시 multiline.pattern: '^[[:space:]]' multiline.negate: false multiline.match: after # ────────────────────────────────────────────────────────────────────── # 2) Elasticsearch 출력부 # ────────────────────────────────────────────────────────────────────── output.elasticsearch: hosts: ["http://es01:9200"] # 인덱스 이름을 버전-날짜 형태로 변경한 경우 index: "filebeat-%{[agent.version]}-%{+yyyy.MM.dd}" # ────────────────────────────────────────────────────────────────────── # 3) Kibana 연동(템플릿·대시보드 자동 로드용) # ────────────────────────────────────────────────────────────────────── setup.kibana: host: "http://kibana:5601" # ────────────────────────────────────────────────────────────────────── # 4) 색인 템플릿 설정 # ────────────────────────────────────────────────────────────────────── # 템플릿을 생성/업데이트하겠다는 의미 setup.template.enabled: true # Elasticsearch에 등록될 템플릿 이름 # "filebeat-{version}"까지 포함하면 더 정확하게 매칭됩니다. # 예) filebeat-8.14.0 setup.template.name: "filebeat-%{[agent.version]}" # 위 이름이 적용될 인덱스 패턴을 지정 (날짜 앞부분까지 매칭) # 예) filebeat-8.14.0-* setup.template.pattern: "filebeat-%{[agent.version]}-*" # 이미 동일 이름의 템플릿이 있으면 덮어쓰기(선택사항) # setup.template.overwrite: true # ────────────────────────────────────────────────────────────────────── # 5) 로그 파일로 Filebeat 자체 로그 남기기 # ────────────────────────────────────────────────────────────────────── logging.level: info logging.to_files: true logging.files: path: /usr/share/filebeat/log-data name: filebeat keepfiles: 7 permissions: 0644
Java
복사
Kibana 접속
브라우저에서 http://localhost:5601로 접속합니다.
Data Views(구 Index Patterns) 생성
사이드바에서 Management → Kibana → Data Views 클릭
우측 상단 Create data view 버튼 클릭
Index pattern name 입력란에 filebeat-* 입력 후 Enter
Time field에서 @timestamp 선택 → Create data view 클릭
Discover에서 로그 확인
사이드바에서 Discover 클릭
상단 드롭다운에서 생성한 Data View(예: filebeat-*) 선택
시간 범위를 현재 시각 기준으로 설정하면, 방금 전 기록한 테스트 로그가 화면에 표시됩니다.
# 8.* 버전 부터는 데이터 스트림으로 로그를 저장한다고 한다. GET _cat/indices?v GET _data_stream/filebeat-* GET filebeat-8.14.0-2025.06.04/_search
Bash
복사

metricbeat.yml

metricbeat.config.modules: path: ${path.config}/modules.d/*.yml reload.enabled: false # Elasticsearch 출력 설정 output.elasticsearch: hosts: ["${ELASTICSEARCH_HOSTS}"] # Kibana 대시보드 로드 setup.kibana: host: "${KIBANA_HOST}" setup.dashboards.enabled: true setup.dashboards.directory: /usr/share/metricbeat/kibana # Metricbeat 자체 로그: 표준 출력으로 설정 logging.level: info logging.to_files: false # ───────────────────────────────────────────────────────────────────────────── # system 모듈 활성화: CPU, 메모리, 네트워크, 파일시스템, 프로세스 등 메트릭 수집 # ───────────────────────────────────────────────────────────────────────────── metricbeat.modules: - module: system period: 10s # 호스트 루트가 /hostfs로 마운트되어 있으므로 별도 path 설정 불필요 metricsets: - cpu - memory - network - filesystem - fsstat - process - process_summary processes: ['.*'] process.include_top_n: by_cpu: 5 by_memory: 5 # ───────────────────────────────────────────────────────────────────────────── # Docker 모듈 활성화 (Docker 컨테이너 메트릭 수집) # ───────────────────────────────────────────────────────────────────────────── - module: docker metricsets: - container - cpu - diskio - healthcheck - info - memory - network hosts: ["unix:///var/run/docker.sock"] period: 10s
YAML
복사
좌측 사이드바에서 “Dashboard” 메뉴(종모양 아이콘 혹은 “대시보드”)를 클릭합니다.
상단 탭 또는 메뉴에서 “Dashboard Library”(또는 “대시보드 라이브러리”)를 선택합니다.
목록 중에서 이름에 Metricbeat가 포함된 대시보드를 찾아 클릭합니다.
예를 들어, “Metricbeat System Overview”나 “Metricbeat Host Overview” 등이 보일 것입니다.

References::