使用轻量化loki 代替elk

/ 默认分类 / 没有评论 / 487浏览

安装

1.promtail-linux-amd64

作用是采集服务器本地日志,推送给loki服务;

promtail-local-config.yaml,可采集多个日志目录;

server:
  http_listen_port: 9080
  grpc_listen_port: 0

positions:
  filename: /tmp/positions.yaml

clients:
  - url: http://172.17.194.14:3100/loki/api/v1/push

scrape_configs:
- job_name: tomcat-1
  static_configs:
  - targets:
      - localhost
    labels:
      job: varlogs
      __path__: /opt/tomcat/tomcat-1/logs/renren/*
- job_name: tomcat-2
  static_configs:
  - targets:
      - localhost
    labels:
      job: varlogs
      __path__: /opt/tomcat/tomcat-2/logs/renren/*
nohup ./promtail-linux-amd64 --config.file=promtail-local-config.yaml &

2.loki-linux-amd64

收集promtail推送来的日志数据,汇总整合;

loki-local-config.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: 127.0.0.1
    kvstore:
      store: inmemory

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

ruler:
  alertmanager_url: http://localhost:9093

limits_config:
  enforce_metric_name: false
  reject_old_samples: true
  reject_old_samples_max_age: 168h
  #接收每次日志大小限制,太低则promtail会报错推送失败
  ingestion_rate_mb: 8
nohup ./loki-linux-amd64 --config.file=loki-local-config.yaml &

3.grafana-enterprise-8.5.0-1.x86_64

默认端口为3000

新版如果使用nginx进行代理,需要以下转发配置,否则报资源安全错误;

    location / {
       proxy_set_header Host $http_host; 
       proxy_pass http://localhost:3000;
    }