aws部署loki日志系统

568 阅读1分钟

S3配置

  • 创建 loki-s3 存储桶
  • 创建一个IAM用户组 loki-s3 并授予指定S3桶的权限
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "LokiStorage",
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket",
                "s3:PutObject",
                "s3:GetObject",
                "s3:DeleteObject"
            ],
            "Resource": [
                "arn:aws:s3:::loki-s3",
                "arn:aws:s3:::loki-s3/*"
            ]
        }
    ]
}
  • 创建一个IAM用户 loki-s3 加入 loki-s3 用户组,并创建访问密钥。

分组件部署loki日志系统

loki部署

  1. 注意官方文档给的示例并不能直接运行,可能文档没有更新,先使用示例values文件部署,查看报错信息。
  2. 提示需要配置schemaConfig,在artifacthub.io/packages/he…
  • 添加helm仓库
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
  • values.yaml文件 (3.0loki)
chunksCache:
    allocatedMemory: 2048

loki:
  auth_enabled: false

  storage:
    bucketNames:
      chunks: loki-s3
      ruler: loki-s3
      admin: loki-s3
    type: s3
    s3:
      endpoint: s3.ap-northeast-1.amazonaws.com
      region: ap-northeast-1
      secretAccessKey: xxxxxxxxx
      accessKeyId: xxxxxxxxx
      s3ForcePathStyle: true
      insecure: false

  storage_config:
    tsdb_shipper:
      index_gateway_client:
        server_address: '{{ include "loki.indexGatewayAddress" . }}'

  schemaConfig:
    configs:
    - from: 2024-04-01
      store: tsdb
      object_store: s3
      schema: v13
      index:
        prefix: index_
        period: 24h

write:
  replicas: 2
read:
  replicas: 2
backend:
  replicas: 2
  • 安装命令
helm upgrade --install -f values.yaml loki grafana/loki --namespace loki --create-namespace
# 卸载
helm uninstall loki -n loki

promtail 部署(用helm部署)

  • helm部署方式
config:
# publish data to loki
  clients:
    - url: http://loki-gateway.loki/loki/api/v1/push
      tenant_id: 1
# The default helm configuration deploys promtail as a daemonSet (recommended)
# 默认部署到default命名空间,指定为loki命名空间
helm upgrade --values promtail-values.yaml --install promtail grafana/promtail --namespace loki
# 卸载
helm uninstall promtail -n loki