开源日志收集软件fluentd 转发(forward)架构配置
需求:
通过开源软件fluentd收集各个设备的apache访问日志到fluentd的转发服务器中,然后通过webHDFS接口,写入到hdfs文件系统中。
软件版本说明:
hadoop版本:1.1.2
fluentd版本:1.1.21
测试环境说明:
node29服务器上安装了apache,以及fluentd,作为fluentd的客户端;
node1服务器,为hadoop服务器的namenode;
node29服务器上fluentd配置文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
< source >
type tail
format apache2
path /var/log/httpd/access_log
pos_file /var/log/td-agent/access_log .pos
time_format %Y-%m-%d %H:%M:%S
localtime
tag apache.access
< /source >
#Log Forwarding to node1 server <match apache.access> type forward
# time_slice_format %Y%m%d # time_slice_wait 10m # localtime #定义日志入库日志的时间; time_format %Y-%m-%d %H:%M:%S
#localtime非常重要,不设置日志时间和系统时间相差8小时; localtime
#定义入库日志的时间; <server>
host node1
port 24224
< /server >
flush_interval 1s
< /match >
|
node1服务器配置,这个服务器上配置了hadoop的namenode,以及作为fluentd的转发角色,具体配置文件如下:
1
2
3
4
|
< source >
type forward
port 24224
< /source >
|
<match apache.access>
type webhdfs
host node1.test.com
port 50070
path /apache/%Y%m%d_%H/access.log.${hostname}
time_slice_format %Y%m%d
time_slice_wait 10m
#定义日志入库日志的时间;
time_format %Y-%m-%d %H:%M:%S
localtime
flush_interval 1s
</match>
配置好以后,重启fluentd服务;
开始测试,在node29用ab命令开始访问apache,生成访问日志;
然后,到node1服务器上去查看HDFS文件系统中,是否生成了相关文件及目录:
查看生成的目录:
查看文件里面具体日志:
hadoop fs -cat /apache/20150106_16/access.log.node1.test.com
如上图所示,fluentd已经通过转发模式,把node29服务器上apache日志收集到hdfs文件系统中了,方便下一步用hadoop进行离线分析。
本文转自 shine_forever 51CTO博客,原文链接:http://blog.51cto.com/shineforever/1599771