Promtail是代理,负责收集日志并将其发送给Loki。
Loki是主服务器,负责存储日志和处理查询。
Grafana用于查询和显示日志。
步骤一、下载启动Loki
# wget https://github.com/grafana/loki/releases/download/v2.0.0/loki-linux-amd64.zip
# unzip loki-linux-amd64.zip
# mkdir -p /usr/local/loki
# mv loki-linux-amd64 /usr/local/loki
# cd /usr/local/loki
# chmod a+x loki-linux-amd64
# vim config.yaml
auth_enabled: false
server:
http_listen_port: 3100
grpc_listen_port: 9095 #grpc监听端口,默认为9095
grpc_server_max_recv_msg_size: 15728640 #grpc最大接收消息值,默认4m
grpc_server_max_send_msg_size: 15728640 #grpc最大发送消息值,默认4m
ingester:
lifecycler:
address: 10.1.43.3 #IP地址
ring:
kvstore:
store: inmemory
replication_factor: 1
final_sleep: 0s
chunk_idle_period: 5m
chunk_retain_period: 30s
max_transfer_retries: 0
max_chunk_age: 20m #一个timeseries块在内存中的最大持续时间。如果timeseries运行的时间超过此时间,则当前块将刷新到存储并创建一个新块
schema_config:
configs:
- from: 2018-04-15
store: boltdb
object_store: filesystem
schema: v11
index:
prefix: index_
period: 168h
storage_config:
boltdb:
directory: /data/loki/loki_data/index
filesystem:
directory: /data/loki/loki_data/chunks
limits_config:
enforce_metric_name: false
reject_old_samples: true
reject_old_samples_max_age: 168h
ingestion_rate_mb: 30 #修改每用户摄入速率限制,即每秒样本量,默认值为4M
ingestion_burst_size_mb: 15 #修改每用户摄入速率限制,即每秒样本量,默认值为6M
chunk_store_config:
max_look_back_period: 168h #回看日志行的最大时间,只适用于即时日志
table_manager:
retention_deletes_enabled: true #日志保留周期开关,默认为false
retention_period: 168h #日志保留周期
# nohup ./loki-linux-amd64 -config.file=/usr/local/loki/config.yaml &
步骤二、下载启动Promtail
# wget https://github.com/grafana/loki/releases/download/v2.0.0/promtail-linux-amd64.zip
# unzip promtail-linux-amd64.zip
# mkdir -p /usr/local/promtail
# mv promtail-linux-amd64 /usr/local/promtail
# cd /usr/local/promtail
# chmod a+x promtail-linux-amd64
# vim promtail.yaml
server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /tmp/positions.ymal
clients:
- url: http://10.1.43.3:3100/loki/api/v1/push
scrape_configs:
- job_name: nginx
static_configs:
- targets:
- 10.1.43.3
labels:
job: nginx
host: 10.1.43.3
__path__: /usr/local/nginx-1.12.2/nginx/logs/*
# nohup ./promtail-linux-amd64 -config.file=/usr/local/promtail/promtail.yaml
步骤三、Grafana添加Loki数据源