日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

5分钟搭建轻量级日志系统Loki

發布時間:2023/12/13 综合教程 55 生活家
生活随笔 收集整理的這篇文章主要介紹了 5分钟搭建轻量级日志系统Loki 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Loki 是一個水平可擴展,高可用性,多租戶日志聚合系統,靈感來自 Prometheus ,其設計非常經濟高效,易于操作。它不索引日志的內容,而是為每個日志流設置一組標簽。

與其他日志聚合系統相比,Loki:

不對日志進行全文本索引。通過存儲壓縮的,非結構化的日志以及僅索引元數據,Loki更加易于操作且運行成本更低。
使用與Prometheus相同的標簽對日志流進行索引和分組,從而使您能夠使用與Prometheus相同的標簽在指標和日志之間無縫切換。
特別適合存儲Kubernetes Pod日志。諸如Pod標簽之類的元數據會自動被抓取并建立索引。
在Grafana中原生支持(需要Grafana v6.0及以上)。

基于Loki的日志記錄堆棧包含3個組件:

promtail是代理,負責收集日志并將其發送給Loki。
loki是主服務器,負責存儲日志和處理查詢。
Grafana用于查詢和顯示日志。

開始

大部分文章都是基于 k8s 、docker-compose去安裝的,這里我們用二進制安裝

Loki

類似 elasticsearch

安裝
curl -O -L "https://github.com/grafana/loki/releases/download/v1.5.0/loki-linux-amd64.zip"
unzip loki-linux-amd64.zip
chmod a+x loki-linux-amd64
./loki-linux-amd64
配置文件 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: 5m
  chunk_retain_period: 30s

schema_config:
  configs:
    - from: 2018-04-15
      store: boltdb
      object_store: filesystem
      schema: v9
      index:
        prefix: index_
        period: 168h

storage_config:
  boltdb:
    directory: /tmp/loki/index

  filesystem:
    directory: /tmp/loki/chunks

limits_config:
  enforce_metric_name: false
  reject_old_samples: true
  reject_old_samples_max_age: 168h

chunk_store_config:
  max_look_back_period: 0

table_manager:
  chunk_tables_provisioning:
    inactive_read_throughput: 0
    inactive_write_throughput: 0
    provisioned_read_throughput: 0
    provisioned_write_throughput: 0
  index_tables_provisioning:
    inactive_read_throughput: 0
    inactive_write_throughput: 0
    provisioned_read_throughput: 0
    provisioned_write_throughput: 0
  retention_deletes_enabled: false
  retention_period: 0

Promtail

比如你要收集Nginx的錯誤日志,那就要在Nginx那臺服務器部署 Promtail,類似 fluentd

安裝
curl -O -l "https://github.com/grafana/loki/releases/download/v1.5.0/promtail-linux-amd64.zip"
unzip promtail-linux-amd64.zip
chmod a+x promtail-linux-amd64
./promtail-linux-amd64
配置文件 config.yaml
# Promtail Server Config
server:
  http_listen_port: 9080
  grpc_listen_port: 0

# Positions
positions:
  filename: /tmp/positions.yaml

# Loki服務器的地址
clients:
  - url: http://172.18.11.161:3100/loki/api/v1/push

scrape_configs:
  - job_name: nginx
    static_configs:
      - targets:
          - localhost
        labels:
          job: nginx-error
          host: localhost
          __path__: /usr/local/nginx/logs/error.log

Grafana

打開Grafana,添加數據源,選

使用

打開 Grafana,點擊 Explore ,

Log labels 輸入 {job="nginx-error"}

總結

以上是生活随笔為你收集整理的5分钟搭建轻量级日志系统Loki的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。