轻量级日志管理系统promtail+loki+grafana部署流程
一、下载
promtail+loki+grafana压缩包
"https://github.com/grafana/loki/releases/download/v1.5.0/loki-linux-amd64.zip"
"https://github.com/grafana/loki/releases/download/v1.5.0/promtail-linux-amd64.zip"
https://dl.grafana.com/enterprise/release/grafana-enterprise-8.3.3.linux-amd64.tar.gz
二、创建安装目录
- 以下目录用来存放各个组件压缩包的解压文件和配置
/usr/local/logsCollect/loki
/usr/local/logsCollect/grafana
/usr/local/logsCollect/promtail - 以下目录用来文件存储和索引存储
/data/loki/chunks
/data/loki/index
三、安装Loki
- 解压loki-linux-amd64.zip
- 修改配置loki-local-config.yaml
获取官方通用配置wget https://raw.githubusercontent.com/grafana/loki/master/cmd/loki/loki-local-config.yaml
官方文档https://grafana.com/docs/loki/latest/installation/local/
auth_enabled: false
server:
http_listen_port: 8094
ingester:
lifecycler:
address: 192.168.244.128 #日志服务器ip,即本机地址
ring:
kvstore:
store: inmemory
replication_factor: 1
final_sleep: 0s
chunk_idle_period: 5m
chunk_retain_period: 30s
schema_config:
configs:
- from: 2024-04-01
store: boltdb
object_store: filesystem
schema: v11
index:
prefix: index_
period: 168h #每张表的时间范围7天
storage_config:
boltdb:
directory: /data/loki/index #索引文件存储地址
filesystem:
directory: /data/loki/chunks #块存储地址
limits_config:
enforce_metric_name: false
reject_old_samples: true
reject_old_samples_max_age: 168h
chunk_store_config:
# 最大可查询历史日期 7天,这个时间必须是schema_config中的period的倍数,否则报错。
max_look_back_period: 168h
# 表的保留期7天
table_manager:
retention_deletes_enabled: true
retention_period: 168h
- 启动
- 命令行启动
./loki-linux-amd64 --config.file=loki-local-config.yaml - 后台运行
nohup ./loki-linux-amd64 --config.file=loki-local-config.yaml > server.log 2>&1 & - 启动脚本
#!/bin/bash
nohup ./loki-linux-amd64 -config.file=./loki-local-config.yaml >./server.log 2>&1 &
echo "$!" > pid
- 结束运行脚本
#!/bin/bash
kill -9 `cat pid`
echo "关闭成功!"
四、安装Grafana
- 解压grafana-enterprise-8.3.3.linux-amd64.tar.gz(tar -xzvf )。注意conf/defaults.ini为grafana的配置文件。
- 修改配置conf/defaults.ini
http_port 默认为3000
- 启动
- 脚本运行
#!/bin/bash
nohup ./bin/grafana-server >./server.log 2>&1 &
echo "$!" > pid
- 结束运行脚本
#!/bin/bash
kill -9 `cat pid`
echo "关闭成功!"
五、安装Promtail
- 解压promtail-linux-amd64.zip
- 配置promtail.yaml
获取通用配置wget https://raw.githubusercontent.com/grafana/loki/main/clients/cmd/promtail/promtail-local-config.yaml
官方文档https://grafana.com/docs/loki/latest/installation/local/
server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: ./positions.yaml
clients:
- url: http://192.168.244.128:8094/loki/api/v1/push #日志服务器loki地址和端口
scrape_configs:
#ucenter1
- job_name: test-log
static_configs:
- targets:
- 192.168.244.128 # 日志所在的服务器
- labels:
job: log1
host: 10.60.134.60
__path__: /app/logs/info.log #本机日志路径,支持通配符
六、浏览器进入Grafana
192.168.244.128:3000 默认账号密码admin/admin