首页 > 其他分享 >最新版本ELFK-8.10部署实战

最新版本ELFK-8.10部署实战

时间:2023-11-13 10:03:13浏览次数:21  
标签:实战 ELFK elastic kibana elasticsearch Elasticsearch 日志 rpm 8.10

一 背景

在现代软件系统中,日志是非常重要的组成部分。它们记录了系统的运行状态、错误消息、用户活动等信息。然而,当系统规模变大并且涉及多个组件时,日志管理变得非常复杂。传统的日志管理方法可能会面临一些挑战,包括集中化存储、检索和分析日志数据的困难。

ELK是一套流行的开源工具集,用于解决这些日志管理挑战。它由以下三个主要组件组成: ELFK(Elasticsearch、Logstash、Filebeat、Kibana)是一套用于实时日志分析和监控的解决方案。它由一系列开源工具组成,各自担当不同的角色。Elasticsearch用于存储和索引日志数据,Logstash用于日志的收集、过滤和转发,Filebeat用于轻量级的日志收集,而Kibana用于可视化和分析日志数据。

二 相关概念

  1. Elasticsearch:Elasticsearch是一个基于Lucene的分布式搜索和分析引擎。它被广泛用于存储、搜索和分析各种类型的数据,包括结构化、非结构化和地理位置数据。Elasticsearch具有高性能、可伸缩性和强大的搜索功能,以及实时数据索引和聚合的能力。
  2. Logstash:Logstash是一个用于日志数据收集、过滤和转发的开源工具。它可以从各种来源(如文件、数据库、消息队列等)收集日志数据,并将其进行处理和转换,然后发送到目标存储或分析系统(如Elasticsearch)中。
  3. Kibana:Kibana是一个基于Web的开源工具,用于实时分析和可视化存储在Elasticsearch中的数据。它提供了丰富的图表、图形和仪表板,使用户可以直观地探索和呈现数据,发现趋势、模式和异常情况,并生成自定义的可视化报告。

最新版本ELFK-8.10部署实战_Logstash

最新版本ELFK-8.10部署实战_elasticsearch_02

三 前提条件

  1. 硬件要求:ELK堆栈是资源密集型的应用程序,因此确保目标部署环境具备足够的计算资源和存储空间,以满足您的需求。这包括CPU、内存和存储设备。
  2. 网络连接:确保目标部署环境具有稳定的网络连接,以便ELK组件之间能够相互通信,并且客户端可以访问Kibana进行日志分析和可视化。
  3. 安全设置:根据您的安全要求,配置适当的防火墙规则和访问控制策略,以确保对ELK组件的访问受到限制并保护系统免受未经授权的访问。
  4. 日志源配置:在部署ELK之前,确定您希望收集和处理的日志源。这可以是应用程序生成的日志文件、系统日志、网络设备日志等。确保您了解日志源的位置、格式和访问权限。
  5. ELK版本选择:确定您希望部署的ELK版本。ELK的组件(Elasticsearch、Logstash和Kibana)有不同的版本和兼容性要求。选择适合您需求和环境的版本,并确保它们之间的兼容性。
  6. 配置和定制化:根据您的需求,对ELK组件进行适当的配置和定制化。这可能包括修改Elasticsearch的索引设置、Logstash的数据处理管道和过滤规则,以及Kibana的仪表板和可视化设置。

四 安装部署

4.2 Linux系统配置

  • 调整进程最大打开文件数数量
vim /etc/security/limits.conf
# 直接末尾添加限制
es soft nofile 65536
es hard nofile 65536
es soft nproc 65535
es hard nproc 65535
  • 调整进程最大虚拟内存区域数量
echo vm.max_map_count=262144>> /etc/sysctl.conf
echo "fs.file-max = 1000000" >> /etc/sysctl.conf
sysctl -p

4.3 ELK安装部署

在此安装ELK版本 8.10

4.3.1 ElasticSearch安装

Elasticsearch包含来自JDK维护者(GPLv2+CE)的捆绑版本的OpenJDK。因此可以不用提前自己安装JDK。

  • 下载并安装公共签名密钥:
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

下载es rpm包并安装

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.10.0-x86_64.rpm
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.10.0-x86_64.rpm.sha512
shasum -a 512 -c elasticsearch-8.10.0-x86_64.rpm.sha512 
sudo rpm --install elasticsearch-8.10.0-x86_64.rpm


