fluentd
Fluentdcollects events from various data sources and writes them to files.
Ruby 环境 version>2.0 (ruby安装https://www.rubylang.org/en/documentation/installation/)
$ gem install fluentd
$ fluentd -s conf
$ fluentd -c conf/fluent.conf &
$ echo '{"json":"message"}' |fluent-cat debug.test
镜像 :dockerpull fluent/fluentd
Dockerfile: https://github.com/fluent/fluentd-docker-image
运行:docker run -d -p24224:24224 -v /data:/fluentd/log fluent/fluentd
容器启动指定fluentd作为loging-griver
docker run -dit \
--log-driver=fluentd \
--log-opt fluentd-address=localhost:24224 \
--log-opt tag="docker.{{.Name}}"\
ubuntu:14.04 sh
配置文件fluentd.conf:
Eg:
@type forward
@type stdout
1. source :input sources.
Eg:
#Receive events from 24224/tcp
#This is used by log forwarding and the fluent-cat command
@type forward
port 24224
#http://this.host:9880/myapp.access?json={"event":"data"}
@type http
port 9880
2. match : outputdestinations.
Eg:
#Match events tagged with "myapp.access" and
# storethem to /var/log/fluent/access.%Y-%m-%d
# Ofcourse, you can control how you partition your data
#with the time_slice_format option.
@type file
path /var/log/fluent/access
3. filter :event processing pipelines.
4. system :set system wide configuration.
5. label : group theoutput and filter for internal routing
6. @include : include other files to reuseconfigfile
docker run -it -p 24224:24224 -v ./conf/test.conf:/fluentd/etc -eFLUENTD_CONF=test.conf fluent/fluentd:ubuntu-base
docker exec -it fluentd /bin/bash
echo '{"json":"message"}' | fluent-catdebug.test
docker run --log-driver=fluentd --log-optfluentd-address=127.0.0.1:24224 busybox echo "Hello Fluentd"
docker run --log-driver=fluentd --log-opt fluentd-address=192.168.0.142:24224 busybox echo"Hello Fluentd"