我没有找到一种正确有效的方法来通过 docker 环境中的 Fluentd 从 Spring Boot docker 收集日志到 Elasticsearch。我的配置如下
spring-boot jar 的 Dockerfile:
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/user-management.jar
EXPOSE 10010
COPY ${JAR_FILE} user-management.jar
ENTRYPOINT ["java", "-jar", "user-management.jar"]
Logback 配置- logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder"/>
</appender>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>/var/log/tests.log</file>
<encoder class="net.logstash.logback.encoder.LogstashEncoder"/>
</appender>
<logger name="jsonLogger" level="DEBUG">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="com.xyz.usermanagement" level="DEBUG">
<appender-ref ref="FILE" />
</logger>
<root level="INFO">
<appender-ref ref="CONSOLE"/>
</root>
</configuration>
Fluentd 配置- fluent.conf
<source>
@type forward
port 24224
bind 0.0.0.0
</source>
<label @FLUENT_LOG>
<match *.**>
@type copy
<store>
@type elasticsearch
host elasticsearch
port 9200
logstash_format true
logstash_prefix fluentd
logstash_dateformat %Y%m%d
include_tag_key true
type_name access_log
tag_key @log_name
flush_interval 5s
</store>
<store>
@type stdout
</store>
</match>
</label>
下面是我用来构建服务的 docker-compose
version: '3.8'
services:
elasticsearch:
container_name: elasticsearchsrvc
image: elasticsearch:7.10.1
environment:
- "discovery.type=single-node"
- xpack.security.enabled=false
volumes:
- elasticsearchdata:/usr/share/elasticsearch/data
networks:
- microservicesntwrk
ports:
- 9200:9200
fluentd:
container_name: fluentdsrvc
image: fluentdimg:0.0.1
build:
context: ../fluentd/
volumes:
- ./fluentd/conf:/fluentd/etc
networks:
- microservicesntwrk
ports:
- 24224:24224
kibana:
container_name: kibanasrvc
image: kibana:7.10.1
environment:
- ELASTICSEARCH_HOSTS=http://elasticsearchsrvc:9200
networks:
- microservicesntwrk
depends_on:
- elasticsearch
ports:
- 5601:5601
usermanagement:
container_name: usermanagementsrvc
image: usermanagementimg:0.0.1
build:
context: ../business/user-management
depends_on:
- fluentd
ports:
- 10010:10010
networks:
- microservicesntwrk
volumes:
elasticsearchdata:
driver: local
networks:
microservicesntwrk:
driver: bridge
name: microservicesntwrk
我能够在弹性搜索中看到 Fluentd 服务生成的日志,但看不到用户管理(Spring-Boot)docker 容器生成的日志。
对此的任何方向表示赞赏,谢谢。