侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

ELK + Filebeat 搭建日志系统流程步骤

技术  /  管理员 发布于 2年前   658

一、ELK+filebeat系统介绍

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


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


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


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


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


大致流程图如下:

ELK+filebeat.png


二、搭建

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

# ---------------------------------- 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索引之后,就可以查看日志了

elastic.png



  • 上一条:
    在laravel中以curl的方式请求京东联盟api获取数据流程步骤
    下一条:
    在Go语言中如何查找一个IP地址的网络地址?
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 2024.07.09日OpenAI将终止对中国等国家和地区API服务(0个评论)
    • 2024/6/9最新免费公益节点SSR/V2ray/Shadowrocket/Clash节点分享|科学上网|免费梯子(1个评论)
    • 国外服务器实现api.openai.com反代nginx配置(0个评论)
    • 2024/4/28最新免费公益节点SSR/V2ray/Shadowrocket/Clash节点分享|科学上网|免费梯子(1个评论)
    • 近期文章
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2017-07
    • 2017-08
    • 2017-09
    • 2018-01
    • 2018-07
    • 2018-08
    • 2018-09
    • 2018-12
    • 2019-01
    • 2019-02
    • 2019-03
    • 2019-04
    • 2019-05
    • 2019-06
    • 2019-07
    • 2019-08
    • 2019-09
    • 2019-10
    • 2019-11
    • 2019-12
    • 2020-01
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2020-07
    • 2020-08
    • 2020-09
    • 2020-10
    • 2020-11
    • 2021-04
    • 2021-05
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-12
    • 2022-01
    • 2022-02
    • 2022-03
    • 2022-04
    • 2022-05
    • 2022-06
    • 2022-07
    • 2022-08
    • 2022-09
    • 2022-10
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-04
    • 2023-05
    • 2023-06
    • 2023-07
    • 2023-08
    • 2023-09
    • 2023-10
    • 2023-12
    • 2024-02
    • 2024-04
    • 2024-05
    • 2024-06
    • 2025-02
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客