1.介绍
Elastic Stack 包含:
- Elasticsearch: 基于Json的分布式搜索和分析引擎
- Logstash: 动态数据收集管道,生态丰富
- Kibana: 提供数据的可视化界面
- Beats: 轻量级的数据采集器
1.1 Elasticsearch 核心
- 搜索、聚合分析、大数据存储
- 布式、高性能、高可用、可伸缩、易维护
- 支持文本搜索、结构化数据、非结构化数据、地理位置搜索等
全文本搜索只是全球众多公司利用 Elasticsearch 解决各种挑战的冰山一角
1.2 Logstash
- 采集: 数据往往以各种各样的形式,或分散或集中地存在于很多系统中。Logstash 支持各种输入选择,可以同时从众多常用来源捕捉事件。能够以连续的流式传输方式,轻松地从您的日志、指标、Web 应用、数据存储以及各种 AWS 服务采集数据。
- 过滤: Logstash 能够动态地转换和解析数据,不受格式或复杂度的影响
- 利用 Grok 从非结构化数据中派生出结构
- 从 IP 地址破译出地理坐标
- PII 数据匿名化,完全排除敏感字段
- 简化整体处理,不受数据源、格式或架构的影响
- 输出: Elasticsearch 是官方首选输出方式,但并非唯一选择。Logstash 提供多种输出选择,目前官方支持200 多个插件
1.3 Kibana Elastic Stack的窗户
- 可视化:
- 图表:柱状图、线状图、饼图、旭日图等
- 位置分析:位置搜索、形状搜索、地图检测等
- 时序分析:可以方便的从各种不同时间维度查看
- 管理和监控:
- 机器学习:非监督型异常和隐患检测
- 安全监控:堆栈检测、异常报警、策略可配置
- 柱状图、线状图、饼图、旭日图等
Beats 轻量级数据采集器
- 开源:Beats 是一个免费且开放的平台,集合了多种单一用途数据采集器。它们从成百上千或成千上万台机器和系统向 Logstash 或 Elasticsearch 发送数据。
- 轻量级:Beats使用go语言开发,对服务器资源占用极低。Beats 可以采集符合 Elastic Common Schema (ECS) 要求的数据,可以将数据转发至 Logstash 进行转换和解析。
- 即插即用:Filebeat 和 Metricbeat 中包含的一些模块能够简化从关键数据源(例如云平台、容器和系统,以及网络技术)采集、解析和可视化信息的过程。只需运行一行命令,即可开始探索。
- 可扩展:由于Beats开源的特性,如果现有Beats不能满足开发需要,我们可以自行构建,并且完善Beats社区
2.Elaltic Search 部署
- 版本选择:最好是java 8、java11或者java14
- jdk兼容性:www.elastic.co/cn/support/…
- 操作系统兼容性:www.elastic.co/cn/support/…
- 自身兼容性:www.elastic.co/cn/support/…
- 下载地址:www.elastic.co/cn/download…
2.1 启动(只能本机访问)
直接下载解压
# 进入 elastic search bin目录
cd /opt/elasticsearch-7.10.0/bin
./elasticsearch
报错:
java.lang.RuntimeException: can not run elasticsearch as root
修改方式: 为elaticsearch创建用户并赋予相应权限
# 为 ES 创建用户
adduser es
passwd es
cd /opt
# 将 es 安装包的所属用户和所属组修改为 es 用户(赋予 es 相应权限)
chown -R es elasticsearch-7.10.0
chgrp -R es elasticsearch-7.10.0
再次启动 OK !!!
但是发现默认 elastic search 绑定 127.0.0.1, 只能在本机访问,无法通过其他主机访问.
2.2 其他主机可以访问
修改配置文件: /opt/elasticsearch-7.10.0/config/elasticsearch.yml
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
启动时报错
[2021-09-26T20:13:57,469][INFO ][o.e.b.BootstrapChecks ] [gFOuNlS] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [2] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
修改方式: blog.csdn.net/feng12345zi…
再次启动,仍然报错
[2021-09-26T20:13:57,469][INFO ][o.e.b.BootstrapChecks ] [izbp111ufnem4hmxlrejs6z] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [1] bootstrap checks failed
[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
ERROR: Elasticsearch did not exit normally - check the logs at /opt/elasticsearch-7.10.0/logs/elasticsearch.log
修改方式: blog.csdn.net/qq_43655835…
修改配置文件:/opt/elasticsearch-7.10.0/config/elasticsearch.yml
node.name: node-1
# --------------------------------- Discovery ----------------------------------
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["node-1"]
自此 elastic 启动完成!!!
2.3 集群部署
- 在本机单个项目启动多节点:
./elasticsearch -E path.data=data1 -E path.logs=log1 -E node.name=node1 -E cluster.name=msb_teach
./elasticsearch -E path.data=data2 -E path.logs=log2 -E node.name=node2 -E cluster.name=msb_teach
-
- 在本机多个项目启动多个单节点: 将安装包复制多分, 修改配置文件后,启动.
3. Kibana
下载地址: www.elastic.co/cn/download…
注意:下载和 elastic search 相同版本的 kibana. 下载文件后解压,直接启动
cd /opt/kibana-7.10.0-linux-x86_64/bin
./kibana
报错:
同样不能使用 root 启动, 切换为普通用户并赋予相应的权限
chown -R es kibana-7.10.0-linux-x86_64
chgrp -R es kibana-7.10.0-linux-x86_64
su es
./kibana
启动成功, kibana 默认监听 5601 端口. 但是 kibana 也是默认绑定 127.0.0.1地址, 其他主机无法访问.
修改配置文件:/opt/kibana-7.10.0-linux-x86_64/config/kibana.yml
# 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"
再次启动发现OK
4. 设置密码
4.1 设置 elastic search 密码
启动elastic search 后设置密码
# -d elasticsearch 后台运行
./elasticsearch -d
./elasticsearch-setup-passwords interactive
此时报错
Unexpected response code [500] from calling GET http://172.22.197.222:9200/_security/_authenticate?pretty
It doesn't look like the X-Pack security feature is enabled on this Elasticsearch node.
Please check if you have enabled X-Pack security in your elasticsearch.yml configuration file.
ERROR: X-Pack Security is disabled by configuration.
需要设置X-Path, 修改配置文件: /opt/elasticsearch-7.10.0/config/elasticsearch.yml
vim /usr/local/elasticsearch/config/elasticsearch.yml
#----------------------------------- X-Pack ------------------------------------
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
重启 elastic, 并设置密码
至此elastic search 密码设置完成!!!
4.2 kibana 配置 elastic search 密码
修改 kibana 配置文件:/opt/kibana-7.10.0-linux-x86_64/config/kibana.yml
# If your Elasticsearch is protected with basic authentication, these settings provide
# the username and password that the Kibana server uses to perform maintenance on the Kibana
# index at startup. Your Kibana users still need to authenticate with Elasticsearch, which
# is proxied through the Kibana server.
elasticsearch.username: "elastic"
elasticsearch.password: "elastic123"
重启 kibana 后, 给 kibana 配置 es的密码完成
5. Elasticsearch Head插件安装
使用Elasticsearch Head可以方便的查看,管理,查询 Elasticsearch
Elasticsearch Head使用实例1: 查看集群健康状态:
- Green:所有Primary和Replica均为active,集群健康
- Yellow:至少一个Replica不可用,但是所有Primary均为active,数据仍然是可以保证完整性的。
- Red:至少有一个Primary为不可用状态,数据不完整,集群不可用。
5.1 服务形式安装
- 安装node
- 下载地址: nodejs.org/en/download…
- 检查是否安装成功 node -v
- 安装 grunt
- 命令行执行: npm install -g grunt-cli
- 输入:grunt -version命令检查是否安装成功
- 下载安装Head插件
- 下载地址:github.com/mobz/elasti…
- 下载完成后,解压,打开elasticsearch-head-master文件夹,修改Gruntfile.js文件,添加hostname:'*', 如图:
- 输入 cd elasticsearch-head && npm install
- 输入 npm run start 启动服务
- 验证:http://localhost:9100/ 安装成功
- 如果无法发现ES节点,尝试在ES配置文件中设置允许跨域
http.cors.enabled: true
http.cors.allow-origin: "*"
修改 Gruntfile.js如图:
5.2 从Chrome网上应用店安装Elasticsearch Head
插件地址: chrome.google.com/webstore/de…
下载安装完成后,点击插件,输入elasticsearch地址后即可使用