ElasticSearch集群(Windows)

ElasticSearch集群(Windows)

把elasticsearch文件夹改名为node-9201,删除data文件夹,清空log日志,拷贝成三份,分别叫node-9201,node-9202,node-9203。
在这里插入图片描述

1. 修改配置文件

  1. node-9201/config/elasticsearch.yml
#节点 9201 的配置信息:
#集群名称,节点之间要保持一致
cluster.name: my-elasticsearch
#节点名称,集群内要唯一
node.name: node-9201
node.master: true
node.data: true
#ip 地址
network.host: localhost
#http 端口
http.port: 9201
#tcp 监听端口
transport.tcp.port: 9301
#discovery.seed_hosts: ["localhost:9301", "localhost:9302","localhost:9303"]
#discovery.zen.fd.ping_timeout: 1m
#discovery.zen.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: "*"
  1. node-9202/config/elasticsearch.yml
#节点 9202 的配置信息:
#集群名称,节点之间要保持一致
cluster.name: my-elasticsearch
#节点名称,集群内要唯一
node.name: node-9202
node.master: true
node.data: true
#ip 地址
network.host: localhost
#http 端口
http.port: 9202
#tcp 监听端口
transport.tcp.port: 9302
discovery.seed_hosts: ["localhost:9301"]
discovery.zen.fd.ping_timeout: 1m
discovery.zen.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: "*"
  1. node-9203/config/elasticsearch.yml
#节点 9203 的配置信息:
#集群名称,节点之间要保持一致
cluster.name: my-elasticsearch
#节点名称,集群内要唯一
node.name: node-9203
node.master: true
node.data: true
#ip 地址
network.host: localhost
#http 端口
http.port: 9203
#tcp 监听端口
transport.tcp.port: 9303
#候选主节点的地址,在开启服务后可以被选为主节点
discovery.seed_hosts: ["localhost:9301", "localhost:9302"]
discovery.zen.fd.ping_timeout: 1m
discovery.zen.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: "*"

2. 启动ES集群

分别执行:
node-9201/bin/elasticsearch.bat
node-9202/bin/elasticsearch.bat
node-9203/bin/elasticsearch.bat

3. 使用cerebro查看集群

在这里插入图片描述
双击bin/cerebro.bat,然后访问地址:http://localhost:9000/,可以看到如下:
在这里插入图片描述
代表集群启动成功。

4. 使用postman查看集群

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
status字段表示当前集群在总体上是否工作正常。3个值分别如下:

  • green:所有主分片和副本分片都正常运行
  • yellow:所有主分片都正常运行,但不是所有的副本分片都正常运行
  • red:有主分片没能正常运行

5. 测试集群添加和查询索引

5.1 在9201节点添加product索引

请求方式:PUT请求
请求地址:http://localhost:9201/product
在这里插入图片描述

5.2 在9203查看product索引

请求方式:GET
请求地址:http://localhost:9203/product
在这里插入图片描述

### 如何在 Windows 系统上部署 Elasticsearch 集群 #### 准备工作 为了成功设置Elasticsearch集群,需确保已下载并解压了Elasticsearch软件包。创建一个专门用于存储多个节点实例的目录`elasticsearch-cluster`,在此目录内复制三份相同的Elasticsearch安装文件夹[^3]。 #### 修改配置文件 `elasticsearch.yml` 对于每一个节点实例中的`elasticsearch.yml`文件,编辑以定义唯一的节点名以及共同的集群名字。例如: ```yaml cluster.name: "my-windows-cluster" node.name: "node-1" ``` 此操作应针对每个节点重复执行,仅更改`node.name`属性来区分不同成员。这一步骤至关重要,因为具有相同`cluster.name`设定值的所有节点将会尝试互相连接形成集群[^1]。 #### 调整系统参数 由于默认的操作系统虚拟内存设置可能不足以支持Elasticsearch运行,建议调整Windows系统的VM(虚拟内存)配置。具体来说,通过命令提示符或PowerShell以管理员身份运行以下指令修改注册表项或将该数值设为至少262144: ```powershell Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' -Name 'PagingFiles' -Value 'C:\pagefile.sys 8192 262144' ``` 注意上述路径和大小可以根据实际需求调整[^2]。 #### 启动各节点服务 进入各个节点对应的`bin`子目录下,利用批处理文件(`elasticsearch.bat`)逐个启动这些进程。如果希望简化这一过程,则可考虑编写批量脚本来自动化完成这项任务。当所有预期参与者的端口监听正常开启后,它们应该能够自动识别彼此并组成集群[^4]: ```batch start "" "%CD%\bin\elasticsearch.bat" ``` 以上命令可以在命令行界面中连续输入多次,每次指向不同的节点位置;或者将多条这样的语句放入同一个`.bat`文件里实现一键式启动。 #### 测试集群健康状况 最后借助像Postman这类工具向任意活动节点发送HTTP请求查询整个集群的状态信息。通常情况下访问地址形如`http://localhost:9200/_cat/health?v=true&pretty`,返回的结果应当显示出健康的绿色标志表明一切运转良好。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值