许可优化
许可优化
产品
产品
解决方案
解决方案
服务支持
服务支持
关于
关于
软件库
当前位置:服务支持 >  软件文章 >  Fluent的Server与Client模式详解(第三章)- yellowcong

Fluent的Server与Client模式详解(第三章)- yellowcong

阅读数 2
点赞 0
article_banner
在实际种,通常是多个fluent协同工作的,就如下图所示,每个k8s的宿主机都装有fluent,输出的日志信息都跑到一个fulent种,然后输出到文件或者kafka里面,给大数据进行消费处理。

这里写图片描述

官网地址

https://docs.fluentd.org/

安装fluent-plugin-forest 插件  


# 客户端需要安装的插件
#用于路径中加入tag
/opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-forest
#用于修改tag
/opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-rewrite-tag-filter
#用于正则匹配日志内容,进行筛选
/opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-grep
#用于修改record
/opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-record-reformer
 
# 服务器端需要安装的插件
/opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-forest
#输出文件到kafka的插件
/opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-kafka 

这里写图片描述

架构


主机ip主机名
192.168.141.51master-01-k8s
192.168.141.52master-02-k8s

server 机器

1 配置文件

服务端,服务的端口为24224,match 匹配,根据不同的类型的tag,对文件进行不同的处理,type stdout 表示直接控制台输出,type file 表示存储为文件。

<source>
  type forward
  port 24224
  bind 0.0.0.0
</source>
 
<match docker.test*>
  type stdout
</match>
 
<match docker.temp*>
  type file
  path /home/lee/fluentd-log
</match>

2 启动service

/opt/td-agent/embedded/bin/fluentd -c docker_in03.conf 

这里写图片描述

Client机器

启动客户端机器,

<source>
  type forward
  port 24224
  bind 0.0.0.0
</source>
 
<match docker.test*>
    type forward    
    <server>
    host 192.168.141.51
    port 24224
    </server>
    flush_interval 60s
</match>
 
<match docker.temp*>
    type forward    
    <server>
    host 192.168.141.51
    port 24224
    </server>
    flush_interval 60s
</match>

这里写图片描述

启动客户端服务

 ./fluentd -c /etc/td-agent/docker_in04.conf

这里写图片描述

启动容器服务

这个地方,通过–log-opt tag=“docker.{{.Name}}” ,来指定容器的tag,然后来根据这个tag来进行匹配(match),默认会根据容器的CONTAINER ID 来进行匹配。

#启动test01
docker run --name test01 --log-driver=fluentd --log-opt tag="docker.{{.Name}}"  --log-opt fluentd-async-connect=true -d -p 8001:8000 imekaku/simple-web python /work/simple.py

#启动temp01
docker run --name temp01  --log-driver=fluentd --log-opt tag="docker.{{.Name}}"  --log-opt fluentd-async-connect=true -d -p 8002:8000 imekaku/simple-web python /work/simple.py

提示:log tag支持如下,官网说明:

{{.ID}},{{.FullID}},{{.Name}},{{.ImageID}},{{.ImageFullID}},{{.ImageName}},{{.DaemonName}}

访问测试

#多次curl访问,就会看到服务端有消息
curl 127.0.0.1:8081
curl 127.0.0.1:8082

这个是test01这个的输出
这里写图片描述

然后temp的还有日志信息,我们只指定了输出的前部分,后面就自动命名了一个配置文件。
这里写图片描述

常见问题

1 config error file=“in_docker_file.conf” error=“Unknown output plugin ‘forest’. Run ‘gem search -rd fluent-plugin’ to find plugins”

导致这个问题的原因是没有安装fluent-plugin-forest 插件
这里写图片描述

参考文章

https://blog.csdn.net/jaysuper/article/details/8021878
http://www.imekaku.com/2016/09/14/fluentd-configure-client-server/


免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删


相关文章
技术文档
QR Code
微信扫一扫,欢迎咨询~
customer

online

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 board-phone 155-2731-8020
close1
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

姓名不为空

姓名不为空
手机不正确

手机不正确

手机不正确
公司不为空

公司不为空

公司不为空