EFK代替ELK方案7.17.3

文章目录

    • 一. 传统的ELK
    • 二. EFK
      • 2.1 安装elasticSearch
      • 2.2 服务端安装fileBeats
        • 2.2.1. 安装 `该也没有必要安装odcker`,直接下载yum或官网jar包启动即可.
        • 2.2.2.编辑配置文件 filebeat-java-logback.yml
        • 2.2.3. es配置`common_log_pipeline`解析日志
      • 三.启动测试


最近发现,logstash日志收集器本身的内存占用和es相当,这也是logstash用java开发,其jvm本身就是内存消耗大户.为了降本增效,发现用go开发的beats可以替代logstash.

ELK : 通常我们将服务器日志通过logback的http发送至logstash服务器统一处理,logstash采集处理后发送到elasticsearch服务器.
EFK: 通常我们将服务器日志保存到本机,本机启动filebeats,fliebeats采集处理发送至elasticsearch.

一. 传统的ELK

在这里插入图片描述

logstash+elasticsearch+Kibana(ELK)日志收集


二. EFK

在这里插入图片描述

logback+ fileBeats + elasticSearch + Kibana日志收集方案

2.1 安装elasticSearch

该docker安装只针对7.18以下版本. 7.18+默认开启生产模式

1. 安装
# 安装es
docker pull elasticsearch:7.17.3
mkdir -p /mydata/elasticsearch/config
mkdir -p /mydata/elasticsearch/data
echo "http.host: 0.0.0.0" >> /mydata/elasticsearch/config/elasticsearch.yml
chmod -R 777 /mydata/elasticsearch/docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms512m -Xmx512m" \
--restart=always --privileged=true \
-v /mydata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /mydata/elasticsearch/data:/usr/share/elasticsearch/data \
-v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-d elasticsearch:7.17.3
2. 进入到es挂载目录elasticsearch.yml的挂载目录,添加以下内容
http.host: 0.0.0.0
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization
xpack.security.enabled: true
# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl.enabled: true
# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl.enabled: false

3. 重启es容器并进入es容器
4. 进入容器后执行以下命令 傻瓜式设置账号密码

./bin/elasticsearch-setup-passwords interactive

5. 重启es容器

2.2 服务端安装fileBeats

2.2.1. 安装 该也没有必要安装odcker,直接下载yum或官网jar包启动即可.

强烈建议不要用docker,docker不保证不出错

# 安装beats
docker run -d --name=filebeat:7.17.3 docker.elastic.co/beats/filebeat:7.17.3 \
--privileged=true \ 
--restart=always \
-v /mydata/beats/filebeat.yml:/usr/share/filebeat/filebeat.yml:ro \
-v /mydata/beats/lib/docker/containers:/var/lib/docker/containers:ro \
-v /mydata/beats/run/docker.sock:/var/run/docker.sock:ro \
-v /mydata/beats/log/messages:/var/log/messages \
-e --strict.perms=false \
-E output.elasticsearch.hosts=["elasticsearch:9200"]
# 安装管道
filebeat setup  --pipelines --modules system

2.2.2.编辑配置文件 filebeat-java-logback.yml

目的: 1.设置filebeat的抓取数据路径 2.设置输出目标,及使用何种预处理
以下是7.17.3到8.6的官方配置.只做增添.

