Loki日誌塊使用MinIO對象存儲

簡介
與其他日誌記錄系統不同,Grafana Loki 是圍繞僅索引有關日誌的元數據的想法構建的:標籤(就像 Prometheus 標籤一樣)。然後,日誌數據本身會被壓縮並以塊的形式存儲在對象存儲(例如 S3 或 GCS)中,甚至本地存儲在文件系統中。小索引和高度壓縮的塊簡化了操作並顯着降低了 Loki 的成本。
在 Loki 2.0 之前,索引數據存儲在單獨的索引中。
 
安裝 Loki
略,參見   文章
 
安裝 MinIO
略,參見   文章
 
Loki對象存儲配置
S3 是 AWS 的託管對象存儲服務,也是互聯網通用的網絡對象存儲服務模式。它非常適合託管對象存儲,尤其是當您已經在 AWS 上運行並且生產安全時。
使用 AWS config 配置 MinIO,因爲 MinIO 實現了 S3 API。而Loki支持配置s3的應用,如下:
storage_config:
  aws:
    # Note: use a fully qualified domain name, like localhost.
    # full example: http://loki:supersecret@localhost.:9000
    s3: http<s>://<username>:<secret>@<fqdn>:<port>
    s3forcepathstyle: true
  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: s3

schema_config:
  configs:
    - from: 2020-07-01
      store: boltdb-shipper
      object_store: aws
      schema: v11
      # index爲索引數據,prefix表示設置索引存儲文件夾的前綴,period表示設置當天24小時內的索引數據放在一個index_xxx目錄,每天創建一個新index_xx索引目錄
      index:
        prefix: index_
        period: 24h
      # 注意chunks存儲的即爲數據塊
      chunks:
        prefix: chunks_
        period: 24h
我們用一個完整的示例,來演示如何將Loki通過s3協議將日誌塊上傳到MinIO,完整的Loki示例配置如下:
root@ubuntu2:/opt/loki# vim loki-local-config-minio.yaml
auth_enabled: false

server:
  http_listen_port: 3100
  grpc_listen_port: 9096

common:
  path_prefix: /tmp/loki
#  storage:
#    filesystem:
#      chunks_directory: /tmp/loki/chunks
#      rules_directory: /tmp/loki/rules
  replication_factor: 1
  ring:
    instance_addr: 0.0.0.0
    kvstore:
      store: inmemory

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

storage_config:
  aws:
    # Note: use a fully qualified domain name, like localhost.
    # full example: http://loki:supersecret@localhost.:9000
    s3: http://miniotest:[email protected]:9000/loki
    s3forcepathstyle: true
  boltdb_shipper:
    active_index_directory: /tmp/loki/boltdb-shipper-active
    cache_location: /tmp/loki/boltdb-shipper-cache
    cache_ttl: 24
    # Can be increased for faster performance over longer query periods, uses more disk space
    shared_store: s3

schema_config:
  configs:
    - from: 2020-10-24
      store: boltdb-shipper
      object_store: aws
      schema: v11
      index:
        prefix: index_
        period: 24h
      chunks:
        prefix: chunks_
        period: 24h

ruler:
  alertmanager_url: http://localhost:9093
MinIo上創建Buckets
loki要使用minio存儲日誌塊數據,必需先在minio創建網絡對象存儲桶bucket,此bucketName必需與yaml配置文件中的bucketName一致,yaml中配置的爲s3: http://miniotest:[email protected]:9000/loki,loki即爲minio存儲桶名稱;miniotest:miniotest爲minio創建用的賬號和密碼,使用此賬號上傳日誌數據到minio對象存儲桶時,確認此賬號有寫入權限,如無可以進入Buckets》loki》Manage》Access Audit》Users中添加。

 

啓動loki服務
./loki-linux-amd64 --config.file=loki-local-config-minio.yaml
日誌存儲查詢
MinIo管理平臺成功上傳日誌塊到fake目錄和索引文件上傳到index目錄;
 
參考:
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章