Grafana Loki 的日誌数据本身被压缩并以块的形式存储在 S3 或 GCS 等对象存储中,甚至存储在本地文件系统中。小索引和高度压缩的块简化了操作并显着降低了 Loki 的成本。
我们的 Grafana Loki 应用情境已经测试得差不多了,今天就来教大家如何将日誌数据存放在 Azure 储存体帐户中的 Blob 吧。
首先到 Azure 建立储存体并且新增一个容器
切换到存取金钥页面,複製您的储存体帐户名称与金钥机码。
编辑 Loki 的配置文件
sudo vi /opt/loki/loki-local-config.yaml
文件内容如下
account_name 填入您的储存体帐户名称account_key 填入您的金钥机码container_name 填入您的容器名称auth_enabled: falseserver: http_listen_port: 3100 grpc_listen_port: 9096common: path_prefix: /opt/loki storage: filesystem: chunks_directory: /opt/loki/chunks rules_directory: /opt/loki/rules replication_factor: 1 ring: instance_addr: 127.0.0.1 kvstore: store: inmemoryquery_range: results_cache: cache: embedded_cache: enabled: true max_size_mb: 100schema_config: configs: - from: "2020-12-11" index: period: 24h prefix: index_ #object_store: filesystem object_store: azure schema: v11 store: boltdb-shipperstorage_config: azure: # Your Azure storage account name account_name: your_storage_account_name # For the account-key, see docs: https://docs.microsoft.com/en-us/azure/storage/common/storage-account-keys-manage?tabs=azure-portal account_key: your_storage_account_key # See https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blobs-introduction#containers container_name: your_container_name request_timeout: 0 boltdb_shipper: active_index_directory: /opt/loki/boltdb-shipper-active cache_location: /opt/loki/boltdb-shipper-cache cache_ttl: 24h shared_store: azurequerier: max_concurrent: 2048query_scheduler: max_outstanding_requests_per_tenant: 2048ruler: alertmanager_url: http://localhost:9093
记得重启 Loki 服务
sudo service loki restart
可以看到 Loki 已经将资料存放到 Azure 储存体中
最后 Grafana 仪表板也可以正常显示日誌分析数据
根据最佳实践指出,当 Loki 把压缩的数据块 chunk_target_size 填满又或者数据块的年龄超过 max_chunk_age 时,该数据块就会变成唯读模式不再写入资料,进而达到读写分离增加查询的效能。
chunk_target_size 预设为 1.5 MBmax_chunk_age 预设为 1小时您需要 5–10 倍或 7.5–10MB 的原始日誌数据来填充 1.5MB 的块。
我们可以把这些唯读的数据块移至非经常性储存体来节省 Azure 费用
切换到生命週期管理,新增规则。
规则名称填入 Move to cool access tiers for blob data,下一步。
设定上次修改时间超过 1 天,移至非经常性储存体。
今天的分享就到这边,希望有帮助到大家。
参考文件
https://grafana.com/docs/loki/latest/storage/https://learn.microsoft.com/zh-tw/azure/cloud-adoption-framework/ready/azure-best-practices/resource-naminghttps://grafana.com/docs/loki/latest/best-practices/https://grafana.com/docs/loki/latest/fundamentals/architecture/components/https://learn.microsoft.com/zh-tw/azure/storage/blobs/access-tiers-overview?tabs=azure-portal