许可优化
许可优化
产品
产品
解决方案
解决方案
服务支持
服务支持
关于
关于
软件库
当前位置:服务支持 >  软件文章 >  使用Fluent收集容器日志:Docker/K8s日志采集

使用Fluent收集容器日志:Docker/K8s日志采集

阅读数 2
点赞 0
article_banner

1.全局 配置 ,使用fluentd驱动收集节点容器日志

[root@localhost logs]# cat /etc/docker/daemon.json 
{
  "registry-mirrors": ["https://kmzfwpoy.mirror.aliyuncs.com","https://ytji6dx6.mirror.aliyuncs.com"],
  "log-driver": "fluentd",  #定义驱动类型为fluentd
  "log-opts": {
    "fluentd-address": "127.0.0.1:24224",  #绑定fluentd节点
    "tag": "{{.Name}}"  #这里指定容器名称为日志名
  }
}

systemctl daemon_reload

   systemctl restart docker

fluentd的配置文件

<source>
  @type   forward
</source>

<match *>

  @type              file

  path               /fluentd/log/${tag}
  append             true
  <format>
    @type            single_value
    message_key      log
  </format>
  <buffer tag,time>
    @type             file
    timekey           1d
    timekey_wait      10m
    flush_mode        interval
    flush_interval    30s
  </buffer>
</match>

新建目录fluentd,子文件夹logs,和配置文件fluentd.conf(内容如上)

   给logs添加权限

chmod 777 logs
docker run -it \
  -d \
  -p 24224:24224 \
  -v /home/fluentd/fluent.conf:/fluentd/etc/fluent.conf \
  -v /home/fluentd/logs:/fluentd/log \
  fluent/fluentd:v1.3

这样就表示启动了

   启动一个容器试试

docker run --name nginx -p 8080:80 nginx:latest

浏览器访问ip:8080,观察访问记录
在这里插入图片描述

   同时到logs目录下,会有一个 容器名.时间戳.log 的日志文件

在这里插入图片描述


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


相关文章
技术文档
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
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

姓名不为空

姓名不为空
手机不正确

手机不正确

手机不正确
公司不为空

公司不为空

公司不为空