栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

kubesphere k8s 安装Fluentd,带elasticsearch插件

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

kubesphere k8s 安装Fluentd,带elasticsearch插件

目录

前言

一、制作Fluentd镜像

二、编写配置文件

1.编辑配置

2.配置说明(可忽略不看)

 3.logback-spring.xml的配置

三、部署fluentd




前言

Fluentd是一款开源的日志收集功能,和Elasticsearch、Kibana一起使用可以搭建EFK日志收集系统。好处就是Fluentd比Logstash轻量化的多。内存占用连Logstash的十分之一都不到。本文将演示如何在kubesphere k8s上部署Fluentd




一、制作Fluentd镜像

dockerhub上有官方的镜像,但是里面不内置elasticsearch插件。这样的话在k8s上会有些问题,没法安装啊!!

制作方法也很简单官方教程:

fluent/fluentd-docker-image: Docker image for Fluentd (github.com)

如果实在是懒得麻烦,用我做好的也行。

aliyun:           docker pull registry.cn-shanghai.aliyuncs.com/samaritan/fluentd:1.14-1



二、编写配置文件

1.编辑配置

在kubesphere上新建一个配置文件

 key:fluent.conf

value:


  @type  tcp
  @id    debug-input
  port  4560
  tag debug
 
    @type json
 


  @type  tcp
  @id    error-input
  port  4561
  tag error
 
    @type json
 


  @type  tcp
  @id    business-input
  port  4562
  tag business
 
    @type json
 


  @type  tcp
  @id    record-input
  port  4563
  tag record
 
    @type json
 


  @type parser
  key_name message
  reserve_data true
  remove_key_name_field true
 
    @type json
 


  @type stdout
  output_type json


  @type elasticsearch
  host elastic-9g8m25-elasticsearch-master.mall-swarm
  port 9200
  type_name docker
  logstash_format true
  logstash_prefix docker-${tag}-logs
  logstash_dateformat %Y-%m-%d
  flush_interval 5s
  include_tag_key true

 

2.配置说明(可忽略不看)

 ">

定义了日志收集的来源,可以有tcp、udp、tail(文件)、forward(tcp+udp)、http等方式。

这里我们从tcp请求收集日志,端口为4560,并且设置了tag为debug。


  @type  tcp
  @id    debug-input
  port  24221
  tag debug
  
    @type json
  

 ">

定义对原始数据的解析方式,可以将日志转化为JSON。

 将debug日志转化为JSON可以进行如下配置。


  @type  tcp
  @id    debug-input
  port  4560
  tag debug
  
    @type json
  

 ">

可以对收集的日志进行一系列的处理,比如说将日志打印到控制台或者对日志进行解析。

对于tag为record来源的日志,我们将其中的message属性转化为JSON格式,如果不进行转化的话,message属性将会是一个字符串。


  @type parser
  key_name message
  reserve_data true
  remove_key_name_field true
  
    @type json
  

 ">

定义了收集到的日志最后输出到哪里,可以输出到stdout(控制台)、file、elasticsearch、mongo等里面。

 这里我们使用elasticsearch来存储日志信息,logstash_format、logstash_prefix、logstash_dateformat主要用来控制日志索引名称的生成,当前配置生成debug日志的索引格式为docker-debug-logs-2021-10-23,flush_interval用来控制日志输出到elasticsearch的时间间隔。


  @type elasticsearch
  host elastic-9g8m25-elasticsearch-master.samaritan
  port 9200
  type_name docker
  logstash_format true
  logstash_prefix docker-${tag}-logs
  logstash_dateformat %Y-%m-%d
  flush_interval 5s
  include_tag_key true

 3.logback-spring.xml的配置

这里面没啥说的,就是将上面的端口配置到里面,好让日志能够输出到fluentd

    ${LOG_STASH_HOST}:4560

三、部署fluentd

kubesphere部署无状态服务。

 使用自定义经常仓库地址 这里用我自己制作上传的带es插件的镜像:

registry.cn-shanghai.aliyuncs.com/samaritan/fluentd:1.14-1。

选择使用默认端口

设置日志搜集端口。

 挂载配置文件,选择之前编写的配置文件,挂载到/fluentd/etc 目录

 点击下一步,创建。

查看启动日志,确定载入的是我们自定义的配置文件,且无报错。


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/343836.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号