Loki 部署

_N.x Blog

使用 Docker

Loki

这里直接下载官方默认配置,具体参数怎么修改参考官方文档

https://raw.githubusercontent.com/grafana/loki/v3.4.1/cmd/loki/loki-local-config.yaml

将以下命令复制并粘贴到命令行中,以使用在上一步中下载的配置文件启动 Docker 容器。

1
2
3
4
5
docker run --name loki -d \
-v /path/to/config:/mnt/config \
-p 3100:3100 \
grafana/loki:3.4.1 \
-config.file=/mnt/config/loki-config.yaml

Promtail

逐步会被alloy替代,这里测试还是继续使用promtail

配置说明 promtail-config.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# This minimal config scrape only single log file.
# Primarily used in rpm/deb packaging where promtail service can be started during system init process.
# And too much scraping during init process can overload the complete system.
# https://github.com/grafana/loki/issues/11398

server:
http_listen_port: 9080
grpc_listen_port: 0

positions:
filename: /tmp/positions.yaml

clients:
- url: http://172.17.0.180:3100/loki/api/v1/push # change loki address

scrape_configs:
- job_name: system
static_configs:
- targets:
- localhost
labels:
job: varlogs # change job name
host: 172.17.0.172
__path__: /var/log/messages # change log path
- targets:
- localhost
labels:
job: auditlogs
host: 172.17.0.172
__path__: /var/log/audit/audit.log
- targets:
- localhost
labels:
job: nginxlogs
host: 172.17.0.172
__path__: /var/log/nginx/access.log
- targets:
- localhost
labels:
job: securelogs
host: 172.17.0.172
__path__: /var/log/secure

启动promtail容器采集日志

1
2
3
4
5
docker run --name promtail -d \
-v /path/to/config:/mnt/config \
-v /var/log:/var/log \
grafana/promtail:3.4.1 \
-config.file=/mnt/config/promtail-config.yaml

Grafana

Grafana部署

导入Loki数据源http://localhost:3100,点击Save and Test

左上角菜单 -> Drilldown -> Logs 即可看到日志数据


Loki

  • Title: Loki 部署
  • Author: _N.x Blog
  • Created at : 2026-01-09 11:46:34
  • Updated at : 2026-01-12 06:06:58
  • Link: https://zengy.win/2026/01/09/Loki-部署/
  • License: This work is licensed under CC BY-NC-SA 4.0.
On this page
Loki 部署