---
title: "日志收集器fluentd：配置forward从客户机到收集入库端"
author: "BlackWing"
date: "2014-11-04T16:41:12Z"
tags: []
categories: ["开源软件"]
slug: "fluentd-forward"
draft: false
lastmod: "2014-11-04T16:41:42Z"
id: 2152319
url: "https://blackwing.iteye.com/blog/2152319"
---

转载请声明出处：http://blackwing.iteye.com/blog/2152319

试用了fluentd，挺方便易用，支持直接到hdfs，hbase，mangoDB等，可以跟已有业务结合。
安装fluentd非常简单，官方教材地址：<http://docs.fluentd.org/categories/installation>

以下是针对ubuntu 12.04 LTS进行说明：
1.先修改系统环境，例如增加open files数目、修改网络参数等：<http://docs.fluentd.org/articles/before-install>

2.根据自己系统版本，直接执行官方写好的一键安装脚本：

```java
curl -L http://toolbelt.treasuredata.com/sh/install-ubuntu-precise-td-agent2.sh | sh
```


安装好后，个文件路径为：
1）配置文件：/etc/td-agent/td-agent.conf
2）起停脚本：/etc/init.d/td-agent start|stop|restart|status
3）默认log路径：/var/log/td-agent/td-agent.log

应用场景是：收集其他部门某应用的log，发回到本部门服务器，并入库到hdfs。所以需要在某部门服务器上，安装fluentd用于把日志forward到本地服务。

借用官方图解：
![](http://docs.fluentd.org/images/fluentd_ha.png)

官方的配置可以参考高可用部分的配置：<http://docs.fluentd.org/articles/high-availability>

大概配置如下：
forward端的配置：

```java
<source>
  type forward
  port 24224
</source>

# Log Forwarding
<match testforward.**>
  type forward
  host 172.19.99.176
  flush_interval 10s
</match>
```


聚集端的配置：

```java
<source>
  type forward
  port 24224
</source>

<match testforward.*>
  type webhdfs
  host namenode
  port 50070
  path /log/%Y%m%d_%H/access.log.${hostname}
  flush_interval 10s
</match>
```



但官方没有详细说明，导致配置后fluentd不能启动，其实原来的td-agent.conf配置文件已经有以下配置：

```java

<source>
  type forward
</source>

```


所以，会有两个forward的source，导致fluentd启动失败，报错说端口24224已经在使用，解决办法是删掉以上默认配置就行。


现在可以测试curl一条信息到forward机器，它就会直接把细心转发到聚集机器，并且自动入库到hdfs。

另外，关于其他日志收集工具，请看董西成的blog：<http://dongxicheng.org/search-engine/log-systems/>