管理存储
您可以在此处阅读 Loki 存储的高级概述
Grafana Loki 需要存储两种不同类型的数据:块(chunks)和索引(indexes)。
使用加速搜索(实验性)时,会使用第三种数据类型:布隆块(bloom blocks)。
Loki 在独立的流中接收日志,每个流由其租户 ID 和标签集唯一标识。当来自流的日志条目到达时,它们被压缩成块(chunks)并保存在块存储中。有关块内部存储方式,请参阅块格式。
索引(index)存储每个流的标签集,并将其链接到各个块。有关如何配置存储和索引的详细信息,请参阅 Loki 配置。
更多信息
存储类型
✅ 支持的索引存储
- 单一存储 TSDB 索引存储,它将 TSDB 索引文件存储在对象存储中。这是 Loki 2.8 及更新版本推荐的索引存储。
- 单一存储 BoltDB (boltdb-shipper) 索引存储,它将 boltdb 索引文件存储在对象存储中。这是 Loki 2.0 到 2.7.x 版本推荐的存储。
❌ 已弃用的索引存储
- Amazon DynamoDB。对此的支持已被弃用,并将在未来的版本中移除。
- Google Bigtable。对此的支持已被弃用,并将在未来的版本中移除。
- Apache Cassandra。对此的支持已被弃用,并将在未来的版本中移除。
- BoltDB(在 Loki 集群模式下不起作用)
✅ 支持且推荐的块存储
- Amazon Simple Storage Service (S3)
- Google Cloud Storage (GCS)
- Microsoft Azure Blob Storage
- IBM Cloud Object Storage (COS)
- 百度对象存储 (BOS)
- 阿里云对象存储服务 (OSS)
⚠️ 支持的块存储,通常不推荐用于生产环境
❌ 已弃用的块存储
- Amazon DynamoDB。对此的支持已被弃用,并将在未来的版本中移除。
- Google Bigtable。对此的支持已被弃用,并将在未来的版本中移除。
- Apache Cassandra。对此的支持已被弃用,并将在未来的版本中移除。
云存储权限
S3
将 S3 用作对象存储时,需要以下权限
s3:ListBuckets3:PutObjects3:GetObjects3:DeleteObject(如果运行单一存储 (boltdb-shipper) 压缩器)
资源:arn:aws:s3:::<bucket_name>, arn:aws:s3:::<bucket_name>/*
有关详细的设置指南,请参阅存储页面上的AWS 部署部分。
DynamoDB
注意
DynamoDB 支持已被弃用,并将在未来的版本中移除。
将 DynamoDB 用于索引时,需要以下权限
dynamodb:BatchGetItemdynamodb:BatchWriteItemdynamodb:DeleteItemdynamodb:DescribeTabledynamodb:GetItemdynamodb:ListTagsOfResourcedynamodb:PutItemdynamodb:Querydynamodb:TagResourcedynamodb:UntagResourcedynamodb:UpdateItemdynamodb:UpdateTabledynamodb:CreateTabledynamodb:DeleteTable(如果table_manager.retention_period大于 0 秒)
资源:arn:aws:dynamodb:<aws_region>:<aws_account_id>:table/<prefix>*
dynamodb:ListTables
资源:*
自动伸缩
如果从表管理器启用自动伸缩,需要以下权限
Application Autoscaling
application-autoscaling:DescribeScalableTargetsapplication-autoscaling:DescribeScalingPoliciesapplication-autoscaling:RegisterScalableTargetapplication-autoscaling:DeregisterScalableTargetapplication-autoscaling:PutScalingPolicyapplication-autoscaling:DeleteScalingPolicy
资源:*
IAM
iam:GetRoleiam:PassRole
资源:arn:aws:iam::<aws_account_id>:role/<role_name>
IBM Cloud Object Storage
将 IBM Cloud Object Storage (COS) 用作对象存储时,需要 IAM Writer 角色。
有关详细的设置指南,请参阅存储页面上的IBM Cloud Object Storage 部分。
块格式
// Header
+-----------------------------------+
| Magic Number (uint32, 4 bytes) |
+-----------------------------------+
| Version (1 byte) |
+-----------------------------------+
| Encoding (1 byte) |
+-----------------------------------+
// Blocks
+--------------------+----------------------------+
| block 1 (n bytes) | checksum (uint32, 4 bytes) |
+--------------------+----------------------------+
| block 1 (n bytes) | checksum (uint32, 4 bytes) |
+--------------------+----------------------------+
| ... |
+--------------------+----------------------------+
| block N (n bytes) | checksum (uint32, 4 bytes) |
+--------------------+----------------------------+
// Metas
+------------------------------------------------------------------------------------------------------------------------+
| #blocks (uvarint) |
+--------------------+-----------------+-----------------+------------------+---------------+----------------------------+
| #entries (uvarint) | minTs (uvarint) | maxTs (uvarint) | offset (uvarint) | len (uvarint) | uncompressedSize (uvarint) |
+--------------------+-----------------+-----------------+------------------+---------------+----------------------------+
| #entries (uvarint) | minTs (uvarint) | maxTs (uvarint) | offset (uvarint) | len (uvarint) | uncompressedSize (uvarint) |
+--------------------+-----------------+-----------------+------------------+---------------+----------------------------+
| ... |
+--------------------+-----------------+-----------------+------------------+---------------+----------------------------+
| #entries (uvarint) | minTs (uvarint) | maxTs (uvarint) | offset (uvarint) | len (uvarint) | uncompressedSize (uvarint) |
+--------------------+-----------------+-----------------+------------------+---------------+----------------------------+
| checksum (uint32, 4 bytes) |
+------------------------------------------------------------------------------------------------------------------------+
// Structured Metadata
+---------------------------------+
| #labels (uvarint) |
+---------------+-----------------+
| len (uvarint) | value (n bytes) |
+---------------+-----------------+
| ... |
+---------------+-----------------+
| checksum (uint32, 4 bytes) |
+---------------------------------+
// Footer
+-----------------------+--------------------------+
| len (uint64, 8 bytes) | offset (uint64, 8 bytes) | // offset to Structured Metadata
+-----------------------+--------------------------+
| len (uint64, 8 bytes) | offset (uint64, 8 bytes) | // offset to Metas
+-----------------------+--------------------------+


