测试使用fluentd日志收集工具,在swarm集群中收集日志的效果,这里有3台机器,分别是134,136,138. 其中134,136作为swarm集群中的两台机器,运行一个Service,并在这两台机器上运行fluentd程序,作为fluentd客户端程序,向138上运行的fluentd服务器程序发送日志。
配置步骤
134,138,136机器配置文件,以及创建service命令
134,138作为fluentd客户端,138作为fluentd服务器:配置文件
root@lee-PC:~$ docker service create --replicas 2 -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 89bsn1yrysynz1pn56ldzlvp7 # 这样传递给fluentd的tag是:docker.ServiceName.ContainerName.ContainerID root@lee-PC:~$ docker service ls ID NAME REPLICAS IMAGE COMMAND 89bsn1yrysyn temp01 0/2 imekaku/simple-web python /work/simple.py root@lee-PC:~$ docker service ls ID NAME REPLICAS IMAGE COMMAND 89bsn1yrysyn temp01 2/2 imekaku/simple-web python /work/simple.py root@lee-PC:~$ docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS 4qe9r5u6te8isyfx0jv8y2yz6 localhost.localdomain Ready Active Reachable 9adxdgug6dreix4485bamlfbm * lee-PC Ready Active Leader root@lee-PC:~$
# 生成的日志文件目录 lee@lee-PC:fluentd-log$ ll total 16 drwxr-xr-x 4 root root 4096 Sep 22 15:53 ./ drwxr-xr-x 9 lee lee 4096 Sep 20 20:20 ../ drwxr-xr-x 3 root root 4096 Sep 22 15:53 program_200/ drwxr-xr-x 3 root root 4096 Sep 22 15:53 program_404/ lee@lee-PC:fluentd-log$ tree ./ ./ ├── program_200 │ └── temp01 │ └── t3.20160922T15_0.log └── program_404 └── temp01 └── t3.20160922T15_0.log 4 directories, 2 files
# 客户端需要安装的插件 /opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-rewrite-tag-filter /opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-grep # 服务器端需要安装的插件 /opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-forest