Redian新闻
>
日志可视化方案:ELK+filebeat

日志可视化方案:ELK+filebeat

公众号新闻

点击上方“芋道源码”,选择“设为星标

管她前浪,还是后浪?

能浪的浪,才是好浪!

每天 10:33 更新文章,每天掉亿点点头发...

源码精品专栏

 
来源:blog.csdn.net/kang9399052316/
article/details/118546182

一、ELK+filebeat系统介绍

ELK是指Elasticsearch,Logstash 和 Kibana。集中式日志收集系统,将所有节点上的日志统一收集,管理,访问。

ElasticSearch(简称ES),是一个实时的分布式搜索和分析引擎,它可以用于全文搜索,结构化搜索以及分析。

Logstash,是一个数据收集引擎,主要用于进行数据收集、解析,并将数据发送给ES。

Kibana,为 Elasticsearch 提供了分析和 Web 可视化界面,并生成各种维度表格、图。

Filebeat,一个轻量级日志传输Agent,可以将指定日志转发到Logstash、Elasticsearch、Kafka、Redis等中。Filebeat占用资源少,而且安装配置也比较简单,支持目前各类主流OS及Docker平台。

大致流程图如下:

基于 Spring Boot + MyBatis Plus + Vue & Element 实现的后台管理系统 + 用户小程序,支持 RBAC 动态权限、多租户、数据权限、工作流、三方登录、支付、短信、商城等功能

  • 项目地址:https://github.com/YunaiV/ruoyi-vue-pro
  • 视频教程:https://doc.iocoder.cn/video/

二、搭建

1、服务器环境:

CentOS7.5、JDK1.8、ElasticSearch7.13.2、Logstash 7.13.2、Kibana7.13.2、Filebeat7.13.2

2、安装包下载地址:

「filebeat下载地址:」

  • https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.13.2-linux-x86_64.tar.gz

「elasticsearch下载地址:」

  • https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.13.2-linux-x86_64.tar.gz

「logstash下载地址:」

  • https://artifacts.elastic.co/downloads/logstash/logstash-7.13.2-linux-x86_64.tar.gz

「kibana下载地址:」

  • https://artifacts.elastic.co/downloads/kibana/kibana-7.13.2-linux-x86_64.tar.gz

3.安装以及配置文件修改

3.1 elasticsearch安装与配置

「tar -zxvf lasticsearch-7.13.2-linux-x86_64.tar.gz -C /opt/elk」/opt/elk是我的安装目录,可自行更改)

解压完之后进入/config,编辑elasticsearch.yml


> 基于 Spring Cloud Alibaba + Gateway + Nacos + RocketMQ + Vue & Element 实现的后台管理系统 + 用户小程序,支持 RBAC 动态权限、多租户、数据权限、工作流、三方登录、支付、短信、商城等功能
>
> * 项目地址:<https://github.com/YunaiV/yudao-cloud>
> * 视频教程:<https://doc.iocoder.cn/video/>

# ---------------------------------- Network -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#
#network.host: 192.168.0.1
#
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#

配置文件里需要注意的是,network.host 默认设置是localhost,运行起来验证的时候外网是访问到不到的,为了方便验证这里可以取消注释,设置成0.0.0.0;http.port默认是9200,如果端口冲突可以取消注释自行修改。

另外,elasticsearch默认是不让root用户启动的,所以我们需要新建一个用户来专门启动elasticsearch,我这里举例创建一个es用户:

创建es用户组:groupadd es

在es用户组下创建es用户:「useradd es -g es -p elasticsearch」

切换到elk目录:cd /opt/elk

赋予es用户elasticsearch权限:「chown -R es:es elasticsearch-7.13.2 chown es asticsearch-7.13.2 -R」

后台运行elasticsearch:cd到bin目录,执行以下命令

./elasticsearch -d
3.2 logstash安装与配置

解压完之后进入/config,拷贝一份logstash-sample.conf到bin目录下,方便后面启动:「cp logstash-sample.conf …/bin/logstash.conf」

编辑刚拷贝到bin目录下的logstash.conf

# Sample Logstash configuration for creating a simple
# Beats -> Logstash -> Elasticsearch pipeline.

input {
  beats {
    port => 5044
  }
}

output {
  elasticsearch {
    hosts => ["http://localhost:9200"]
    index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
    #user => "elastic"
    #password => "changeme"
  }
}

可以看到beats里有个port,这是给后面filebeat传输日志留的端口,冲突的话可以自行修改;

output是日志输出相关,hosts是之前安装elasticsearch的地址和端口,index是索引名,后面kibana运行起来后我们就能看到输出的索引名,一般是用项目名+时间。

后台运行logstash:cd到bin目录,执行以下命令

 nohup ./logstash -f logstash.conf &
3.3kibana安装与配置

一样还是先解压,cd到confi目录,然后编辑配置文件kibana.yml

# Kibana is served by a back end server. This setting specifies the port to use.
#server.port: 5601

# Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values.
# The default is 'localhost', which usually means remote machines will not be able to connect.
# To allow connections from remote users, set this parameter to a non-loopback address.
server.host: "0.0.0.0"


# Specifies locale to be used for all localizable strings, dates and number formats.
# Supported languages are the following: English - en , by default , Chinese - zh-CN .
i18n.locale: "zh-CN"

可以看到我这里用的是默认端口5601,这里serverhost不能用localhost,不然外网访问不到,在配置文件的最后一行,还可以将系统设置为中文。

kibana也不能使用root用户启动,但是我发现加上–allow-root就可以用root用户启动,elasticsearch适不适用我没有尝试,有试过的小伙伴可以评论交流一下。

启动kibana:cd到kibana/bin目录,执行以下命令

nohup ./kibana --allow-root &
3.4filbeat安装与配置

解压,然后编辑配置文件filebeat.yml

这里配置选择test所有的log文件,并将enable设为true

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.

- type: log

  # Change to true to enable this input configuration.
  enabled: true

  # Paths that should be crawled and fetched. Glob based paths.
  paths:
    - /Users/guapikang/logback/test/*.log
    #- c:\programdata\elasticsearch\logs\*

因为解决方案是将日志交给logstash集中处理而不是elesticsearch,所以这里注释掉elesticsearch的配置

# ---------------------------- Elasticsearch Output ----------------------------
# output.elasticsearch:
#   # Array of hosts to connect to.
#   hosts: ["localhost:9200"]

  # 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的地址与端口

# ------------------------------ 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"

三、启动

1、启动顺序

es=>logstash=>kibana=>filebeat

2、效果展示

配置好kibana索引之后,就可以查看日志了



欢迎加入我的知识星球,一起探讨架构,交流源码。加入方式,长按下方二维码噢

已在知识星球更新源码解析如下:

最近更新《芋道 SpringBoot 2.X 入门》系列,已经 101 余篇,覆盖了 MyBatis、Redis、MongoDB、ES、分库分表、读写分离、SpringMVC、Webflux、权限、WebSocket、Dubbo、RabbitMQ、RocketMQ、Kafka、性能测试等等内容。

提供近 3W 行代码的 SpringBoot 示例,以及超 4W 行代码的电商微服务项目。

获取方式:点“在看”,关注公众号并回复 666 领取,更多内容陆续奉上。

文章有帮助的话,在看,转发吧。

谢谢支持哟 (*^__^*)

微信扫码关注该文公众号作者

戳这里提交新闻线索和高质量文章给我们。
相关阅读
Is China dangerous?599的可视化空气炸锅,月销上千,而你捡漏只要200多新一代基线资料表R包,10min学会精美可视化结果!平方差公式的可视化演示...(待会删)yyds!网易内部PPT数据可视化学习资源,请低调使用!"𝙇𝙚𝙖𝙙 𝙏𝙝𝙚 𝘾𝙝𝙖𝙧𝙜𝙚"广告#创译挑战8、9月网剧备案:同比下降36.7% ,网文IP影视化占比17.4%一月排期速报:EB-1排期时代终于到来了!EB-1排期时代,你该怎么办?分布式实时日志分析解决方案 ELK 部署架构广州多区解除社会面临时管控!海珠区符合条件的密接、阳性可居家隔离!专家:无接触感染概率低,但需细化方案一款开源的数据可视化分析平台,提供多种大屏模板,非常炫酷玩游戏学CUDA?试试这个可视化解谜项目白纸皆兵3天上手!摩根大通点名的可视化工具,留学生速领!Nginx 可视化神器!复杂配置一键生成,监控管理一条龙!原来摩根大通点名的可视化工具,留学生3天就能轻松上手!分布式实时日志:ELK 的部署架构方案限时领!摩根大通点名的可视化工具,初学小白3天就能上手!【首发】一目可视完成数千万元天使轮融资,瞄准医学可视化构造生物医学知识库在美国313.旧地重游美国移民2023年1月排期公布:EB1重回排期时代,EB5预留类别保持无排期FastTrack Universität 2023莱比锡大学公立语言项目招生简章最航运 | 解析亚马逊刚发布的供应链数字化可视化应用!方便实用的可视化空气炸锅,让的你年夜饭出彩iBUILDING数字孪生中台正式发布,可视化管理加速智慧建筑发展推荐一款 JSON 可视化工具神器!最牛财务Excel资料+300套可视化案例250套经典模板丢掉Excel,手把手教你用Python做可视化数据,还能任意调节动画丝滑度The Empty Playground5 款顶级 Docker 可视化管理工具,免费又好用!在线研讨会:InfiniBand 池化方案与存算分离数据库 | 直播预告速领!摩根大通点名的可视化工具,留学生3天就能轻松上手!13 款炫酷的 MySQL 可视化管理工具!美国移民2023年4月排期公布:EB-1原地踏步,EB-5预留签证类别无排期美国入境档案--赵一荻、张闾琳和张学森
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。