Loki 도입하기

Category
Infra
Tags
Loki
Published
March 27, 2025
Last updated
Last updated March 27, 2025

Loki 란

 

LGTM 스택

 

Loki 구조

 

Getting started

 

Loki 설정

Example

Loki quickstart 설정

Loki 문서의 Loki quickstart에서 제공하는 loki-config.yaml 설정은 다음과 같습니다.
server: http_listen_address: 0.0.0.0 http_listen_port: 3100 memberlist: # Gossip 프로토콜을 이용한 분산 시스템 구성 join_members: ["read", "write", "backend"] # Loki 클러스터 내에서 함께 동작할 멤버들 dead_node_reclaim_time: 30s # 죽은 노드가 복구되지 않으면 데이터를 다른 노드가 가져감 gossip_to_dead_nodes_time: 15s # 죽은 노드와의 gossip 시도 시간 left_ingesters_timeout: 30s # 노드가 떠났을 때, 해당 데이터가 유지되는 시간 bind_addr: ['0.0.0.0'] # 모든 네트워크 인터페이스에서 gossip을 수신 bind_port: 7946 # Gossip 통신을 위한 포트 gossip_interval: 2s schema_config: configs: - from: 2023-01-01 # 이 설정이 적용되는 시작 날짜 store: tsdb # 사용되는 스토리지 엔진 (TSDB = Time Series Database) object_store: s3 # 객체 저장소로 S3를 사용 schema: v13 # Loki 스키마 버전 index: prefix: index_ # 인덱스 테이블의 접두어 period: 24h # 하루 단위로 새로운 인덱스 테이블 생성 common: path_prefix: /loki # Loki의 기본 데이터 저장 경로 replication_factor: 1 # 데이터 복제 개수 (1이면 복제 없음) compactor_address: http://backend:3100 # Compactor 역할을 하는 백엔드 노드의 주소 storage: # 데이터 저장소 설정 s3: endpoint: minio:9000 # Minio S3 스토리지 엔드포인트 insecure: true # HTTPS 없이 HTTP 사용 (보안에 취약) bucketnames: loki-data # Loki 로그 데이터를 저장할 버킷 이름 access_key_id: loki # S3 접근을 위한 Access Key secret_access_key: supersecret # S3 접근을 위한 Secret Key s3forcepathstyle: true ring: kvstore: store: memberlist # 클러스터 노드 간의 키-값 저장소로 Memberlist 사용 ruler: storage: s3: bucketnames: loki-ruler # Ruler(Alerting Rule 저장소)용 S3 버킷 compactor: working_directory: /tmp/compactor # Compactor가 임시로 사용할 디렉토리
Loki의 기능을 잘 활용해 분산 시스템을 구성하고, S3에 데이터를 저장하는 모습을 볼 수 있습니다.
 

example 1-Local-Configuration-Example.yaml

# This is a complete configuration to deploy Loki backed by the filesystem. # The index will be shipped to the storage via tsdb-shipper. auth_enabled: false server: http_listen_port: 3100 common: ring: instance_addr: 127.0.0.1 kvstore: store: inmemory replication_factor: 1 path_prefix: /tmp/loki schema_config: configs: - from: 2020-05-15 store: tsdb object_store: filesystem schema: v13 index: prefix: index_ period: 24h storage_config: filesystem: directory: /tmp/loki/chunks
 
 

설정

Loki를 도입하고 테스트해보기 위해 클러스터링과 S3를 사용하지 않고, 최소 기능으로 작동하는 설정을
auth_enabled: false server: http_listen_address: 0.0.0.0 http_listen_port: 3100 ingester: lifecycler: address: 127.0.0.1 ring: kvstore: store: inmemory replication_factor: 1 schema_config: configs: - from: 2025-01-01 store: tsdb object_store: filesystem schema: v13 index: prefix: index_ period: 24h storage_config: filesystem: directory: /tmp/loki/chunks
 
 

설정 값들 설명

# Common configuration to be shared between multiple modules. If a more specific # configuration is given in other sections, the related configuration within # this section will be ignored. [common: <common>]
 

Grafana 설정

 
 

Referenece