Grafana loki配置, 无脑版

使用docker部署Grafana +loki

1.创建 docker-compose.yml 文件
stylus 复制代码
touch docker-compose.yml

写入以下内容 vim touch docker-compose.yml

yaml 复制代码
version: "3"
 
networks:
  loki:
 
services:
  loki:
    image: grafana/loki:latest
    restart: unless-stopped
    ports:
      - "3100:3100"
    volumes:
      - ./config/loki/:/etc/loki/
    command: -config.file=/etc/loki/local-config.yaml
    networks:
      - loki
 
 
  grafana:
    image: grafana/grafana:latest
    ports:
      - "3000:3000"
    networks:
      - loki
2.同目录创建 config/loki/local-config.yaml , 是用来配置loki的
stylus 复制代码
touch config/loki/local-config.yaml

写入配置 vim config/loki/local-config.yaml

yaml 复制代码
auth_enabled: false
 
server:
  http_listen_port: 3100
 
common:
  path_prefix: /loki
  storage:
    filesystem:
      chunks_directory: /loki/chunks
      rules_directory: /loki/rules
  replication_factor: 1
  ring:
    kvstore:
      store: inmemory
 
schema_config:
  configs:
    - from: 2020-10-24
      store: boltdb-shipper
      object_store: filesystem
      schema: v11
      index:
        prefix: index_
        period: 24h
3.启动 docker-compose up -d
4.如果是云服务器, 需要开放 3100, 3000端口
5.需要收集日志的机器, 因为无法使用docker, 手动安装promtail

下载地址https://github.com/grafana/loki/releases, 最新版, 选择 promtail-linux-amd64

使用解压得得到一个可执行文件

stylus 复制代码
unzip promtail-linux-amd64.zip

创建配置文件config.yaml 用于promtail

复制代码
touch config.yaml

写入配置, 修改带注释的位置就行了

yaml 复制代码
server:
  http_listen_port: 9080
  grpc_listen_port: 0
 
positions:
  filename: /tmp/positions.yaml
 
clients:
  - url: http://ip:3100/loki/api/v1/push #部署loki的ip
 
scrape_configs:
- job_name: web
  static_configs:
  - targets:
      - localhost
    labels:
      job: web-varlogs
      __path__: /var/log/*log
 
- job_name: web
  static_configs:
  - targets:
      - localhost
    labels:
      job: collection_log      #任务名
      __path__: /xxxx/log.log  #需要收集的日志的路径

promtail的日志记录, 我记录在home目录下

stylus 复制代码
touch /home/promtail.log

启动promtail

stylus 复制代码
nohup ./promtail-linux-amd64 -config.file=./config.yaml  > /home/promtail.log 2>&1 &

查看进程是否启动

stylus 复制代码
ps -ef|grep promtail
6.登录grafana

​ 地址为服务的 ip:3000

​ 账号密码都是 admin

配置loki

在connection -----> data source -->输入loki

配置成功后, 在explore中, 选择刚刚的loki

点击Label browser --->选择logfile, 选择job --->show log 就可以看到日志了

相关推荐
飞翔沫沫情6 小时前
Prometheus 监控 ESXi 实战
grafana·prometheus·esxi·vcenter 监控·vsphere 监控
goodlook01232 天前
监控平台搭建-日志-alloy篇(八)
grafana·prometheus
goodlook01232 天前
监控平台搭建-日志-springboot直接推送loki篇(九)
java·spring boot·后端·grafana
新钛云服2 天前
Grafana Polystat面板与腾讯云可观测平台的深度融合实践
大数据·云计算·腾讯云·grafana
flying robot3 天前
Prometheus[2.33.3]grafana[12.3.1]监控安装
grafana·prometheus
flying robot3 天前
Grafana对xx-export监控和AlertManager 告警
grafana
一只懒鱼a6 天前
Prometheus和Grafana的安装和使用
grafana·prometheus
YanDDDeat6 天前
Prometheus + Grafana 搭建应用监控体系
java·后端·eureka·grafana·prometheus
goodlook01236 天前
监控平台搭建-日志-loki篇-最新版3.6.3(七)
服务器·grafana·prometheus
世界尽头与你6 天前
CVE-2025-4123_ Grafana 安全漏洞
安全·网络安全·渗透测试·grafana