Fluentd

Fluentd 是由Ruby和C编写的,需要ruby进行,然而安装td-agent 是fluentd 的易安装版本,不用考虑太多的依赖关系。

编辑配置文件/etc/td-agent/td-agent.conf 中的source来设置日志来源

<source>

 type tail  

 format apache  

 path /var/log/apache2/access_log  

 pos_file /var/log/apache2/access_log.pos  

 tag mongo.apache  

</source>

type tail: tail方式是 Fluentd 内置的输入方式,其原理是不停地从源文件中获取增量日志,与linx命令tail相似,也可以使用其他输入方式如http、forward等输入,也可以使用输入插件,将 tail 改为相应的插件名称 如: type tail_ex  ,注意tail_ex为下划线


1. 使用中转方式

先发送给中转站,中转再发送至elatsearch

在本机修改tdagent配置

# vim /etc/td-agent/conf.d/td-agent.conf

<source>

  type tail

  format json

  time_key time

  time_format %N

  pos_file /var/log/td-agent/x.log.pos

  path /log/x.%d.%m.%Y.log

  tag  log.x

</source>

<match log.**>

   type forward # forward模式,转发给其他服务器处理

   send_timeout 60s

   recover_wait 10s

   heartbeat_interval 1s

   phi_threshold 16

   hard_timeout 60s

   heartbeat_type tcp

   <server>  

      name auth.shard

      host td-agent

      port 24

      weight 1

  </server>

  <secondary>

      type file

      path /var/log/td-agent/log-forward-failed

</secondary>

</match>

 在中转修改tdagent配置

 #  vim /etc/td-agent/conf.d/td-agent-log.conf

 <source>

 type forward

 </source>

<match log.**>

   type forest

   subtype copy

   <template>  

          <store>      

          @type elasticsearch

           host elasticsearch

          port 92

          ssl_verify false

          logstash_format true

          logstash_prefix bilogs

          logstash_dateformat log.%m.%d.%Y

          time_key time

          flush_interval 10s

          request_timeout 15s

          reload_on_failure true

          reconnect_on_error true

        </store>

    </template>

</match>

kibana上添加index  log

# cat /opt/supervisor/log/12.12.2017.log |/opt/td-agent/embedded/bin/fluent-cat log** (非中转方式)


2. 不使用中转方式

直接发送给elatsearch

在所要添加的服务本机

# vim /etc/td-agent/conf.d/td-agent.conf

<match bilog.**>

  type forest

  subtype copy

  <template>

      <store>

          @type elasticsearch

          #type_name multiplayer.shard

          host elasticsearch

          port 92 

          ssl_verify false

          logstash_format true

          logstash_prefix bilogs

          logstash_dateformat bilog%m.%d.%Y

          time_key time

          flush_interval 10s

          request_timeout 15s

          reload_on_failure true

          reconnect_on_error true

            </store>

        </template>

</match>

# cat *json* | /opt/td-agent/embedded/bin/fluent-cat bilog**

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容