loki 收集docker swarm日志
目录
参考自
https://github.com/swarmstack/loki
https://www.yuque.com/wangtao-7pwni/ivs01l/eyavpl
思路
1. loki 收集docker swarm的日志需要给docker daemon安装一个loki plugin ,docker daemon将会把日志推送给loki服务
2. grafana上安装Loki源 来展示数据
步骤
启动一个loki服务
1. 下载配置文件
wget https://raw.githubusercontent.com/grafana/loki/v1.5.0/cmd/loki/loki-local-config.yaml -O loki-config.yaml
2. 启动loki服务 (在172.16.2.176节点上)
docker run --name loki -v /root/deploy/loki/loki-config.yaml:/mnt/config/loki-config.yaml -p 3100:3100 --restart=always -d grafana/loki:1.5.0 -config.file=/mnt/config/loki-config.yaml
在docker swarm 的每个node上安装loki插件
docker plugin install grafana/loki-docker-driver:latest --alias loki
修改docker配置文件 /etc/docker/daemon.json
{
"debug": true,
"log-driver": "loki",
"log-opts": {
"loki-url": "http://172.16.2.176:3100/loki/api/v1/push",
"max-size": "50m",
"max-file": "10"
},
"insecure-registries" : ["172.16.2.176:5000"],
"registry-mirrors": ["https://pqbap4ya.mirror.aliyuncs.com"]
}
重启docker swarm各个节点
如果docker swarm集群上已经有容器了,可以先驱逐容器,如果没有可以直接重启docker daemon进程
1. 驱逐容器
docker node update --availability drain ${nodeId}
2. 重启对应docker
systemctl daemon-reload
systemctl restart docker
gafana安装
1. docker-compose.yaml文件
version: "3"
services:
grafana:
image: grafana/grafana:master
ports:
- 3000:3000
deploy:
restart_policy:
condition: on-failure
placement:
constraints: [node.hostname == app01]
2. 启动
docker stack deploy -c docker-compose.yaml grafana