promtail 配置详解_部署-DevOps-Prometheus-Loki

场景

可以在一个平台下集中查看多个主机的系统及业务服务的日志

资源

centos7.x

docker-ce 19.x

docker-compose 1.23.x

grafana/grafana:latest

grafana/loki:latest

grafana/promtail:latest

服务端(Grafana/Loki)

Grafana/loki服务yml文件

# vim docker-compose-monitor.yml

version: '3.6'

services:

grafana:

image: grafana/grafana:latest

deploy:

mode: replicated

replicas: 1

resources:

limits:

memory: 128M

reservations:

memory: 64M

environment:

- GF_SECURITY_ADMIN_USER=admin

- GF_SECURITY_ADMIN_PASSWORD=xietong123

volumes:

- /etc/localtime:/etc/localtime

#- ./grafana/etc:/etc/grafana

#- ./grafana/lib/grafana.db:/var/lib/grafana/grafana.db

#- ./grafana/share:/usr/share/grafana

ports:

- '13000:3000'

loki:

image: grafana/loki:latest

#command: -config.file=/etc/loki/loki-local-config.yaml

deploy:

mode: replicated

replicas: 1

ports:

- "13100:3100"

volumes:

- /etc/localtime:/etc/localtime

- ./loki:/etc/loki

loki配置文件

# cat loki/local-config.yaml

auth_enabled: false

server:

http_listen_port: 3100

ingester:

lifecycler:

address: 127.0.0.1

ring:

kvstore:

store: inmemory

replication_factor: 1

final_sleep: 0s

chunk_idle_period: 1h # Any chunk not receiving new logs in this time will be flushed

max_chunk_age: 1h # All chunks will be flushed when they hit this age, default is 1h

chunk_target_size: 1048576 # Loki will attempt to build chunks up to 1.5MB, flushing first if chunk_idle_period or max_chunk_age is reached first

chunk_retain_period: 30s # Must be greater than index read cache TTL if using an index cache (Default index read cache TTL is 5m)

max_transfer_retries: 0 # Chunk transfers disabled

schema_config:

configs:

- from: 2020-10-24

store: boltdb-shipper

object_store: filesystem

schema: v11

index:

prefix: index_

period: 24h

storage_config:

boltdb_shipper:

active_index_directory: /loki/boltdb-shipper-active

cache_location: /loki/boltdb-shipper-cache

cache_ttl: 24h # Can be increased for faster performance over longer query periods, uses more disk space

shared_store: filesystem

filesystem:

directory: /loki/chunks

compactor:

working_directory: /loki/boltdb-shipper-compactor

shared_store: filesystem

limits_config:

reject_old_samples: true

reject_old_samples_max_age: 168h

chunk_store_config:

max_look_back_period: 0s

table_manager:

retention_deletes_enabled: false

retention_period: 0s

ruler:

storage:

type: local

local:

directory: /loki/rules

rule_path: /loki/rules-temp

alertmanager_url: http://localhost:19093

ring:

kvstore:

store: inmemory

enable_api: true

被收集日志的服务器(Promtail)

Promtail服务yml文件

# vim docker-compose-monitor.yml

version: '3.2'

services:

promtail:

image: grafana/promtail:latest

deploy:

mode: replicated

replicas: 1

volumes:

- /etc/localtime:/etc/localtime

- /data/promtail:/etc/promtail

- /var/log:/var/log

Promtail配置文件

# cat config.yml

server:

http_listen_port: 9080

grpc_listen_port: 0

grpc_server_max_recv_msg_size: 6291456

grpc_server_max_send_msg_size: 6291456

positions:

filename: /tmp/positions.yaml

clients:

- url: http://192.168.12.55:13100/loki/api/v1/push

scrape_configs:

#system messages

- job_name: messages

static_configs:

- targets:

- localhost

labels:

job: messages

__path__: /var/log/messages

#nginx logs

- job_name: host10-nginx-all

static_configs:

- targets:

- localhost

labels:

job: host10-nginx-all

app: host10-nginx

node: host10

__path__: /var/log/nginx/*.log

说明:

192.168.12.55:13100是loki服务器的IP及端口

grafana添加loki数据源

explore中选择loki数据源

查看promtail服务配置中定义的日志标签(对应路径下的log)

问题

待解决(可以正常查看日志)

你可能感兴趣的:(promtail,配置详解)