1、Docker安装

参考:https://www.cnblogs.com/a120608yby/p/9883175.html

2、Docker Compose安装

参考:https://www.cnblogs.com/a120608yby/p/14582853.html

3、服务配置

# vim docker-compose.yaml
version: "3.8"

services:
  loki:
    image: grafana/loki:2.7.4
    container_name: loki
    restart: always
    ports:
      - "3100:3100"
    networks:
      - ops_default
    command: -config.file=/etc/loki/local-config.yaml

  promtail:
    image: grafana/promtail:2.7.4
    container_name: promtail
    restart: always
    networks:
      - ops_default
    volumes:
      - /var/log:/var/log
    command: -config.file=/etc/promtail/config.yml

  grafana:
    image: grafana/grafana:latest
    container_name: grafana
    restart: always
    networks:
      - ops_default
    ports:
      - "3000:3000"

networks:
  ops_default:
    external: true

4、启动服务

docker-compose up -d

5、查看服务启动状态

docker-compose ps

6、docker容器日志接入到Loki

# 安装插件
docker plugin install grafana/loki-docker-driver:latest --alias loki --grant-all-permissions

# 查看插件
docker plugin ls

# 更新插件
docker plugin disable loki --force
docker plugin upgrade loki grafana/loki-docker-driver:latest --grant-all-permissions
docker plugin enable loki
systemctl restart docker

# 卸载插件
docker plugin disable loki --force
docker plugin rm loki

7、服务docker-compose配置

version: '3.9'

x-logging:
  &loki-logging
  driver: loki
  options:
    loki-url: "http://172.16.1.100:3100/loki/api/v1/push"
    max-size: "300m"
    max-file: "10"

services:
  demo:
    image: reg.istack.com/demo/demo:latest
    container_name: demo
    restart: always
    network_mode: host
    logging: *loki-logging
    command:
      "java -Xms512m -Xmx1024m -Djava.security.egd=file:/dev/./urandom -Dfile.encoding=utf-8 -Dspring.profiles.active=dev -jar app.jar"

参考:

https://grafana.com/docs/loki/latest/installation/docker/
https://grafana.com/docs/loki/latest/clients/docker-driver/

  

posted on 2023-03-01 15:30  a120608yby  阅读(1035)  评论(0编辑  收藏  举报