京东6.18大促主会场领京享红包更优惠

 找回密码
 立即注册

QQ登录

只需一步,快速开始

使用ElasticSearch集群搭建步调

2024-11-4 02:15| 发布者: 76a9| 查看: 144| 评论: 0

摘要: 目录一、前言二、使用 RPM 安装 Elasticsearch导入 Elasticsearch GPG 密钥从 RPM 存储库安装三、设置根本安全性生成证书使用TLS加密节点间通讯四、为 Elasticsearch 加密 HTTP 客户端通讯五、设置集群编辑 elastics
目录

一、前言

Elasticsearch 是一个开源的分布式搜索和分析引擎,用于全文搜索、布局化搜索、分析和可视化大规模数据。

它被筹划成一个可扩展的实时搜索引擎,可以大概处理大规模数据,并提供快速的搜索和分析功能。

以下是一些 Elasticsearch 的特性和用途:

  • 全文搜索:Elasticsearch可以存储大量的数据,并提供基于全文搜索的查询功能,支持各种复杂的查询操纵。
  • 实时性:Elasticsearch可以大概实时索引数据,并且查询的响应时间非常快,实用于需要快速查询的场景。
  • 分布式架构:Elasticsearch 是一个分布式体系,数据被分散存储在多个节点上,可以水平扩展以处理大规模数据。
  • 多种数据范例支持:Elasticsearch 支持多种数据范例的索引和查询,包括文本、数字、日期等。
  • 强大的查询语言:Elasticsearch 提供了丰富而机动的查询语言,可以满意各种复杂的查询需求。
  • 实时数据分析:除了搜索功能,Elasticsearch 还提供了强大的数据分析功能,可以对数据举行聚合、统计和可视化分析。
  • 易于摆设和管理:Elasticsearch 提供了简朴易用的API和管理工具,可以方便地摆设、监控和管理集群。
  • 与其他工具集成:Elasticsearch 与很多工具和技能(如Logstash、Kibana、Beats等)集成,构建了强大的日志管理和数据分析办理方案。

总的来说,Elasticsearch是一个功能强大且机动的搜索和分析引擎,实用于各种场景,包括日志分析、实时监控、全文搜索等。

本例将在3台机器上搭建 Elasticsearch 集群:

[code]192.168.72.151 node-1 192.168.72.152 node-2 192.168.72.153 node-3[/code]

二、使用 RPM 安装 Elasticsearch

导入 Elasticsearch GPG 密钥

下载并安装公共署名密钥

[code]rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch[/code]

从 RPM 存储库安装

在 /etc/yum.repos.d/ 创建 elasticsearch.repo

[code][elasticsearch] name=Elasticsearch 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=0 autorefresh=1 type=rpm-md[/code]

实行 yum install 下令

[code]yum install --enablerepo=elasticsearch elasticsearch -y[/code]

默认生成的目录

  • 安装目录:/usr/share/elasticsearch
  • 设置文件目录:/etc/elasticsearch

启动 Elasticsearch 下令:

[code]systemctl enable elasticsearch.service systemctl start elasticsearch.service[/code]

三、设置根本安全性

首次启动 Elasticsearch 时,会为用户生成暗码,并自动为用户设置 TLS ,可以随时调解 TLS 设置,更新节点证书

生成证书

1、在恣意节点上进入 Elasticsearch 的安装目录,使用 elasticsearch-certutil 为集群生成 CA 。

[code]bin/elasticsearch-certutil ca[/code]
  • 设置 CA 文件名(默认即可)
  • 为 CA 设置暗码

2、利用上一步的 elastic-stack-ca.p12 为集群生成证书和私钥。

[code]bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12[/code]
  • 输入CA的暗码
  • 为证书创建暗码,并设置文件名(默认即可)

3、将证书拷贝到其他节点上。

使用TLS加密节点间通讯

1、进入 Elasticsearch 设置目录,编辑 elasticsearch.conf 文件:

[code]cluster.name: my-cluster node.name: node-1 xpack.security.enabled: true xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.client_authentication: required xpack.security.transport.ssl.keystore.path: elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: elastic-certificates.p12[/code]

2、实行以下下令将证书暗码保存到 Elasticsearch 的 keystore

[code]bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password[/code]

