一、Loki介绍与安装
- 受 Prometheus 启发的可以水平扩展、高可用以及支持多租户的日志聚合系统。
- 使用了和 Prometheus 相同的服务发现机制,将标签添加到日志流中而不是构建全文索引。
- 从 Promtail 接收到的日志和应用的 metrics 指标就具有相同的标签集。
- 不仅提供了更好的日志和指标之间的上下文切换,还避免了对日志进行全文索引。
二、官网下载路径
https://github.com/grafana/loki/releases/
三、解压tar包
/data/app/loki/loki //此目录结构为自定义,若不存在此结构可自行创建
unzip loki-linux-amd64.zip //解压
四、Loki文件夹改名
mv loki-linux-amd64 loki
五、增加配置文件loki-config.yaml
官网示例配置文件:https://github.com/grafana/loki/tree/main/cmd/loki
官网配置参数解析:https://grafana.com/docs/loki/latest/configuration/#analytics
# loki 配置
auth_enabled: false
# 指定各个服务的端口
server:
http_listen_port: 3100
grpc_listen_port: 9096
grpc_server_max_recv_msg_size: 15728640 #grpc最大接收消息值,默认4m
grpc_server_max_send_msg_size: 15728640 #grpc最大发送消息值,默认4m
# 公共块设置不同组件共享的公共定义
common:
path_prefix: /data/app/loki/loki
storage:
filesystem:
chunks_directory: /data/app/loki/loki/chunks
rules_directory: /data/app/loki/loki/rules
replication_factor: 1
ring:
instance_addr: 192.168.xxx.xx #IP地址
kvstore:
store: inmemory # 持久化方式:内存存储
schema_config:
configs:
- from: 2020-10-24
store: boltdb-shipper
object_store: filesystem # 持久化方式:本地文件
schema: v11
index:
prefix: index_
period: 24h
limits_config:
ingestion_rate_mb: 60 # 修改每用户摄入速率限制,即每秒样本量,默认值为4M
ingestion_burst_size_mb: 80 # 每个用户允许摄入的采样突发大小,单位MB,默认为6MB
retention_period: 240h # 多久过期,默认744h
ruler:
alertmanager_url: http://192.168.xxx.xx:9093 #IP + 端口
# By default, Loki will send anonymous, but uniquely-identifiable usage and configuration
# analytics to Grafana Labs. These statistics are sent to https://stats.grafana.org/
#
# Statistics help us better understand how Loki is used, and they show us performance
# levels for most users. This helps us prioritize features and documentation.
# For more information on what's sent, look at
# https://github.com/grafana/loki/blob/main/pkg/usagestats/stats.go
# Refer to the buildReport method to see what goes into a report.
#
# If you would like to disable reporting, uncomment the following lines:
#analytics:
# reporting_enabled: false
六、启动命令
nohup ./loki-linux-amd64 -config.file=./loki-config.yaml & //后台启动
PS:不懂可以自行了解nohup命令
七、查看Loki是否启动成功
ps -ef | grep loki