ElasticSearch学习(三)——Windows集群部署

本文涉及的产品
检索分析服务 Elasticsearch 版,2核4GB开发者规格 1个月
简介: ElasticSearch学习(三)——Windows集群部署

image.png

Windows集群部署

  1. 创建elasticsearch-cluster文件夹,在内部复制3个ElasticSearch服务(将之前的单点解压缩的那个es文件夹复制过来)
  2. 点开之后会看到有data,logs两个文件夹,因为之前使用过,所以里面是有数据和日志的,因为我们需要用一个全新的集群环境,所以把data文件夹删除,logs文件夹清空。

然后就是进行配置,集群和单点是不一样的,单点直接双击elasticsearch.bat文件启动即可,但是集群的话是需要配置的。

打开elasticsearch.yml文件

修改的部分:

# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
# 集群名称,必须要一致
cluster.name: my-application
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
# 节点名称,集群内要唯一
node.name: node-8001
node.master: true
node.data: true
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
# ---------------------------------- Network -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#
# ip地址
network.host: localhost
# http端口
http.port: 8001
# tcp监听端口
transport.tcp.port: 9301
#
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
# 跨域
http.cors.enabled: true
http.cors.allow-origin: "*"

修改完之后:

进入bin目录,启动node-8001,可以看到:

然后打开postman,查询集群健康状态:

响应:

{
    "cluster_name": "my-application",
    "status": "green", // 可以看到为健康状态为绿色
    "timed_out": false,
    "number_of_nodes": 1, // 当前的节点为1个
    "number_of_data_nodes": 1, // 当前的数据节点为1个 
    "active_primary_shards": 1,
    "active_shards": 1,
    "relocating_shards": 0,
    "initializing_shards": 0,
    "unassigned_shards": 0,
    "delayed_unassigned_shards": 0,
    "number_of_pending_tasks": 0,
    "number_of_in_flight_fetch": 0,
    "task_max_waiting_in_queue_millis": 0,
    "active_shards_percent_as_number": 100.0
}

如此复制一份,并命名node-8002,删除data目录,清空logs目录,修改elasticsearch.yml文件(添加到对应模块即可):

# ---------------------------------- Cluster -----------------------------------
# 集群名称,必须要一致
cluster.name: my-application
# ------------------------------------ Node ------------------------------------
# 节点名称,集群内要唯一
node.name: node-8002
node.master: true
node.data: true
# ---------------------------------- Network -----------------------------------
# ip地址
network.host: localhost
# http端口
http.port: 8002
# tcp监听端口
transport.tcp.port: 9302
# --------------------------------- Discovery ----------------------------------
# discovery es中的一个特殊的查找模块,用来查找节点的。
# 你第一台机器启动就不用写了,因为他启动就他一个,但是第二台就需要,因为他要去找第一台去
# 9301为内部通讯端口,是第一台机器的tcp监听端口
discovery.seed_hosts: ["localhost:9301"]
discovery.zen.fd.ping_timeout: 1m
discovery.zne.fd.ping_retries: 5
# 跨域
http.cors.enabled: true
http.cors.allow-origin: "*"

然后启动node-8002可以看到:

可以看到node-8001找到了node-8001服务。

使用postman,查询集群健康状态:

响应:

{
    "cluster_name": "my-application",
    "status": "green", // 健康状态为绿色
    "timed_out": false,
    "number_of_nodes": 2, // 当前集群中的节点为2个
    "number_of_data_nodes": 2, // 当前集群中的数据节点为2个
    "active_primary_shards": 1,
    "active_shards": 2,
    "relocating_shards": 0,
    "initializing_shards": 0,
    "unassigned_shards": 0,
    "delayed_unassigned_shards": 0,
    "number_of_pending_tasks": 0,
    "number_of_in_flight_fetch": 0,
    "task_max_waiting_in_queue_millis": 0,
    "active_shards_percent_as_number": 100.0
}

如此同node-8002修改一份node-8003,删除data目录,清空logs目录,修改elasticsearch.yml:

# ---------------------------------- Cluster -----------------------------------
# 集群名称,必须要一致
cluster.name: my-application
# ------------------------------------ Node ------------------------------------
# 节点名称,集群内要唯一
node.name: node-8003
node.master: true
node.data: true
# ---------------------------------- Network -----------------------------------
# ip地址
network.host: localhost
# http端口
http.port: 8003
# tcp监听端口
transport.tcp.port: 9303
# --------------------------------- Discovery ----------------------------------
# discovery es中的一个特殊的查找模块,用来查找节点的。
# 你第一台机器启动就不用写了,因为他启动就他一个,但是第二台就需要,因为他要去找第一台去
# 9301为内部通讯端口,是第一台机器的tcp监听端口
discovery.seed_hosts: ["localhost:9301","localhost:9302"]
discovery.zen.fd.ping_timeout: 1m
discovery.zne.fd.ping_retries: 5
# 跨域
http.cors.enabled: true
http.cors.allow-origin: "*"

然后启动node-8003服务,可以看到:

