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 就可以看到日志了

相关推荐
Insist7533 天前
prometheus安装部署与alertmanager邮箱告警
linux·运维·grafana·prometheus
爱敲代码的TOM3 天前
Grafana+Loki+Alloy构建企业级日志平台
grafana
linux修理工4 天前
n1 ARMbian部署Grafana
arm开发·架构·grafana
_何同学7 天前
Spring Boot 监控实战:集成 Prometheus 与 Grafana,打造全方位监控体系
spring boot·grafana·prometheus
苦逼IT运维10 天前
Jenkins 监控方案:Prometheus + Grafana 实践
jenkins·grafana·prometheus
川石课堂软件测试12 天前
Oracle 数据库:视图与索引
数据库·网络协议·nginx·http·oracle·grafana·prometheus
川石课堂软件测试13 天前
Oracle 数据库如何查询列
linux·数据库·sql·功能测试·oracle·grafana·prometheus
MasterNeverDown16 天前
.NET 微服务日志系统:Serilog + Loki + Grafana 实践指南
微服务·.net·grafana
❀͜͡傀儡师17 天前
docker安装Prometheus和Grafana 监控界面
docker·grafana·prometheus
好运连连99917 天前
ubuntu promethus+grafana监控多台服务器
linux·ubuntu·grafana