###################### Filebeat Configuration Example ########################## This file is an example configuration file highlighting only the most common
# options. The filebeat.reference.yml file from the same directory contains all the
# supported options with more comments. You can use it as a reference.
#
# You can find the full configuration reference here:
# https://www.elastic.co/guide/en/beats/filebeat/index.html# For more available modules and options, please see the filebeat.reference.yml sample
# configuration file.# ============================== Filebeat inputs ===============================filebeat.inputs:# Each - is an input. Most options can be set at the input level, so# you can use different inputs for various configurations.# Below are the input-specific configurations.# filestream is an input for collecting log messages from files.- type: filestreamencoding: utf-8# Unique ID among all inputs, an ID is required.id: my-filestream-id# Change to true to enable this input configuration.enabled: true# Paths that should be crawled and fetched. Glob based paths.paths:- c:/mydata/filebeat/logs/*.log#- /mydata/filebeat/logs/*.log# yyyy-MM-dd 时间格式开头的行,合并到上一行末multiline:pattern: '^\d{4}\-\d{2}\-\d{2}'negate: truematch: after# Exclude lines. A list of regular expressions to match. It drops the lines that are# matching any regular expression from the list.# Line filtering happens after the parsers pipeline. If you would like to filter lines# before parsers, use include_message parser.#exclude_lines: ['^DBG']# Include lines. A list of regular expressions to match. It exports the lines that are# matching any regular expression from the list.# Line filtering happens after the parsers pipeline. If you would like to filter lines# before parsers, use include_message parser.#include_lines: ['^ERR', '^WARN']# Exclude files. A list of regular expressions to match. Filebeat drops the files that# are matching any regular expression from the list. By default, no files are dropped.#prospector.scanner.exclude_files: ['.gz$']# Optional additional fields. These fields can be freely picked# to add additional information to the crawled log files for filtering#fields:#  level: debug#  review: 1# ============================== Filebeat modules ==============================filebeat.config.modules:# Glob pattern for configuration loadingpath: ${path.config}/modules.d/*.yml# Set to true to enable config reloadingreload.enabled: true# Period on which files under path should be checked for changes#reload.period: 10s# ======================= Elasticsearch template setting =======================setup.template.settings:index.number_of_shards: 1#index.codec: best_compression#_source.enabled: false
setup.template.name: "yqc"      # 设置一个新的模板,模板的名称
setup.template.pattern: "yqc-*" # 模板匹配那些索引,这里表示以yqc开头的所有的索引
setup.template.overwrite: true
setup.template.enabled: false
setup.ilm.enabled: false
#index.codec: best_compression
#_source.enabled: false# ================================== General ===================================# The name of the shipper that publishes the network data. It can be used to group
# all the transactions sent by a single shipper in the web interface.
#name:# The tags of the shipper are included in their field with each
# transaction published.
#tags: ["service-X", "web-tier"]# Optional fields that you can specify to add additional information to the
# output.
#fields:
#  env: staging# ================================= Dashboards =================================
# These settings control loading the sample dashboards to the Kibana index. Loading
# the dashboards is disabled by default and can be enabled either by setting the
# options here or by using the `setup` command.
#setup.dashboards.enabled: false# The URL from where to download the dashboard archive. By default, this URL
# has a value that is computed based on the Beat name and version. For released
# versions, this URL points to the dashboard archive on the artifacts.elastic.co
# website.
#setup.dashboards.url:# =================================== Kibana ===================================# Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API.
# This requires a Kibana endpoint configuration.
setup.kibana:# Kibana Host
# Scheme and port can be left out and will be set to the default (http and 5601)
# In case you specify and additional path, the scheme is required: http://localhost:5601/path
# IPv6 addresses should always be defined as: https://[2001:db8::1]:5601
#host: "localhost:5601"# Kibana Space ID
# ID of the Kibana Space into which the dashboards should be loaded. By default,
# the Default Space will be used.
#space.id:# =============================== Elastic Cloud ================================# These settings simplify using Filebeat with the Elastic Cloud (https://cloud.elastic.co/).# The cloud.id setting overwrites the `output.elasticsearch.hosts` and
# `setup.kibana.host` options.
# You can find the `cloud.id` in the Elastic Cloud web UI.
#cloud.id:# The cloud.auth setting overwrites the `output.elasticsearch.username` and
# `output.elasticsearch.password` settings. The format is `<user>:<pass>`.
#cloud.auth:# ================================== Outputs ===================================# Configure what output to use when sending the data collected by the beat.# ---------------------------- Elasticsearch Output ----------------------------
output.elasticsearch:# Array of hosts to connect to.hosts: [ "localhost:9200" ]username: "elastic"password: "elastic"# pipeline使用的是es的管道解析功能pipeline: "common_log_pipeline"encoding: utf-8indices:- index: "yqc-info-%{[agent.version]}-%{+yyyy.MM.dd}"when.contains:message: "INFO"- index: "yqc-error-%{[agent.version]}-%{+yyyy.MM.dd}"when.contains:message: "ERROR"# Protocol - either `http` (default) or `https`.#protocol: "https"# Authentication credentials - either API key or username/password.#api_key: "id:api_key"#username: "elastic"#password: "changeme"# ------------------------------ Logstash Output -------------------------------#output.logstash:# The Logstash hosts#hosts: ["localhost:5044"]# Optional SSL. By default is off.# List of root certificates for HTTPS server verifications#ssl.certificate_authorities: ["/etc/pki/root/ca.pem"]# Certificate for SSL client authentication#ssl.certificate: "/etc/pki/client/cert.pem"# Client Certificate Key#ssl.key: "/etc/pki/client/cert.key"# ================================= Processors =================================
# pipeline使用的是es的解析功能,而processors是filebeats本身的功能
processors:- add_host_metadata:when.not.contains.tags: forwarded- add_cloud_metadata: ~- add_docker_metadata: ~- add_kubernetes_metadata: ~# ================================== Logging ===================================# Sets log level. The default log level is info.# Available log levels are: error, warning, info, debug#logging.level: debug# At debug level, you can selectively enable logging only for some components.# To enable all selectors, use ["*"]. Examples of other selectors are "beat",# "publisher", "service".#logging.selectors: ["*"]# ============================= X-Pack Monitoring ==============================# Filebeat can export internal metrics to a central Elasticsearch monitoring# cluster.  This requires xpack monitoring to be enabled in Elasticsearch.  The# reporting is disabled by default.# Set to true to enable the monitoring reporter.#monitoring.enabled: false# Sets the UUID of the Elasticsearch cluster under which monitoring data for this# Filebeat instance will appear in the Stack Monitoring UI. If output.elasticsearch# is enabled, the UUID is derived from the Elasticsearch cluster referenced by output.elasticsearch.#monitoring.cluster_uuid:# Uncomment to send the metrics to Elasticsearch. Most settings from the# Elasticsearch outputs are accepted here as well.# Note that the settings should point to your Elasticsearch *monitoring* cluster.# Any setting that is not set is automatically inherited from the Elasticsearch# output configuration, so if you have the Elasticsearch output configured such# that it is pointing to your Elasticsearch monitoring cluster, you can simply# uncomment the following line.#monitoring.elasticsearch:# ============================== Instrumentation ===============================# Instrumentation support for the filebeat.#instrumentation:# Set to true to enable instrumentation of filebeat.#enabled: false# Environment in which filebeat is running on (eg: staging, production, etc.)#environment: ""# APM Server hosts to report instrumentation results to.#hosts:#  - http://localhost:8200# API Key for the APM Server(s).# If api_key is set then secret_token will be ignored.#api_key:# Secret token for the APM Server(s).#secret_token:# ================================= Migration ==================================# This allows to enable 6.7 migration aliases
#migration.6_to_7.enabled: true