启动成功:

使用postman,查询集群健康状态:

响应:

{
    "cluster_name": "my-application",
    "status": "green", // 健康状态为绿色
    "timed_out": false,
    "number_of_nodes": 3,  // 当前集群中的节点为3个
    "number_of_data_nodes": 3, // 当前集群中的数据节点为2个
    "active_primary_shards": 1,
    "active_shards": 2,
    "relocating_shards": 0,
    "initializing_shards": 0,
    "unassigned_shards": 0,
    "delayed_unassigned_shards": 0,
    "number_of_pending_tasks": 2,
    "number_of_in_flight_fetch": 0,
    "task_max_waiting_in_queue_millis": 43810,
    "active_shards_percent_as_number": 100.0
}

注意:

这种方式要按照顺序启动,如果修改了配置文件,需要删除data目录,重启elasticsearch

配置文件参考:

# 集群名称,必须要一致
cluster.name: my-application
# 节点名称,集群内要唯一
node.name: node-8001
node.master: true
node.data: true
# ip地址
network.host: localhost
# http端口
http.port: 8001
# tcp监听端口
transport.tcp.port: 9301
# 查找节点(第一个节点的配置文件无需添加)
discovery.seed_hosts: ["localhost:9301"]
discovery.zen.fd.ping_timeout: 1m
discovery.zne.fd.ping_retries: 5
# 集群内的可以被选为主节点的节点列表 
#cluster.initial_master_nodes: ["node-1","node-2","node-3"]
# 跨域配置
#action.destructive_requires_name: true
http.cors.enabled: true
http.cors.allow-origin: "*"

注意:

很多问题都出现在第一次配置失败。假如你Es项目路径下有建立了data的目录,那就要在每次改配置的时候去清掉里面的东西,像是缓存垃圾,导致后面每次修改都不生效。

解决方法:

关闭es,删除data目录,重启es

相关实践学习
使用阿里云Elasticsearch体验信息检索加速
通过创建登录阿里云Elasticsearch集群,使用DataWorks将MySQL数据同步至Elasticsearch,体验多条件检索效果,简单展示数据同步和信息检索加速的过程和操作。
ElasticSearch 入门精讲
ElasticSearch是一个开源的、基于Lucene的、分布式、高扩展、高实时的搜索与数据分析引擎。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr(也是基于Lucene)。 ElasticSearch的实现原理主要分为以下几个步骤: 用户将数据提交到Elastic Search 数据库中 通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据 当用户搜索数据时候,再根据权重将结果排名、打分 将返回结果呈现给用户 Elasticsearch可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。
相关文章
|
8月前
|
存储 C语言 C++
[笔记]windows逆向学习
[笔记]windows逆向学习
|
19天前
|
Java Windows
windows下 安装 Elasticsearch报错warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME
windows下 安装 Elasticsearch报错warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME
69 0
|
19天前
|
存储 缓存 自然语言处理
Elasticsearch框架学习的难点和重点有哪些
Elasticsearch是基于Lucene的开源搜索引擎,广泛应用于全文检索和日志分析。学习重点包括理解节点、集群、索引、分片和副本等基本概念,掌握数据索引、查询DSL、聚合和性能优化。倒排索引和分词器是全文搜索的核心,集群管理和监控对于稳定性至关重要。实践中需根据数据量和查询模式优化分片策略,利用缓存提升搜索性能。学习Elasticsearch要结合实际项目,关注官方文档和社区资源。【5月更文挑战第6天】
|
19天前
|
人工智能 架构师 开发者
大模型时代,该如何更好的学习 Elasticsearch?
大模型时代,该如何更好的学习 Elasticsearch?
19 0
|
19天前
|
安全 Linux 数据安全/隐私保护
Windows 部署 Elasticsearch + kibana 8.0 指南
Windows 部署 Elasticsearch + kibana 8.0 指南
33 0
|
19天前
|
SQL 关系型数据库 MySQL
Trinitycore学习之windows上用cmake生成vs项目并尝试在windows上启动服务
Trinitycore学习之windows上用cmake生成vs项目并尝试在windows上启动服务
63 0
|
19天前
|
监控 安全 Java
ElasticSearch在Windows上的下载与安装
ElasticSearch在Windows上的下载与安装
|
8月前
|
IDE Unix 编译器
Windows下配置CMake(入门级教程,适合新人收藏学习)
Windows下配置CMake(入门级教程,适合新人收藏学习)
891 1
|
8月前
elasticsearch生产集群部署-3个节点集群部署
elasticsearch生产集群部署-3个节点集群部署
61 0
|
19天前
|
机器人 Linux 数据安全/隐私保护
Python办公自动化【Windows中定时任务、OS/linux 系统定时任务 、Python 钉钉发送消息、Python 钉钉发送图片】(九)-全面详解(学习总结---从入门到深化)
Python办公自动化【Windows中定时任务、OS/linux 系统定时任务 、Python 钉钉发送消息、Python 钉钉发送图片】(九)-全面详解(学习总结---从入门到深化)
81 0