日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

kubesphere k8s 安装Fluentd,带elasticsearch插件

發布時間:2023/12/20 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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:

<source>
? @type ?tcp
? @id ? ?debug-input
? port ?4560
? tag debug
? <parse>
? ? @type json
? </parse>
</source>

<source>
? @type ?tcp
? @id ? ?error-input
? port ?4561
? tag error
? <parse>
? ? @type json
? </parse>
</source>

<source>
? @type ?tcp
? @id ? ?business-input
? port ?4562
? tag business
? <parse>
? ? @type json
? </parse>
</source>

<source>
? @type ?tcp
? @id ? ?record-input
? port ?4563
? tag record
? <parse>
? ? @type json
? </parse>
</source>

<filter record>
? @type parser
? key_name message
? reserve_data true
? remove_key_name_field true
? <parse>
? ? @type json
? </parse>
</filter>

<match fluent.**>
? @type stdout
? output_type json
</match>

<match **>
? @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
</match>
?

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

?<source>

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

這里我們從tcp請求收集日志,端口為4560,并且設置了tag為debug。

<source>@type tcp@id debug-inputport 24221tag debug<parse>@type json</parse> </source>

?<parse>

定義對原始數據的解析方式,可以將日志轉化為JSON。

?將debug日志轉化為JSON可以進行如下配置。

<source>@type tcp@id debug-inputport 4560tag debug<parse>@type json</parse> </source>

?<filter xxx>

可以對收集的日志進行一系列的處理,比如說將日志打印到控制臺或者對日志進行解析。

對于tag為record來源的日志,我們將其中的message屬性轉化為JSON格式,如果不進行轉化的話,message屬性將會是一個字符串。

<filter record>@type parserkey_name messagereserve_data trueremove_key_name_field true<parse>@type json</parse> </filter>

?<match>

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

?這里我們使用elasticsearch來存儲日志信息,logstash_format、logstash_prefix、logstash_dateformat主要用來控制日志索引名稱的生成,當前配置生成debug日志的索引格式為docker-debug-logs-2021-10-23,flush_interval用來控制日志輸出到elasticsearch的時間間隔。

<match **>@type elasticsearchhost elastic-9g8m25-elasticsearch-master.samaritanport 9200type_name dockerlogstash_format truelogstash_prefix docker-${tag}-logslogstash_dateformat %Y-%m-%dflush_interval 5sinclude_tag_key true </match>

?3.logback-spring.xml的配置

這里面沒啥說的,就是將上面的端口配置到里面,好讓日志能夠輸出到fluentd

<appender name="LOG_STASH_DEBUG" class="net.logstash.logback.appender.LogstashTcpSocketAppender"><destination>${LOG_STASH_HOST}:4560</destination> </appender>

三、部署fluentd

kubesphere部署無狀態服務。

?使用自定義經常倉庫地址 這里用我自己制作上傳的帶es插件的鏡像:

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

選擇使用默認端口

設置日志搜集端口。

?掛載配置文件,選擇之前編寫的配置文件,掛載到/fluentd/etc 目錄

?點擊下一步,創建。

查看啟動日志,確定載入的是我們自定義的配置文件,且無報錯。


總結

以上是生活随笔為你收集整理的kubesphere k8s 安装Fluentd,带elasticsearch插件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。