我已经使用docker启动了Fluentd服务器。我的Fluentd配置是
<source>
@type syslog
port 514
bind 0.0.0.0
tag system
</source>
<match **>
@type stdout
</match>
我用来启动
fluentd
服务器的命令是
docker run -p 514:514 -v $(pwd)/tmp:/fluentd/etc fluent/fluentd:edge-debian -c /fluentd/etc/fluentd.conf
它成功启动了服务器,我得到了日志
2023-09-20 16:05:18 +0000 [info]: init supervisor logger path=nil rotate_age=nil rotate_size=nil
2023-09-20 16:05:18 +0000 [info]: parsing config file is succeeded path="/fluentd/etc/fluentd.conf"
2023-09-20 16:05:18 +0000 [info]: gem 'fluentd' version '1.16.2'
2023-09-20 16:05:18 +0000 [warn]: define <match fluent.**> to capture fluentd logs in top level is deprecated. Use <label @FLUENT_LOG> instead
2023-09-20 16:05:18 +0000 [info]: using configuration file: <ROOT>
<source>
@type syslog
port 514
bind "0.0.0.0"
tag "system"
</source>
<match **>
@type stdout
</match>
</ROOT>
2023-09-20 16:05:18 +0000 [info]: starting fluentd-1.16.2 pid=7 ruby="3.1.4"
2023-09-20 16:05:18 +0000 [info]: spawn command to main: cmdline=["/usr/local/bin/ruby", "-Eascii-8bit:ascii-8bit", "/usr/local/bundle/bin/fluentd", "-c", "/fluentd/etc/fluentd.conf", "--plugin", "/fluentd/plugins", "--under-supervisor"]
2023-09-20 16:05:19 +0000 [info]: #0 init worker0 logger path=nil rotate_age=nil rotate_size=nil
2023-09-20 16:05:19 +0000 [info]: adding match pattern="**" type="stdout"
2023-09-20 16:05:19 +0000 [info]: adding source type="syslog"
2023-09-20 16:05:19 +0000 [warn]: #0 define <match fluent.**> to capture fluentd logs in top level is deprecated. Use <label @FLUENT_LOG> instead
2023-09-20 16:05:19 +0000 [info]: #0 starting fluentd worker pid=16 ppid=7 worker=0
2023-09-20 16:05:19 +0000 [info]: #0 listening syslog socket on 0.0.0.0:514 with udp
2023-09-20 16:05:19 +0000 [info]: #0 fluentd worker is now running worker=0
2023-09-20 16:05:19.058192424 +0000 fluent.info: {"pid":16,"ppid":7,"worker":0,"message":"starting fluentd worker pid=16 ppid=7 worker=0"}
2023-09-20 16:05:19.058414751 +0000 fluent.info: {"message":"listening syslog socket on 0.0.0.0:514 with udp"}
2023-09-20 16:05:19.059112948 +0000 fluent.info: {"worker":0,"message":"fluentd worker is now running worker=0"}
我编写了简单的Python脚本来测试连接,如下
import logging
import logging.handlers
import socket
if __name__ == "__main__":
syslogger = logging.getLogger('SyslogLogger')
handler = logging.handlers.SysLogHandler(address=("0.0.0.0", 514), facility=19, socktype=socket.SOCK_DGRAM)
syslogger.addHandler(handler)
syslogger.info("Hello World")
脚本运行没有任何错误,但我在 fluidd 上没有收到任何日志。
服务器和脚本都位于本地计算机上。