ELK日志平台(elasticsearch+logstash+kibana)搭建

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


前言

为了实现分布式日志数据统一收集,实现集中式查询和管理 故障排查 安全信息和事件管理


一、ELK是什么?

ELK 是三个开源项目的首字母缩写,这三个项目分别是:ElasticsearchLogstashKibana

• Elasticsearch 是一个搜索和分析引擎。

• Logstash 是服务器端数据处理管道,能够同时从多个来源采集数据,转换数据,然后将数据发送到诸如 Elasticsearch 等存储库中。

• Kibana 则可以让用户在 Elasticsearch 中使用图形和图表对数据进行可视化。

其中filbeat是安装到web端的服务器进行日志采集

在这里插入图片描述

二、安装步骤

注意好对应的版本!!! (该教程使用的是7.13.2版本)

1.es(Elasticsearch)安装配置

由于一开始装的是7.10.2的所以截图中是7.10.2,版本不对应的话会出现版本冲突问题,后续统一调整为了7.13.2版本

创建es用户组:groupadd es
在es用户组下创建es用户:useradd es -g es -p es

进入es用户
[root@iZj6c49h0dw85252u6oxu0Z ~]# su es

下载安装包或者上传安装包
[es@iZj6c49h0dw85252u6oxu0Z data]$ wget https://artifacts.elastic.co/downloads/elasticsearch/eelasticsearch-7.13.2-linux-x86_64.tar.gz

解压
[es@iZj6c49h0dw85252u6oxu0Z data]$ tar -zxvf elasticsearch-7.13.2-linux-x86_64.tar.gz 

赋予用户权限:chown -R es:es /data/elasticsearch-7.13.2

启动es
[es@iZj6c49h0dw85252u6oxu0Z es]$ cd elasticsearch-7.13.2/
[es@iZj6c49h0dw85252u6oxu0Z elasticsearch-6.5.0]$ bin/elasticsearch -d
修改三个配置文件,文件中添加
export JAVA_HOME=/data/elasticsearch-7.13.2/jdk
export PATH=$JAVA_HOME/bin:$PATH

在这里插入图片描述

在/data/elasticsearch-7.13.2/config 中修改配置

在这里插入图片描述

服务器中验证  curl http://内网ip:9200

在这里插入图片描述


出现该画面就是按照配置成功启动了!

可以修改 /elasticsearch-7.13.2/config/jvm.options 文件
分配运行内存
-Xms4g
-Xmx4g

安装时遇到的问题:

错误问题

一
[root@izuf672oio5mc4fbyj0s0jz ~]# curl http://47.244.38.173:9200/
curl: (7) Failed connect to 47.244.38.173:9200; Connection refused

修改elasticsearch.yml文件,去掉注释并修改IP:network.host: 0.0.0.0,并开通入方向的阿里云访问规则,再次启动ES就可以了
[es@izuf672oio5mc4fbyj0s0jz elasticsearch-6.5.0]$ vi config/elasticsearch.yml 


二
[1] bootstrap checks failed
[1]: max file descriptors [65535] for elasticsearch process is too low,increase to at least [65536]

root用户下修改/etc/security/limits.conf
:su root
vim /etc/security/limits.conf

1.修改内容:
root soft nofile 65535
root hard nofile 65535
* soft nofile 65536
* hard nofile 65536

2.修改/etc/sysctl.conf
最后新增vm.max_map_count=655360
修改完成后,执行 sysctl -p 命令,使配置生效

2.Logstash安装配置

上传并解压
tar -zxvf logstash-7.13.2-linux-x86_64.tar.gz
解压完之后进入/config,拷贝一份logstash-sample.conf到bin目录下,方便后面启动:
cp /data/logstash-7.13.2/config/logstash-sample.conf /data/logstash-7.13.2/config/logstash.conf
编辑以下内容拷贝到bin的logstash.conf

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

input {
  beats {
    port => 5044
  }
}

# log.file.path=/data/jars/logs/charge-server/charge-server-2023-08-29.5.log
# index => "%{[@metadata][beat]}}-%{+YYYY.MM.dd}"
# index => "%{[fields][log_type]}-%{+YYYY.MM.dd}"

output {
    elasticsearch {
      hosts => ["http://localhost:9200"]
      index => "%{[fields][log_type]}-%{+YYYY.MM.dd}"
      #user => "elastic"
      #password => "changeme"
  }
 
}
服务器后台启动
nohup bin/logstash -f config/logstash.conf > /dev/null 2>&1 &
    