2.2.3. es配置common_log_pipeline解析日志

目的: 我们需要根据日志数据来自定义解析结果, 当然默认的也可以.自定义就需要使用pipeline功能

那如何确定日志数据被pipeline解析的格式? 答案是使用grok语法 grok的模拟解析工具在kibana有提供或在线grok工具. (请自行查阅gork语法)

日志打印格式

    <!-- 日志输出格式 --><property name="log.console.pattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS,GMT+8}-%magenta(${IP})-%blue([%thread])-%highlight(%-5level)-%logger{20}-%yellow(%method)-%cyan(%msg)-%red(%exception%n)" /><property name="log.file.pattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS,GMT+8}-${ip}-[%thread]-%level-%logger{20}-%method-%msg-%exception%n" />

日志数据

2023-09-18 20:34:55.439-ip_IS_UNDEFINED-[main]-INFO-o.a.d.s.b.c.e.OverrideDubboConfigApplicationListener-onApplicationEvent-Dubbo Config was overridden by externalized configuration {dubbo.application.logger=slf4j, dubbo.application.metadataType=remote, dubbo.application.name=vector-member, dubbo.application.qos-enable=false, dubbo.config.multiple=true, dubbo.consumer.check=false, dubbo.consumer.version=1.0.0, dubbo.metadata-report.address=nacos://localhost:8848, dubbo.metadata-report.parameters.namespace=410031c2-6c35-40e0-a417-dbd2870e8aaa, dubbo.metadata-report.parameters.password=nacos, dubbo.metadata-report.parameters.username=nacos, dubbo.protocol.name=dubbo, dubbo.protocol.port=-1, dubbo.protocol.serialization=hessian2, dubbo.provider.version=1.0.0, dubbo.registry.address=nacos://localhost:8848, dubbo.registry.check=false, dubbo.registry.parameters.namespace=410031c2-6c35-40e0-a417-dbd2870e8aaa, dubbo.registry.parameters.password=nacos, dubbo.registry.parameters.username=nacos}-

grok解析

%{TIMESTAMP_ISO8601:timestamp}-%{DATA:ip}-%{DATA:thread}-%{LOGLEVEL:log_level}-%{DATA:class}-%{GREEDYDATA:method}-%{GREEDYDATA:msg}-%{GREEDYDATA:exception_message}

在这里插入图片描述

对应的预处理方法即数据被映射的数据项

PUT _ingest/pipeline/common_log_pipeline
{"description": "common_log_pipeline","processors": [{"grok": {"field": "message","patterns": ["%{TIMESTAMP_ISO8601:timestamp}-%{DATA:ip}-%{DATA:thread}-%{LOGLEVEL:log_level}-%{DATA:class}-%{GREEDYDATA:method}-%{GREEDYDATA:msg}-%{GREEDYDATA:exception_message}"],"ignore_failure":true}},{"remove" : {"field" : "input"}},{"remove" : {"field" : "message"}},{"remove" : {"field" : "agent"}},{"remove" : {"field" : "ecs"}},{"remove" : {"field" : "host"}},{"remove" : {"field" : "log"}}]
}

在这里插入图片描述

三.启动测试

filebeat应该和服务器代码一起,利用filebeat采集服务器存储的日志文件发送到es.

# linux
./filebeat -e -c filebeat.yml
# windows
filebeat.exe -e -c filebeat.yml

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/81768.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

性能测试 —— Jmeter 常用三种定时器

1、同步定时器 位置&#xff1a;HTTP请求->定时器->Synchronizing Timer 当需要进行大量用户的并发测试时&#xff0c;为了让用户能真正的同时执行&#xff0c;添加同步定时器&#xff0c;用户阻塞线程&#xff0c;知道线程数达到预先配置的数值&#xff0c;才开始执行…

rk平台快捷键进入uboot模式和烧录模式

(1)进入U-boot命令行模式 上电时,多次按下ctrlc按键(2)进入maskrom烧录模式 方法一:上电时(或者reboot时),多次按下ctrlb 方法二:在uboot命令 手敲rbrom

vue3 - 使用reactive定义响应式数据进行赋值时,视图没有改变,值已经改变的解决方案

问题&#xff1a; 在Vue 3.0 中我们使用 reactive() 定义的响应式数据的时候&#xff0c;当是一个数组或对象时&#xff0c;我们直接进行赋值&#xff0c;发现数据已经修改成功&#xff0c;但是页⾯并没有自动渲染成最新的数据&#xff1b;这是为什么呢&#xff1f; 就如同官网…

线性代数的本质(二)——线性变换与矩阵

文章目录 线性变换与矩阵线性变换与二阶方阵常见的线性变换复合变换与矩阵乘法矩阵的定义列空间与基矩阵的秩逆变换与逆矩阵 线性变换与矩阵 线性变换与二阶方阵 本节从二维平面出发学习线性代数。通常选用平面坐标系 O x y Oxy Oxy &#xff0c;基向量为 i , j \mathbf i,…

数据结构-时间复杂度/空间复杂度

Hello&#xff0c;好久没有更新了哦&#xff0c;已经开始学习数据结构了&#xff0c;这篇文章呢就是对刚学数据结构所接触到的时间复杂度进行一个分享哦&#xff0c;如果有错误之处&#xff0c;大家记得拍拍我哦~ 既然要讨论时间/空间复杂度&#xff0c;那我们就得知道时间/空…

SpringBoot国际化配置组件支持本地配置和数据库配置

文章目录 0. 前言i18n-spring-boot-starter1. 使用方式0.引入依赖1.配置项2.初始化国际化配置表3.如何使用 2. 核心源码实现一个拦截器I18nInterceptorI18nMessageResource 加载国际化配置 3.源码地址 0. 前言 写个了原生的SpringBoot国际化配置组件支持本地配置和数据库配置 背…

tdesign的文件上传(微信小程序+idea的springboot)

目录 1. springboot后端 1.1 FileController.java 1.2 listener文件的ErpApplicationListener.java 1.3 【重点&#xff01;】FileServiceImpl层 1.4 IFileService 1.5 StringUtil通用类 1.6 主程序加一个监听器 1.7 application.yml文件 2. 微信小程序端 2.1 TDesign的…

随机产生两个数在屏幕上打印,例如6*7=? 让学生输入答案,若正确打印答对了,否则提示学生重做,直到答对为止(小游戏)

#include<stdio.h> #include<stdlib.h> #include<time.h>//时间的库函数 int main() {int i 0;srand(time(0));//随机种子初始化int num1 rand() %10;//随机数int num2 rand() %10;printf("%d * %d ?\n", num1, num2);printf("请输入答案…

阿里云无影电脑:免费体验无影云电脑3个月

阿里云无影云电脑免费领取流程&#xff0c;免费无影云电脑配置为4核8G&#xff0c;可以免费使用3个月&#xff0c;阿里云百科分享阿里云无影云电脑&#xff08;云桌面&#xff09;免费申请入口、申请流程及免费使用限制条件说明&#xff1a; 目录 阿里云无影云电脑免费申请入…

【C++初阶】动态内存管理

​&#x1f47b;内容专栏&#xff1a; C/C编程 &#x1f428;本文概括&#xff1a; C/C内存分布、C语言动态内存管理、C动态内存管理、operator new与operator delete函数、new和delete的实现原理、定位new表达式、常见面试问题等。 &#x1f43c;本文作者&#xff1a; 阿四啊 …

CSRF和SSRF有什么不同?

文章目录 CSRF复现SSRF复现启动环境漏洞复现探测存活IP和端口服务计划任务反弹shell 区别 CSRF复现 打开dvwa&#xff0c;将难度调为low&#xff0c;点击CSRF&#xff0c;打开后发现有一个修改密码的输入框&#xff1a; 在这里修改密码&#xff0c;并用bp抓包&#xff0c;在…

C++实现观察者模式(包含源码)

文章目录 观察者模式一、基本概念二、实现方式三、角色四、过程五、结构图六、构建思路七、完整代码 观察者模式 一、基本概念 观察者模式&#xff08;又被称为模型&#xff08;Model&#xff09;-视图&#xff08;View&#xff09;模式&#xff09;是软件设计模式的一种。在…

开启编程之门

自我介绍 目前已经大二了&#xff0c;计算机专业在读&#xff0c;是一个热爱编程&#xff0c;做事踏实专注的人。转眼间一年已经过去了&#xff0c;也接触编程一年了&#xff0c;但开始并没有对所学所想进行很好的总结和输出&#xff0c;这一年也有了新的很多感悟与心得&#x…

浅谈双十一背后的支付宝LDC架构和其CAP分析

本人汤波&#xff0c;superthem.com 圆领超级个体创始人&#xff0c;Github page地址&#xff1a;https://tbwork.github.io/ 看到很多人在盗用我的文章&#xff0c;还标记成原创&#xff0c;进行收费&#xff0c;非常令人作呕。 我的所有技术文章全部免费阅读&#xff0c;大家…

PCB走线规则

1、线间距。 这里应该遵循3W规则&#xff0c;所谓3W就是为了减少线间串扰&#xff0c;应保证线间距足够大&#xff0c;当线中心不少于3倍线宽&#xff0c;则可 保持70%的电场不互相干扰。如要达到98%的电场不互相干扰&#xff0c;可使用10W的间距。——这是查阅华为PCB布线规则…

npm 清缓存(重新安装node-modules)

安装node依赖包的会出现失败的情况&#xff0c;如下图所示&#xff1a; 此时 提示有些依赖树有冲突&#xff0c;根据提示 “ this command with --force or --legacy-peer-deps” 执行命令即可。 具体步骤如下&#xff1a; 1、先删除本地node-modules包 2、删掉page-loacl…

el-upload 上传附件(拆解步骤)

目录 1. 看elementui /element-plus 官网案例 2. html部分&#xff1a; 把官网上的搬下来&#xff0c;最好加一个按钮&#xff0c;上传到服务器&#xff08;后端&#xff09; 3. js 部分&#xff1a; 3.1 首先&#xff0c;先定义一个变量&#xff0c;files 3.2 当上传图片…

机器学习(11)---降维PCA

目录 一、概述1.1 维度1.2 sklearn中的降维算法 二、降维实现原理2.1 PCA与SVD2.2 降维实现2.3 降维过程 三、鸢尾花数据集降维3.1 高维数据的可视化3.2 探索降维后的数据3.3 累积可解释方差贡献率曲线 四、选n_components参数方法4.1 最大似然估计自选超参数4.2 按信息量占比选…

WavJourney:进入音频故事情节生成世界的旅程

推荐&#xff1a;使用 NSDT场景编辑器快速搭建3D应用场景 若要正确查看音频生成的强大功能&#xff0c;请考虑以下方案。我们只需要提供一个简单的指令&#xff0c;描述场景和场景设置&#xff0c;模型就会生成一个扣人心弦的音频脚本&#xff0c;突出与原始指令的最高上下文相…

数组和指针笔试题解析之【数组】

目录 前言&#xff1a; 1.一维数组&#xff1a; 2.字符数组 &#xff1a; 2.1题型一&#xff1a; 2.2题型二&#xff1a; 2.3题型三&#xff1a; 3.二维数组 &#xff1a; 前言&#xff1a; 1.数组名的意义&#xff1a; sizeof(数组名)&#xff1a;这里的数组名表示整…