GLP(Grafana+Loki+Promtail) 轻量日志中心搭建

Loki 部分

# 下载安装包

# 安装到一台单独的主机作为收集器服务端

# 安装到一台单独的主机作为收集器服务端
wget "https://github.com/grafana/loki/releases/download/v2.7.3/loki-linux-amd64.zip"
unzip "loki-linux-amd64.zip"
chmod a+x "loki-linux-amd64"

# 配置文件 loki.yaml

auth_enabled: false

server:
  http_listen_port: 9099
  grpc_listen_port: 9096


# 限制使用资源
resources:
  limits:
    cpu: 2000m
    memory: 5000Mi

common:
  path_prefix: /app/loki
  storage:
    filesystem:
      chunks_directory: /app/loki/chunks
      rules_directory: /app/loki/rules
  replication_factor: 1
  ring:
    instance_addr: 127.0.0.1
    kvstore:
      store: inmemory

query_range:
  results_cache:
    cache:
      embedded_cache:
        enabled: true
        max_size_mb: 100

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

ruler:
  alertmanager_url: http://192.168.0.1:9098

# 限流配置
limits_config:
  enforce_metric_name: false
  reject_old_samples: true
  reject_old_samples_max_age: 168h
  # 每秒采样率大小限制,默认值为4M
  ingestion_rate_mb: 10
  # 突发采样率大小限制,默认值为6M
  ingestion_burst_size_mb: 20  
  
# 数据表管理
table_manager:
  retention_deletes_enabled: true
  # 超出自动清理
  retention_period: 14d

# 块清理
chunk_store_config:
  max_look_back_period: 14d

# 启动 loki

nohup ./loki-linux-amd64 -config.file=loki.yaml > /app/loki/logs/loki.log 2>&1 &

# 访问测试

http://192.168.0.1:3100/metrics

Promtail 部分

# 安装包下载

# 安装到每个要采集的目标主机作为收集器的客户端

?wget https://github.com/grafana/loki/releases/download/v2.7.2/promtail-linux-amd64.zip

unzip "promtail-linux-amd64"

chmod a+x "promtail-linux-amd64"
?

# 配置文件 promtail.yaml

server:
  http_listen_port: 9080
  grpc_listen_port: 0

positions:
  filename: /app/promtail/positions.yaml
  sync_period: 5s

clients:
  - url: http://192.168.0.1:9099/loki/api/v1/push

scrape_configs:
  - job_name: system
    static_configs:
    - targets:
        - 192.168.0.1 
      labels:
        job: varlogs
        host: 192.168.0.1
        __path__: /var/log/*log

# 启动 promtail

cd /data/promtail

nohup ./promtail-linux-amd64 --config.file=promtail.yaml > /app/promtail/logs/promtail.log 2>&1 &

# 测试

http://192.168.0.1:9080/service-discovery

Grafana 部分

# 安装包下载

?
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.3.6-1.x86_64.rpm

yum --installroot=/app/grafana/ install grafana-enterprise-9.3.6-1.x86_64.rpm

yum install grafana-enterprise-9.3.6-1.x86_64.rpm

?

# 重新启动

systemctl restart grafana-server

# 测试地址

http://192.168.0.1:3000