应用命令启动(可实时看到启动日志)
bin/logstash -f config/logstash.conf

3.Kibana安装与配置

上传并解压
tar -zxvf kibana-7.13.2-linux-x86_64.tar.gz
编辑/config/kibana.yml

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

kibana也不能使用root用户启动

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

#es的hosts
elasticsearch.hosts: ["http://192.xxx.x.211:9200"]
cd kibana-7.13.2-linux-x86_64/bin/
    
启动    
./kibana --allow-root &
nohup ./kibana --allow-root &

日志路径
/data/ELK/kibana-7.13.2-linux-x86_64/config/node.options

4.Filbeat安装与配置

上传并解压
tar -zxvf filebeat-7.13.2-linux-x86_64.tar.gz
编辑/filebeat-7.13.2-linux-x86_64/filebeat.yml

filebeat.inputs:

- type: log
  enabled: true
  paths:
    # 地址是服务的日志地址
    - /data/jars/logs/base-server/*.log
    #- c:\programdata\elasticsearch\logs\*
  fields:
    log_type: "base-server"

#多个服务就在后面追加
- type: log
  enabled: true
  paths:
    - /data/jars/logs/finance-server/*.log
    #- c:\programdata\elasticsearch\logs\*
  fields:
    log_type: "finance-server"
    

- type: filestream

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

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


# ============================== Filebeat modules ==============================

filebeat.config.modules:
  # Glob pattern for configuration loading
  path: ${path.config}/modules.d/*.yml

  # Set to true to enable config reloading
  reload.enabled: false

  # 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




# =================================== 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:


#日志是推送到Logstash,# ------------------------------ Logstash Output -------------------------------
output.logstash:
  #The Logstash hosts
  #配置安装Logstash所在的服务器ip
  hosts: ["127.0.0.1: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 =================================
processors:
  - add_host_metadata:
      when.not.contains.tags: forwarded
  - add_cloud_metadata: ~
  - add_docker_metadata: ~
  - add_kubernetes_metadata: ~
启动运行
nohup ./filebeat -e -c filebeat.yml > /dev/null 2>&1 &
./filebeat -e -c filebeat.yml

遇到的问题:

不定时间,filebeat就会自动退出或者ssh连接断开filebeat自动退出

1后台启动
`nohup ./filebeat -e -c filebeat.yml > /dev/null 2>&1 &`

2不要直接关闭终端,而是先执行命令exit后

3关闭shh连接终端

最后ip:5601访问kibana 至此安装完毕!


总结

例如:以上就是今天要讲的内容,本文仅仅简单介绍了ELK的安装,而ELK其他强大的功能需要继续学习

原文地址:https://blog.csdn.net/qq_44474979/article/details/134963092

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


文章浏览阅读774次,点赞24次,收藏16次。typescript项目中我们使用typings-for-css-modules-loader来替代css-loader实现css modules。1、typings-for-css-modules-loader加载器介绍 Webpack加载器,用作css-loader的替代产品,可动态生成CSS模块的TypeScript类型这句话是什么意思呢?就是编译时处理css文件...
文章浏览阅读784次。react router redux antd eslint prettier less axios_react+antd+redux+less
文章浏览阅读3.9k次,点赞5次,收藏11次。需要删除.security-7索引文件。把在第1步中的被注释的配置打开。之后就是按照提示输入密码。执行bin目录下的文件。_failed to authenticate user 'elastic' against
文章浏览阅读1.2k次,点赞23次,收藏24次。Centos 8 安装es_centos8 yum elasticsearch
文章浏览阅读3.2k次。设置完之后,数据会⾃动同步到其他节点。修改密码时,将第⼀步配置删除,然后重启。单独使⽤⼀个节点⽣成证书;执⾏设置⽤户名和密码的命令。执⾏完上⾯命令以后就可以在。⽂件,在⾥⾯添加如下内容。这个⽂件复制到其他节点下。其中⼀个节点设置密码即可。依次对每个账户设置密码。全部节点都要重启⼀遍。需要在配置⽂件中开启。个⽤户分别设置密码,⽬录下,证书⽂件名为。功能,并指定证书位置。_es设置账号和密码
文章浏览阅读1.9k次,点赞2次,收藏7次。针对多数据源写入的场景,可以借助MQ实现异步的多源写入,这种情况下各个源的写入逻辑互不干扰,不会由于单个数据源写入异常或缓慢影响其他数据源的写入,虽然整体写入的吞吐量增大了,但是由于MQ消费是异步消费,所以不适合实时业务场景。不易出现数据丢失问题,主要基于MQ消息的消费保障机制,比如ES宕机或者写入失败,还能重新消费MQ消息。针对这种情况,有数据强一致性要求的,就必须双写放到事务中来处理,而一旦用上事物,则性能下降更加明显。可能出现延时问题:MQ是异步消费模型,用户写入的数据不一定可以马上看到,造成延时。_mysql同步es
文章浏览阅读3.6w次,点赞48次,收藏44次。【程序员洲洲送书福利-第十九期】《C++ Core Guidelines解析》
文章浏览阅读1.3k次。当我们在开发Vue应用时,经常需要对表单进行校验,以确保用户输入的数据符合预期。Vue提供了一个强大的校验规则机制,通过定义rules规则,可以方便地对表单进行验证,并给出相应的错误提示。_vue ruler校验
文章浏览阅读2k次,点赞16次,收藏12次。Linux内核源码下载地址及方式_linux源码下载
文章浏览阅读1k次。这样在每天自动生成的索引skywalking_log_xxx就会使用上述模版来生成,timestamp会被设置成date类型。然后此时在–>索引管理–>kibana–>索引模式添加skywalking_log*索引时就会有时间字段了。在通过skywalking将日志收集到es后,由于skywalking收集的日志(skywalking_log索引)没有date类型的字段导致在es上再索引模式中没有时间范围的查询。skywalking收集的日志有时间戳字段timestamp,只是默认为long类型。_skywalking timestamp
文章浏览阅读937次,点赞18次,收藏21次。1.初始化git仓库,使用git int命令。2.添加文件到git仓库,两步走:2.1 使用命令,注意,可反复多次使用,添加多个文件;2.2 使用命令,完成。此笔记是我个人学习记录笔记,通过廖雪峰的笔记进行学习,用自己能理解的笔记记录下来,如果侵权,联系删。不存在任何盈利性质,单纯发布后,用于自己学习回顾。
文章浏览阅读786次,点赞8次,收藏7次。上述示例中的 origin 是远程仓库的名称,https://github.com/example/repository.git 是远程仓库的 URL,(fetch) 表示该远程仓库用于获取更新,(push) 表示该远程仓库用于推送更新。你可以选择在本地仓库创建与远程仓库分支对应的本地分支,也可以直接将本地仓库的分支推送到远程仓库的对应分支。将 替换为远程仓库的名称(例如 origin), 替换为要推送的本地分支的名称, 替换为要推送到的远程分支的名称。_git remote 智能切换仓库
文章浏览阅读1.5k次。配置eslint校验代码工具_eslint 实时校验
文章浏览阅读1.2k次,点赞28次,收藏26次。Git入门基础介绍,什么是Git,如何使用Git,以及Git的工作的基本原理
文章浏览阅读2.7k次。基于官方给出的几种不同环境不同的安装方式,本文将会选择在使用.zip文件在Windows上安装Elasticsearch在Linux或macOS上从存档文件安装ElasticsearchInstall Elasticsearch with Docker (此种方式待定)使用Docker安装Elasticsearch。_elasticsearch安装部署windows
文章浏览阅读3.3k次,点赞5次,收藏11次。【Linux驱动】内核模块编译 —— make modules 的使用(单模块编译、多模块编译)_make modules
文章浏览阅读1k次。docker启动es报错_max virtual memory areas vm.max_map_count [65530] is too low, increase to at
文章浏览阅读4.2k次,点赞2次,收藏6次。使用docker单机安装elasticsearch后再安装kibana时找不到es。_unable to retrieve version information from elasticsearch nodes. security_ex
文章浏览阅读1.1k次。日志处理对于任何现代IT系统都是关键部分,本教程专为新手设计,通过详细解释Logstash的三大核心组件,为您展示如何从零开始搭建强大的日志处理系统。您还将学习如何同步MySQL数据到Elasticsearch,并通过一个"Hello World"示例快速入门。无论您是完全的新手还是有一些基础,本教程都将引导您顺利掌握Logstash的基本操作和高级应用。_logstash mysql
文章浏览阅读1.1w次,点赞5次,收藏25次。执行这条指令之后,你的本地项目就与远程Git仓库建立了连接,你就可以开始对你的代码进行版本追踪和协作开发了。使用“git remote add origin”指令,可以轻松地将本地项目连接到远程Git仓库。git remote set-url origin 执行这条指令之后,Git就会将已经添加的名为“origin”的仓库删除。git remote add origin 其中,是你的远程Git仓库的网址。_git remote add origin