# 安装完成输出
Creating elasticsearch group... OK
Creating elasticsearch user... OK
--------------------------- Security autoconfiguration information ------------------------------

Authentication and authorization are enabled.
TLS for the transport and HTTP layers is enabled and configured.

The generated password for the elastic built-in superuser is : 6R-hxNMSxxxxxtxwW

If this node should join an existing cluster, you can reconfigure this with
'/usr/share/elasticsearch/bin/elasticsearch-reconfigure-node --enrollment-token <token-here>'
after creating an enrollment token on your existing cluster.

You can complete the following actions at any time:

Reset the password of the elastic built-in superuser with
'/usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic'.

Generate an enrollment token for Kibana instances with
 '/usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana'.

Generate an enrollment token for Elasticsearch nodes with
'/usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s node'.

-------------------------------------------------------------------------------------------------
### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemd
 sudo systemctl daemon-reload
 sudo systemctl enable elasticsearch.service
### You can start elasticsearch service by executing
 sudo systemctl start elasticsearch.service
[/usr/lib/tmpfiles.d/elasticsearch.conf:1] Line references path below legacy directory /var/run/, updating /var/run/elasticsearch → /run/elasticsearch; please update the tmpfiles.d/ drop-in file accordingly.
  • 启动

安装Elasticsearch时,默认开启并配置了安全特性。安装Elasticsearch时,会自动进行如下安全配置: 启用认证授权,并为弹性内置超级用户生成密码。 TLS的证书和密钥是为传输层和HTTP层生成的,TLS是用这些密钥和证书启用和配置的。 将密码、证书和密钥输出到您的终端。 我们建议将弹性密码存储为shell中的环境变量。例子:

export ELASTIC_PASSWORD="your_password"

加入以有集群

/usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s node

/usr/share/elasticsearch/bin/elasticsearch-reconfigure-node --enrollment-token <enrollment-token>
  • 配置ES服务自启动

配置Elasticsearch在系统启动时自动启动,使用如下命令:

sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service

# 但节点ES配置 /etc/elasticsearch/elasticsearch.yml

注释 cluster.initial_master_nodes: ["localhost"]

并添加 discovery.type: single-node


sudo systemctl start elasticsearch.service
  • 重制elastic密码
[root@VM-48-14-centos ~]# /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic
This tool will reset the password of the [elastic] user to an autogenerated value.
The password will be printed in the console.
Please confirm that you would like to continue [y/N]y


Password for the [elastic] user successfully reset.
New value: 6MhAxxxxxxxxxtW

如果您的Elasticsearch密钥存储库有密码保护,则需要使用本地文件和systemd环境变量向systemd提供密钥存储库密码。这个本地文件应该在它存在的时候受到保护,并且可以在Elasticsearch启动并运行后安全地删除。

echo "keystore_password" > /path/to/my_pwd_file.tmp
chmod 600 /path/to/my_pwd_file.tmp
sudo systemctl set-environment ES_KEYSTORE_PASSPHRASE_FILE=/path/to/my_pwd_file.tmp
sudo systemctl start elasticsearch.service

查看日志

sudo journalctl --unit elasticsearch
  • 检查服务状态
