Docker中的Fluentd无法从我的日志文件中删除
我在/var/log/logf/a.log
中的输入:
test 1st log
test 2nd log
test 3rd log
和我的配置/opt/app/conf/fluent.conf
:<source>
@type tail
path /var/log/logf/a.log
tag test
read_from_head true
<parse>
@type none
message_key test
</parse>
</source>
<match test>
@type stdout
</match>
和我的Dockerfile
id /opt/app/Dockerfile
FROM fluent/fluentd:v1.11-debian-1
USER root
COPY ./conf/fluent.conf /fluentd/etc
RUN ["gem", "install", "fluent-plugin-elasticsearch", "--no-document", "--version", "3.5.2"]
USER fluent
我运行我的Dockerfile
$ sudo docker build -t log-app .
$ sudo docker run -d --name logging log-app:latest
$ sudo docker logs -f logging
结果卡住了,我不知道为什么2020-10-26 10:24:58 +0000 [info]: parsing config file is succeeded path="/fluentd/etc/fluent.conf"
2020-10-26 10:24:58 +0000 [info]: gem 'fluent-plugin-elasticsearch' version '3.5.2'
2020-10-26 10:24:58 +0000 [info]: gem 'fluentd' version '1.11.4'
2020-10-26 10:24:58 +0000 [warn]: 'pos_file PATH' parameter is not set to a 'tail' source.
2020-10-26 10:24:58 +0000 [warn]: this parameter is highly recommended to save the position to resume tailing.
2020-10-26 10:24:58 +0000 [info]: using configuration file: <ROOT>
<source>
@type tail
path "/var/log/logf/a.log"
tag "test"
read_from_head true
<parse>
@type "none"
message_key "test"
unmatched_lines
</parse>
</source>
<match test>
@type stdout
</match>
</ROOT>
2020-10-26 10:24:58 +0000 [info]: starting fluentd-1.11.4 pid=6 ruby="2.6.6"
2020-10-26 10:24:58 +0000 [info]: spawn command to main: cmdline=["/usr/local/bin/ruby", "-Eascii- 8bit:ascii-8bit", "/usr/local/bundle/bin/fluentd", "-c", "/fluentd/etc/fluent.conf", "-p", "/fluentd/plugins", "--under-supervisor"]
2020-10-26 10:24:59 +0000 [info]: adding match pattern="test" type="stdout"
2020-10-26 10:24:59 +0000 [info]: adding source type="tail"
2020-10-26 10:24:59 +0000 [warn]: #0 'pos_file PATH' parameter is not set to a 'tail' source.
2020-10-26 10:24:59 +0000 [warn]: #0 this parameter is highly recommended to save the position to resume tailing.
2020-10-26 10:24:59 +0000 [info]: #0 starting fluentd worker pid=15 ppid=6 worker=0
2020-10-26 10:24:59 +0000 [info]: #0 fluentd worker is now running worker=0
我认为这是一个权限问题,但是我不确定,因为此Fluentd不会引发错误,您能解决这个问题吗?[已解决] 由karan shah先生的解释完全解决了
我用docker-compose和安装量解决了以下问题:
在文件
/opt/app/docker-compose.yaml
中version: '2'
services:
fluentd:
build: .
container_name: fl-logging
volumes:
- "./conf/:/fluentd/etc:ro"
- "/var/log/logf:/var/log/logf"
并运行docker compose $ sudo docker-compose up -d --build
最佳答案
问题是您尚未将本地日志文件安装到Fluentd容器中以使其可访问。
使用如下命令。sudo docker run -d --name logging -v PATHTOYOURLOGFILE:/var/log/logf/ log-app:latest
阅读有关here卷的更多信息。
您还可以使用如下所示的docker-compose文件
version: '2.2'
services:
fluentd:
build: ./opt/app/
container_name: fl01
volumes:
- "/opt/app/conf/:/fluentd/etc/:ro"
- "PATHTOYOURLOGFILE:/var/log/logf/"
networks:
- elastic
ports:
- "9880:9880"
networks:
elastic:
driver: bridge
关于docker - 流利的Docker无法从我的日志文件中消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64535572/