创建一个Service
[ini]
root@localhost:~# docker service create –replicas 1 -p 8004:8000 –name temp01 –log-driver=fluentd \
–log-opt tag=”docker.{{.Name}}” –log-opt fluentd-async-connect=true \
imekaku/simple-web python /work/simple.py
ckccpo6wy0ovoazxfzdf01zrq
# match的tag如下
matched tag=”docker.temp01.1.ckccpo6wy0ovoazxfzdf01zrq”
[/ini]
客户端对应的fluentd配置文件
# 几乎没有变化,只是对应的swarm多的tag字段需要做相应的匹配 <source> type forward port 24224 bind 0.0.0.0 </source> <match docker.*.*.*> type rewrite_tag_filter rewriterule1 source stdout out.${tag} rewriterule2 source stderr err.${tag} </match> # 使用输出 <match out.docker.*.*.*> type forward <server> host 192.168.126.136 port 24224 </server> flush_interval 5s </match> <match err.docker.*.*.*> type forward <server> host 192.168.126.136 port 24224 </server> flush_interval 5s </match>
服务器端fluentd配置
<source> type forward port 24224 bind 0.0.0.0 </source> <match err.docker.*.*.*> type forest subtype file <template> output_tag false output_time false message_key log format single_value path /home/lee/fluentd-log/err/${tag_parts[2]}/temp </template> </match> <match out.docker.*.*.*> type forest subtype file <template> output_tag false output_time false message_key log format single_value path /home/lee/fluentd-log/out/${tag_parts[2]}/temp </template> </match>