grafana loki 2.4 简化服务部署

grafana loki 2.4 版本简化了集群部署的使用,实际上部署起来很简单了,而且系统扩容更方便了

环境准备

  • docker-compose 文件
---
version: "3"
 
networks:
  loki:
 
services:
  read:
    image: grafana/loki:2.4.2
    command: "-config.file=/etc/loki/config.yaml -target=read"
    ports:
      - 3100
      - 7946
      - 9095
    volumes:
      - ./loki-config.yaml:/etc/loki/config.yaml
    depends_on:
      - minio
    networks: &loki-dns
      loki:
        aliases:
          - loki
 
  write:
    image: grafana/loki:2.4.2
    command: "-config.file=/etc/loki/config.yaml -target=write"
    ports:
      - 3100
      - 7946
      - 9095
    volumes:
      - ./loki-config.yaml:/etc/loki/config.yaml
    depends_on:
      - minio
    networks:
      <<: *loki-dns
 
  promtail:
    image: grafana/promtail:2.4.2
    logging: &logging
      driver: grafana/loki-docker-driver:main
      options:
        loki-url: "http://localhost:3100/loki/api/v1/push"
        loki-retries: "1"
        loki-tenant-id: "tenant1"
    volumes:
      - /var/log:/var/log
      - ./promtail-config.yaml:/etc/promtail/config.yaml:ro
    command: -config.file=/etc/promtail/config.yaml
    depends_on:
      - gateway
    networks:
      - loki
 
  minio:
    image: minio/minio
    entrypoint:
      - sh
      - -euc
      - |
        mkdir -p /data/loki-data && \
        mkdir -p /data/loki-ruler && \
        minio server /data
    environment:
      - MINIO_ACCESS_KEY=loki
      - MINIO_SECRET_KEY=supersecret
      - MINIO_PROMETHEUS_AUTH_TYPE=public
      - MINIO_UPDATE=off
    logging:
      <<: *logging
    ports:
      - 9000
    volumes:
      - ./.data/minio:/data
    networks:
      - loki
 
  grafana:
    image: grafana/grafana:latest
    logging:
      <<: *logging
    environment:
      - GF_PATHS_PROVISIONING=/etc/grafana/provisioning
      - GF_AUTH_ANONYMOUS_ENABLED=true
      - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
    depends_on:
      - gateway
    entrypoint:
      - sh
      - -euc
      - |
        mkdir -p /etc/grafana/provisioning/datasources
        cat <<EOF > /etc/grafana/provisioning/datasources/ds.yaml
        apiVersion: 1
        datasources:
          - name: Loki
            type: loki
            access: proxy
            url: http://gateway:3100
            jsonData:
              httpHeaderName1: "X-Scope-OrgID"
            secureJsonData:
              httpHeaderValue1: "tenant1"
        EOF
        /run.sh
    ports:
      - "3000:3000"
    networks:
      - loki
 
  gateway:
    logging:
      <<: *logging
    image: nginx:latest
    depends_on:
      - read
      - write
    entrypoint:
      - sh
      - -euc
      - |
        cat <<EOF > /etc/nginx/nginx.conf
        user  nginx;
        worker_processes  5;  ## Default: 1
 
        events {
          worker_connections   1000;
        }
 
        http {
          resolver 127.0.0.11;
 
          server {
            listen             3100;
 
            location = / {
              return 200 'OK';
              auth_basic off;
            }
 
            location = /api/prom/push {
              proxy_pass       http://write:3100\$$request_uri;
            }
 
            location = /api/prom/tail {
              proxy_pass       http://read:3100\$$request_uri;
              proxy_set_header Upgrade \$$http_upgrade;
              proxy_set_header Connection "upgrade";
            }
 
            location ~ /api/prom/.* {
              proxy_pass       http://read:3100\$$request_uri;
            }
 
            location = /loki/api/v1/push {
              proxy_pass       http://write:3100\$$request_uri;
            }
 
            location = /loki/api/v1/tail {
              proxy_pass       http://read:3100\$$request_uri;
              proxy_set_header Upgrade \$$http_upgrade;
              proxy_set_header Connection "upgrade";
            }
 
            location ~ /loki/api/.* {
              proxy_pass       http://read:3100\$$request_uri;
            }
          }
        }
        EOF
        /docker-entrypoint.sh nginx -g "daemon off;"
    ports:
      - "3100:3100"
    networks:
      - loki
  • 安装loki docker log driver
    注意使用新版本的docker desktop 可能会有问题,解决方法是自己购进啊一个
 
docker plugin install  grafana/loki-docker-driver:main --alias loki-compose --grant-all-permissions

使用

  • 启动服务
docker-compose up- d

 

 


 

 

说明

新版本loki 的模式是越来越简单了,我们只需要一个minio (s3) 就可以方便的部署了,

参考资料

https://grafana.com/docs/loki/latest/fundamentals/architecture/#modes-of-operation
https://grafana.com/docs/loki/latest/release-notes/v2-4/
https://github.com/rongfengliang/grafana-loki-learning

posted on 2022-02-19 20:09  荣锋亮  阅读(638)  评论(0编辑  收藏  举报

导航