- 使用fluentd插件聚合Apache日志
- 1. 前提提件
- 2. 安装
- 3. 步骤
- 第一步:创建存储桶。
- 第二步:修改fluentd配置以使用Minio作为存储后端。
- 第三步: 重启 fluentd server.
- 第四步: 检查fluentd的日志以确认是否一切正在运行。
- 第五步: 验证你的配置。
- 第六步: 验证聚合的日志。
使用fluentd插件聚合Apache日志
在本文中,我们将学习如何使用fluent-plugin-s3插件结合Minio做为日志聚合器。
1. 前提提件
- 从这里下载Minio Server。
- 从这里下载mc。
2. 安装
- 安装并运行Apache server 。
- 安装fluentd 和 fluent-plugin-s3。
3. 步骤
第一步:创建存储桶。
fluentd将会实时聚合半结构化apache日志到这个存储桶。
mc mb myminio/fluentdBucket created successfully ‘myminio/fluentd’.
第二步:修改fluentd配置以使用Minio作为存储后端。
将aws_key_id, aws_sec_key, s3_bucket, s3_endpoint替换为你自己的值。
将 /etc/td-agent/td-agent.conf 替换为:
<source>@type tailformat apache2path /var/log/apache2/access.logpos_file /var/log/td-agent/apache2.access.log.postag s3.apache.access</source><match>@type s3aws_key_id `aws_key_id`aws_sec_key `aws_sec_key`s3_bucket `s3_bucket`s3_endpoint `s3_endpoint`path logs/force_path_style truebuffer_path /var/log/td-agent/s3time_slice_format %Y%m%d%H%Mtime_slice_wait 10mutcbuffer_chunk_limit 256m</match>
第三步: 重启 fluentd server.
sudo /etc/init.d/td-agent restart
第四步: 检查fluentd的日志以确认是否一切正在运行。
tail -f /var/log/td-agent/td-agent.logpath logs/force_path_style truebuffer_path /var/log/td-agent/s3time_slice_format %Y%m%d%H%Mtime_slice_wait 10mutcbuffer_chunk_limit 256m</match></ROOT>2016-05-03 18:44:44 +0530 [info]: following tail of /var/log/apache2/access.log
第五步: 验证你的配置。
Ping Apache server。该示例采用ab(Apache Bench)程序。
ab -n 100 -c 10 http://localhost/
第六步: 验证聚合的日志。
Minio Server的fluent存储桶应该显示聚合后的日志。
mc ls myminio/fluentd/logs/[2016-05-03 18:47:13 IST] 570B 201605031306_0.gz[2016-05-03 18:58:14 IST] 501B 201605031317_0.gz
注意事项:
fleuntd需要有访问/var/log/apache2/access.log的权限。
原文: https://docs.minio.io/cn/aggregate-apache-logs-with-fluentd-and-minio.html