3、为集群中的每个节点完成前面的步调。

4、在集群的每个节点上,重新启动 Elasticsearch 。

四、为 Elasticsearch 加密 HTTP 客户端通讯

1、 在恣意单个节点上,从安装 Elasticsearch 的目录中,运行Elasticsearch HTTP 证书工具生成证书署名哀求(CSR)。

[code]bin/elasticsearch-certutil http[/code]
  • 是否生成 CSR ,输入 n 。
  • 是否使用现有 CA ,输入 y 。
  • 输入 CA 的路径。这是 elastic-stack-ca.p12 的绝对路径。
  • 输入 CA 的暗码。
  • 输入证书的有用期。
  • 是否为每个节点生成一个证书,输入 y 。
  • 输入每个节点的名称(node.name)。
  • 输入所有节点的主机名、IP地址。
  • 输入私钥暗码。

该下令生成一个 .zip 文件,其中包含 Elasticsearch 和 Kibana 使用的证书和密钥。每个文件夹都包含一个 README.txt ,说明如何使用这些文件。

2、解压缩生成的 elasticsearch-ssl-http.zip 文件。这个压缩文件包含用于Elasticsearch和Kibana的目录。

[code]/elasticsearch |_ README.txt |_ http.p12 |_ sample-elasticsearch.yml[/code] [code]/kibana |_ README.txt |_ elasticsearch-ca.pem |_ sample-kibana.yml[/code]

3、在集群中的每个节点上,完成以下步调:

复制上面 elasticsearch 文件夹中的 http.p12 到 Elasticsearch 的设置目录下。

编辑 elasticsearch.yml ,启用 HTTPS 安全性,并指定 http.12 文件的位置。

[code]xpack.security.http.ssl.enabled: true xpack.security.http.ssl.keystore.path: http.p12[/code]

将私钥暗码添加到 Elasticsearch 的安全设置中。

[code]bin/elasticsearch-keystore add xpack.security.http.ssl.keystore.secure_password[/code]

4、重新启动 Elasticsearch

五、设置集群

编辑 elasticsearch.yml

3个节点的设置文件除了ip、节点名之外,都一样

[code]cluster.name: my-clusters node.name: node-1 path.data: /var/lib/elasticsearch path.logs: /var/log/elasticsearch indices.memory.index_buffer_size: 20% indices.memory.min_index_buffer_size: 96mb thread_pool: search: size: 32 analyze: size: 30 queue_size: 1000 indices.requests.cache.size: 2% indices.queries.cache.size: 10% indices.fielddata.cache.size: 20% indices.breaker.fielddata.limit: 40% network.host: 0.0.0.0 http.port: 9200 transport.port: 9300 transport.compress: true http.max_content_length: 100mb discovery.seed_hosts: ["192.168.72.151", "192.168.72.152","192.168.72.153"] cluster.initial_master_nodes: ["node-1", "node-2","node-3"] cluster.fault_detection.leader_check.interval: 5s discovery.cluster_formation_warning_timeout: 10s cluster.publish.timeout: 30s cluster.routing.allocation.node_initial_primaries_recoveries: 16 cluster.routing.allocation.node_concurrent_recoveries: 8 indices.recovery.max_bytes_per_sec: 125mb[/code]

集群默认是通过9300端口连接的,记得防火墙还要开通9300

启动集群

依次启动各个节点

[code]service elasticsearch start[/code]

设置暗码

[code]bin/elasticsearch-setup-passwords interactive[/code]

查抄集群状态

[code]curl -XGET --user elastic:password http://192.168.72.151:9200/_cluster/health?pretty[/code]

也可以在欣赏器直接访问

请留意,上述步调中的IP地址、端口和目录路径应根据你的实际情况举行调解。

总结

以上为个人履历,盼望能给各人一个参考,也盼望各人多多支持脚本之家。


来源:https://www.jb51.net/server/328783kz2.htm
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
关闭

站长推荐上一条 /6 下一条

QQ|手机版|小黑屋|梦想之都-俊月星空 ( 粤ICP备18056059号 )|网站地图

GMT+8, 2025-7-1 18:38 , Processed in 0.031140 second(s), 18 queries .

Powered by Mxzdjyxk! X3.5

© 2001-2025 Discuz! Team.

返回顶部