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+Grafana知识梳理(2)
grafana·prometheus
打工仔折腾 AI7 天前
多台服务器日志分散难查?用Promtail+Loki+Grafana搭建集中检索平台
服务器·人工智能·后端·python·性能优化·django·grafana
蓝胖的四次元口袋9 天前
Prometheus+Grafana知识梳理(1)
grafana·prometheus
哈__10 天前
日志散在多台服务器怎么查?用 Promtail + Loki + Grafana 搭一套集中检索平台
运维·服务器·grafana
DylanlZhao22 天前
我想看看本地 LLM 给我省了多少钱,于是我监控了它
llm·grafana
天天喝旺仔24 天前
Prometheus + Grafana 监控告警体系搭建实战:从 Exporter 指标采集、PromQL 查询到 Alertmanager 告警落地
容器·kubernetes·grafana·prometheus·时序数据库
qq_452396231 个月前
第十二篇:《数据采集:Grafana Alloy、Fluent Bit、Vector 的选型与配置》
java·贪心算法·grafana
2601_962097361 个月前
可观测性实战:Prometheus+Grafana+OTel构建监控
grafana·prometheus·微服务架构·可观测性·opentelemetry
Joker-Full-stack1 个月前
higress Grafana生产事故复盘:Loki 2.9 WAL 竞态 Bug 导致 5 天审计日志消失
bug·grafana·higress
IT界的老黄牛1 个月前
Jenkins 监控一条龙:接入、看板 9964、11 条告警规则直接抄走
jenkins·grafana·prometheus·监控·ci-cd·告警规则