loki安装配置

loki官网

 

/lib/systemd/system/loki.service

复制代码
[Unit]
Description=loki
After=syslog.target network.target

[Service]
Type=simple
WorkingDirectory=/opt/loki/
ExecStart=/opt/loki/loki --config.file=loki-config.yaml
ExecStop=/bin/kill -9 $MAINPID

User=root
Group=root
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target
复制代码
loki-config.yaml
复制代码
auth_enabled: false

server:
  http_listen_port: 3100
  grpc_listen_port: 0

common:
  instance_addr: 10.22.32.2
  path_prefix: /opt/loki/data
  storage:
    filesystem:
      chunks_directory: /opt/loki/data/chunks
      rules_directory: /opt/loki/data/rules
  replication_factor: 1
  ring:
    kvstore:
      store: inmemory

query_range:
  results_cache:
    cache:
      embedded_cache:
        enabled: true
        max_size_mb: 100

schema_config:
  configs:
    - from: 2020-10-24
      store: tsdb
      object_store: filesystem
      schema: v13
      index:
        prefix: index_
        period: 24h
storage_config:
  # New tsdb-shipper configuration
  tsdb_shipper:
    active_index_directory: /opt//loki/tsdb/tsdb-index
    cache_location: /opt/loki/tsdb/tsdb-cache

query_scheduler:
  # the TSDB index dispatches many more, but each individually smaller, requests. 
  # We increase the pending request queue sizes to compensate.
  max_outstanding_requests_per_tenant: 32768

limits_config:
  max_query_lookback: 672h # 28 days
  retention_period: 672h   # 28 days
  per_stream_rate_limit: 5M    # setting per_stream_rate_limit no higher than 5MB, and per_stream_rate_limit_burst no higher than 20MB
  per_stream_rate_limit_burst: 20M
  #max_active_streams: 50000
  max_streams_per_user: 50000
  ingestion_rate_mb: 80
  ingestion_burst_size_mb: 256

compactor:
  working_directory: /opt/loki/data/retention
  delete_request_store: filesystem
  retention_enabled: true
querier:
  max_concurrent: 16

ruler:
  alertmanager_url: http://localhost:9093

frontend:
  encoding: protobuf
  max_outstanding_per_tenant: 4096
  compress_responses: true
View Code
复制代码

docker pull grafana/promtail:3.0.0

#!/bin/bash

logdir=/opt/logs
docker run --restart=always -d -v /opt/promtail/config:/mnt/config -v ${logdir}:/var/log grafana/promtail:3.0.0 --config.file=/mnt/config/promtail-local-config.yaml

promtail-local-config.yaml

复制代码
server:
  http_listen_port: 9080
  grpc_listen_port: 0

positions:
  filename: /opt/promtail-positions.yaml

clients:
  - url: http://10.22.32.2:3100/loki/api/v1/push

scrape_configs:
- job_name: openresty
  decompression:
    enabled: true
    initial_delay: 10s
    format: gz
  static_configs:
  - targets:
      - localhost
    labels:
      job: applog
      host: 10.16.2.19
      __path__: /var/log/*.log

  pipeline_stages:
    - regex:
#        expression: '^((?P<ip>\\S+) - - \\[(?P<timestamp>.+?)\\] "(?P<method>\\S+) (?P<request>.+?) HTTP/(?P<version>\\S+)" (?P<status>\\d+) (?P<size>\\d+) "(?P<referer>.*)" "(?P<useragent>.*)" "(?P<request_id>.*)" (?P<response_time>\\S+))'
        expression: '^(?P<ip>\S+) - - \[(?P<timestamp>.*?)\] "(?P<method>\S+) (?P<request>.+?) HTTP/(?P<version>\S+)" (?P<status>\d+) (?P<size>\d+) "(?P<referer>.*?)" "(?P<useragent>[^"]+)" "(?P<request_id>.*?)" (?P<response_time>\S+)'
    - labels:
        ip:
        status:
        method:
View Code
复制代码

grafana安装

配置loki数据源,可以直接在expoler设置查看

dashboard地址

可参考

 

posted @   林夕之风  阅读(108)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示