SpringBoot(57)整合Plumelog实现日志查询-创新互联
文章目录
网站标题:SpringBoot(57)整合Plumelog实现日志查询-创新互联
网站路径:http://myzitong.com/article/eedjh.html
- 一、前言
- 二、docker-compose一键搭建日志服务
- docker-compose.yml
- 三、SpringBoot整合Plumelog
- 1、`pom.xml`
- 2、`application.yml`
- 3、`logback-spring.xml`
- 4、启动项目记录日志
- 四、本文案例demo源码
Plumelog 一个简单易用的java分布式日志组件
二、docker-compose一键搭建日志服务https://gitee.com/plumeorg/plumelog
plumelog
+elasticsearch
+redis
tips: 详情可查看 https://gitee.com/zhengqingya/docker-compose
# 准备
git clone https://gitee.com/zhengqingya/docker-compose.git
cd docker-compose/Linux/plumelog
# 运行
docker-compose -f docker-compose.yml -p plumelog up -d
# 当前目录下所有文件赋予权限(读、写、执行) -- 解决es启动报错问题...
chmod -R 777 ./app/elasticsearch
- 访问地址:ip地址:8891
- 账号:admin
- 密码:admin
version: "3"
# 网桥 ->方便相互通讯
networks:
plumelog:
ipam:
driver: default
config:
- subnet: "172.23.0.0/24"
services:
plumelog:
image: registry.cn-hangzhou.aliyuncs.com/zhengqing/plumelog:3.5.3
container_name: plumelog
restart: unless-stopped
volumes:
# 引用外部配置文件 ex: es,redis (配置也可通过 -e 去修改)
- ./app/plumelog/application.properties:/home/application.properties
environment: # 设置环境变量,相当于docker run命令中的-e
TZ: Asia/Shanghai
LANG: en_US.UTF-8
JAVA_OPTS: "-XX:+UseG1GC -Dspring.config.location=/home/application.properties,classpath:application.properties,"
plumelog.queue.redis.redisHost: 172.23.0.33:6379
plumelog.redis.redisHost: 172.23.0.33:6379
plumelog.es.esHosts: 172.23.0.22:9200
ports:
- "8891:8891"
depends_on:
- elasticsearch
- redis
networks:
plumelog:
ipv4_address: 172.23.0.11
elasticsearch:
image: registry.cn-hangzhou.aliyuncs.com/zhengqing/elasticsearch:7.14.1 # 原镜像`elasticsearch:7.14.1`
container_name: plumelog_elasticsearch # 容器名为'elk_elasticsearch'
restart: unless-stopped # 指定容器退出后的重启策略为始终重启,但是不考虑在Docker守护进程启动时就已经停止了的容器
volumes: # 数据卷挂载路径设置,将本机目录映射到容器目录
- "./app/elasticsearch/data:/usr/share/elasticsearch/data"
- "./app/elasticsearch/logs:/usr/share/elasticsearch/logs"
- "./app/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml"
# - "./app/elasticsearch/config/jvm.options:/usr/share/elasticsearch/config/jvm.options"
environment: # 设置环境变量,相当于docker run命令中的-e
TZ: Asia/Shanghai
LANG: en_US.UTF-8
discovery.type: single-node
ES_JAVA_OPTS: "-Xmx512m -Xms512m"
ELASTIC_PASSWORD: "123456" # elastic账号密码
ports:
- "9200:9200"
- "9300:9300"
networks:
plumelog:
ipv4_address: 172.23.0.22
redis:
image: registry.cn-hangzhou.aliyuncs.com/zhengqing/redis:7.0.5 # 镜像'redis:7.0.5'
container_name: plumelog_redis # 容器名为'redis'
restart: unless-stopped # 指定容器退出后的重启策略为始终重启,但是不考虑在Docker守护进程启动时就已经停止了的容器
command: redis-server /etc/redis/redis.conf --requirepass 123456 --appendonly no # 启动redis服务并添加密码为:123456,默认不开启redis-aof方式持久化配置
# command: redis-server --requirepass 123456 --appendonly yes # 启动redis服务并添加密码为:123456,并开启redis持久化配置
environment: # 设置环境变量,相当于docker run命令中的-e
TZ: Asia/Shanghai
LANG: en_US.UTF-8
volumes: # 数据卷挂载路径设置,将本机目录映射到容器目录
- "./app/redis/data:/data"
- "./app/redis/config/redis.conf:/etc/redis/redis.conf" # `redis.conf`文件内容`http://download.redis.io/redis-stable/redis.conf`
ports: # 映射端口
- "6379:6379"
networks:
plumelog:
ipv4_address: 172.23.0.33
三、SpringBoot整合Plumelog
1、pom.xml
com.plumelog plumelog-logback 3.5.3
2、application.yml
spring:
profiles:
active: dev
# 配置日志地址
logging:
config: classpath:logback-spring.xml
plumelog:
appName: plumelog_demo
# 需要和plumelog服务端的redis配置一致
redisHost: 127.0.0.1:6379
redisAuth: 123456
redisDb: 10
3、logback-spring.xml
${plumelog.appName} ${plumelog.redisHost} ${plumelog.redisAuth} ${plumelog.redisDb} ${plumelog.env}
4、启动项目记录日志访问plumelog的ui界面查看日志
四、本文案例demo源码https://gitee.com/zhengqingya/java-workspace
今日分享语句:
我一定会加油,直追我的目标,有些该放弃的我会放弃,再也不会幻想了,未来的日子,我想你一样,坚强,达到我想要的目标!
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
网站标题:SpringBoot(57)整合Plumelog实现日志查询-创新互联
网站路径:http://myzitong.com/article/eedjh.html