[Why] I use a fluentd to collect docker logs, and use three output plugins:stdout/es/mq. But when I use them at the same time, will meet some problems. This fluentd will be very slow. Logs will be stacked. Another problem is that dockerd always sends logs to the same worker of fluentd.The multi-process function of fluentd can't work. [How] Change the architecture. A fluentd collects docker logs, do stdout and forward logs to master-fluentd. master-fluentd send logs to es and mq. Like this: |-----------| |--------|--> stdout |--------------|---> es |docker logs| --> |fluentd | |master-fluentd| |-----------| |--------|--> forword---> |--------------|---> mq
Signed-off-by: Wu Zhende wuzhende666@163.com --- container/master-fluentd/Dockerfile | 6 +++ container/master-fluentd/build | 6 +++ container/master-fluentd/build-depends | 1 + container/master-fluentd/docker-fluentd.conf | 48 ++++++++++++++++++++ container/master-fluentd/start | 26 +++++++++++ 5 files changed, 87 insertions(+) create mode 100644 container/master-fluentd/Dockerfile create mode 100755 container/master-fluentd/build create mode 100755 container/master-fluentd/build-depends create mode 100644 container/master-fluentd/docker-fluentd.conf create mode 100755 container/master-fluentd/start
diff --git a/container/master-fluentd/Dockerfile b/container/master-fluentd/Dockerfile new file mode 100644 index 0000000..192ece3 --- /dev/null +++ b/container/master-fluentd/Dockerfile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. + +FROM fluentd-base:alpine + +COPY --chown=1090:1090 docker-fluentd.conf /fluentd/etc/docker-fluentd.conf diff --git a/container/master-fluentd/build b/container/master-fluentd/build new file mode 100755 index 0000000..7d0291d --- /dev/null +++ b/container/master-fluentd/build @@ -0,0 +1,6 @@ +#!/usr/bin/env ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true + +system 'docker build -t master-fluentd:alpine .' diff --git a/container/master-fluentd/build-depends b/container/master-fluentd/build-depends new file mode 100755 index 0000000..29ee9d3 --- /dev/null +++ b/container/master-fluentd/build-depends @@ -0,0 +1 @@ +fluentd-base diff --git a/container/master-fluentd/docker-fluentd.conf b/container/master-fluentd/docker-fluentd.conf new file mode 100644 index 0000000..ef97d5c --- /dev/null +++ b/container/master-fluentd/docker-fluentd.conf @@ -0,0 +1,48 @@ +<system> + workers 10 +</system> + +<source> + @type forward + bind 0.0.0.0 +</source> + +<match **> + @type copy + + <store> + @type elasticsearch + host 172.17.0.1 + port 9202 + suppress_type_name true + flush_interval 1s + index_name ${tag} + ssl_verify false + log_es_400_reason true + with_transporter_log true + </store> + + <store> + @type rabbitmq + host 172.17.0.1 + exchange logging-test + exchange_type fanout + exchange_durable false + heartbeat 10 + <format> + @type json + </format> + </store> +</match> + +<label @FLUENT_LOG> + <match fluent.*> + @type stdout + <format> + @type stdout + output_type single_value + message_key message + add_newline true + </format> + </match> +</label> diff --git a/container/master-fluentd/start b/container/master-fluentd/start new file mode 100755 index 0000000..9e02980 --- /dev/null +++ b/container/master-fluentd/start @@ -0,0 +1,26 @@ +#!/usr/bin/env ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true + +require_relative '../defconfig.rb' + +docker_rm "master-fluentd" + +cmd = %w[ + docker run + --restart=always + --name master-fluentd + -v /etc/localtime:/etc/localtime:ro + -d + -u 1090:1090 + -p 24225:24224/tcp + -p 24225:24224/udp + -e FLUENTD_CONF=docker-fluentd.conf + --log-driver json-file + --log-opt max-size=1g + master-fluentd:alpine +] +cmd += ['sh', '-c', 'umask 002 & fluentd -c /fluentd/etc/docker-fluentd.conf'] + +system(*cmd)