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
用容器运行fluentd
镜像 :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:
配置文件fluentd.conf:
Eg:
<source>
@type forward
</source>
<match docker.**>
@type stdout
</match>
指令:http://docs.fluentd.org/articles/config-file
1. source :input sources.
Eg:
#Receive events from 24224/tcp
#This is used by log forwarding and the fluent-cat command
<source>
@type forward
port 24224
</source>
#http://this.host:9880/myapp.access?json={"event":"data"}
<source>
@type http
port 9880
</source>
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.
<matchmyapp.access>
@type file
path /var/log/fluent/access
</match>
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"