[root@VM-48-14-centos ~]# curl --cacert /etc/elasticsearch/certs/http_ca.crt -u elastic:6MhAuNxxxxxxdtW https://localhost:9200
{
  "name" : "elk-host",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "cLLsiBX1ToirQuBKwyA-1g",
  "version" : {
    "number" : "8.10.0",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "e338da74c79465dfdc204971e600342b0aa87b6b",
    "build_date" : "2023-09-07T08:16:21.960703010Z",
    "build_snapshot" : false,
    "lucene_version" : "9.7.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}
  • 查看ES配置
[root@VM-48-14-centos ~]# egrep -v "^#|^$" /etc/elasticsearch/elasticsearch.yml
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
discovery.type: single-node
xpack.security.enabled: true
xpack.security.enrollment.enabled: true
xpack.security.http.ssl:
  enabled: true
  keystore.path: certs/http.p12
xpack.security.transport.ssl:
  enabled: true
  verification_mode: certificate
  keystore.path: certs/transport.p12
  truststore.path: certs/transport.p12
http.host: 0.0.0.0

配置自动索引

PUT _cluster/settings
{
    "persistent": {
        "action.auto_create_index": "true" 
    }
}


GET _cluster/settings

4.3.2 Kibana安装

rpm安装kibana,版本为:8.10

wget https://artifacts.elastic.co/downloads/kibana/kibana-8.10.2-x86_64.rpm
wget https://artifacts.elastic.co/downloads/kibana/kibana-8.10.2-x86_64.rpm.sha512
shasum -a 512 -c kibana-8.10.2-x86_64.rpm.sha512 
sudo rpm --install kibana-8.10.2-x86_64.rpm

# 设置kibana开机自启动
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable kibana.service
  • 为kibana生成token
[root@elk-host ~]# /usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana
eyJ2ZXIiOiI4LjEwLjAiLCJhZHIiOlsiMTcyLjE3LjQ4LjE0OjkyMDAiXSwiZmdyIjoiMTk0MTM0MzQ4NTg5M2Y2Y2Y3xxxxxxxcyYmU4ZTM5NDNmMzg5Mzc0MjA2ZTE4MSIsImtleSI6Ikt5cTlEb3NCR20tYS1uXzNkQ0JEOmlMODEtNWNqU25Da0dkV0o3LXB2VkEifQ==
  • 启动kibana
# 修改kibana 监听0.0.0.0
server.host: 0.0.0.0

输入token

最新版本ELFK-8.10部署实战_elastic_03

最新版本ELFK-8.10部署实战_elasticsearch_04

最新版本ELFK-8.10部署实战_Elasticsearch_05

最新版本ELFK-8.10部署实战_elastic_06

配置完成后,通过es的用户名密码登陆

elastic:6MhAuNxxxxxxxxkdtW

最新版本ELFK-8.10部署实战_elastic_07

4.3.3 Logstash安装

Logstash版本为8.10

使用yum安装

  • 配置yum源并安装
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

# 写入es yum仓库源
cat > /etc/yum.repos.d/logstash.repo <<EOF
[logstash-8.x]
name=Elastic repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF

# 安装
yum -y install logstash.x86_64

# 配置开机自启动
systemctl enable logstash
  • 测试Logstash

最新版本ELFK-8.10部署实战_elastic_08

[root@elk-host ~]# /usr/share/logstash/bin/logstash -e 'input { stdin { } } output { stdout {} }'

最新版本ELFK-8.10部署实战_elasticsearch_09

  • 配置logstash

查看初始logstash配置

[root@elk-host ~]# egrep -v "^#|^$" /etc/logstash/logstash.yml
path.data: /var/lib/logstash
path.logs: /var/log/logstash
  • 配置与ES对接,数据源为Filebeat
cat > /etc/logstash/conf.d/logstash-filebeat.conf <<EOF
input {
  beats {
    port => 5044
  }
}

output {
  elasticsearch {
    hosts => ["https://127.0.0.1:9200"]
    #index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
    index => "logstash-%{+YYYY.MM.dd}"
    ssl_certificate_verification => false
    user => "elastic"
    password => "6MxxxxxxxxdtW"
  }
}
EOF
  • 启动服务
systemctl start logstash

4.3.3 Filebeat安装

最新版本ELFK-8.10部署实战_Logstash_10

安装8.10 rpm包安装方式

  • 安装
curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-8.10.2-x86_64.rpm
sudo rpm -vi filebeat-8.10.2-x86_64.rpm

# 开机自启动
systemctl enable filebeat
  • 配置filebeat

先简单配置本地日志文件,输出到logstash

filebeat.inputs:
- type: filestream

  # 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:
    - /var/log/*.log
output.logstash:
  # The Logstash hosts
  hosts: ["localhost:5044"]

查看filebeat日志

journalctl -fu filebeat

五 测试

最新版本ELFK-8.10部署实战_Elasticsearch_11

最新版本ELFK-8.10部署实战_elasticsearch_12

六 注意事项

  • kibana如果报错,可以进入es容器内执行reset kibana_system用户密码:elasticsearch-reset-password -i -u kibana_system

参考链接

标签:实战,ELFK,elastic,kibana,elasticsearch,Elasticsearch,日志,rpm,8.10
From: https://blog.51cto.com/kaliarch/8337149

相关文章

  • Filebeat采集AWS S3作为输入源实战
    一背景在现代应用程序和系统中,日志数据的收集和分析是至关重要的。AWSS3(AmazonSimpleStorageService)是一种高度可扩展的对象存储服务,许多组织选择将其用作存储和备份日志文件的中心存储库。Filebeat是一款轻量级的日志数据传输工具,它可以收集、解析和传输日志数据到其他系统进......
  • java项目实战-spring-基本用法01-day24
    目录1.spring简单介绍2.IOC/DI--控制反转--是啥3.实现3.如果对象的属性为引用数据类型如何实例化对象4如何用注解的方式以少量的代码实现对象的创建于获取1.spring简单介绍https://spring.io什么事SSM?spring-mvcspring-framework--web服务层mybatis--......
  • 容器日志采集的三种方式实战操作讲解(Filebeat)
    目录一、概述二、K8s集群部署三、ElasticSearch和kibana环境部署1)部署docker2)部署docker-compose3)创建网络4)修改Linux句柄数和最大线程数5)下载部署包开始部署四、容器日志采集的三种方式实战操作1)【第一种方式】:Filebeat与应用运行在同一容器(不推荐)1、下载Trinoonk8s......
  • Apache DolphinScheduler实战(07)-缓存机制
    1缓存目的由于M/S调度过程中,会产生大量数据库读操作,如tenant,user,processDefinition等:对DB产生很大读压力使整个核心调度流程变慢考虑这部分业务数据读多写少,引入缓存模块:减少DB读压力,加快核心调度流程。2缓存设置spring:cache:#defaultenablecache,youcand......
  • java项目实战-mybatis-基本用法02接口绑定实现类-day23
    目录1.复习什么是接口什么是类?2.mybatis接口绑定实现类来实现查询3.参数的传递4插入数据1.复习什么是接口什么是类?publicinterfaceSpeak{voidsay();}Speak这个接口里面定义了say方法所有实现了Speak的类都必须实现say方法publicclassChineseimpl......
  • 《实战Java高并发程序——第1章 走入并行世界》
    基础平台Java虚拟机,虚拟机除了要执行main函数外,还需要做JIT编译和垃圾回收。无论是main函数、JIT编译还是垃圾回收,在虚拟机内部都是一个单独的线程。多核CPU:将多个独立的计算单元整合到单独的CPU中如何让多个CPU内核有效并正确地工作也就成了一门技术。如多线程间如何保证线程......
  • 解码知识图谱:从核心概念到技术实战
    知识图谱是近年来人工智能和数据科学领域的焦点。本文深入探索了知识图谱的核心概念、发展历程、研究内容以及其在表示、存储、获取、构建和推理方面的技术细节。结合Python和PyTorch示例代码,文章旨在为读者提供一个全面、深入且实用的知识图谱概览,帮助广大技术爱好者和研究者深化......
  • 云原生架构实战07 Kubernetes的核心实战 下
    7、存储抽象pod如果挂掉,在其他的机器启动新pod,原来pod的数据是无法迁移到新机器的;所以使用单独的存储层来解决。将节点上的文件或目录挂载到pod上,此时该目录会变成持久化存储目录,即使Pod被删除后重启,也可以重新加载到该目录,该目录下的文件不会丢失。nfs卷能将NFS(网络文件系统)挂载......
  • 解码知识图谱:从核心概念到技术实战
    知识图谱是近年来人工智能和数据科学领域的焦点。本文深入探索了知识图谱的核心概念、发展历程、研究内容以及其在表示、存储、获取、构建和推理方面的技术细节。结合Python和PyTorch示例代码,文章旨在为读者提供一个全面、深入且实用的知识图谱概览,帮助广大技术爱好者和研究者深......
  • 抖音小程序开发实战:打造独特品牌体验的代码之旅
    抖音小程序的崛起为品牌提供了一个全新的数字化平台,而通过深入的抖音小程序开发,品牌不仅能够提升曝光度,更能打造独特的用户体验。在本文中,我们将深入研究抖音小程序开发的关键技术要点,并通过实际代码演示,带领读者走进这个充满创新和技术魅力的开发世界。1.建立小程序基础框架首先,......