一、Windows部署集群

注意: elasticSearch8和7版本的配置方法不同,此处只演示7版本
ElasticSearch7.8.0版本下载地址

1. 配置部署

1.1 步骤

  1. 解压之后可以在,config文件夹下面找到elasticsearch.yml配置文件,将文件内容修改为下列配置。
  2. 负责完整的elasticsearch文件夹,重命名为node1002,按照上面的步骤,修改elasticsearch.yaml文件。
  3. 删除文件夹中data文件夹,然后双击bin目录下elasticsearch.bat文件运行即可

1.2 文件路径截图

3. 部署集群 - 图1
3. 部署集群 - 图2

1.3节点配置文件

  1. node1001配置
  1. #节点 1 的配置信息:
  2. #集群名称,节点之间要保持一致
  3. cluster.name: my-elasticsearch
  4. #节点名称,集群内要唯一
  5. node.name: node-1001
  6. node.master: true
  7. node.data: true
  8. #ip 地址
  9. network.host: localhost
  10. #http 端口
  11. http.port: 1001
  12. #tcp 监听端口
  13. transport.tcp.port: 9301
  14. #discovery.seed_hosts: ["localhost:9301", "localhost:9302","localhost:9303"]
  15. #discovery.zen.fd.ping_timeout: 1m
  16. #discovery.zen.fd.ping_retries: 5
  17. #集群内的可以被选为主节点的节点列表
  18. #cluster.initial_master_nodes: ["node-1", "node-2","node-3"]
  19. #跨域配置
  20. #action.destructive_requires_name: true
  21. http.cors.enabled: true
  22. http.cors.allow-origin: "*"
  1. node1002配置
  1. #节点 2 的配置信息:
  2. #集群名称,节点之间要保持一致
  3. cluster.name: my-elasticsearch
  4. #节点名称,集群内要唯一
  5. node.name: node-1002
  6. node.master: true
  7. node.data: true
  8. #ip 地址
  9. network.host: localhost
  10. #http 端口
  11. http.port: 1002
  12. #tcp 监听端口
  13. transport.tcp.port: 9302
  14. discovery.seed_hosts: ["localhost:9301"]
  15. discovery.zen.fd.ping_timeout: 1m
  16. discovery.zen.fd.ping_retries: 5
  17. #集群内的可以被选为主节点的节点列表
  18. #cluster.initial_master_nodes: ["node-1", "node-2","node-3"]
  19. #跨域配置
  20. #action.destructive_requires_name: true
  21. http.cors.enabled: true
  22. http.cors.allow-origin: "*"
  1. node1003配置
  1. #节点 3 的配置信息:
  2. #集群名称,节点之间要保持一致
  3. cluster.name: my-elasticsearch
  4. #节点名称,集群内要唯一
  5. node.name: node-1003
  6. node.master: true
  7. node.data: true
  8. #ip 地址
  9. network.host: localhost
  10. #http 端口
  11. http.port: 1003
  12. #tcp 监听端口
  13. transport.tcp.port: 9303
  14. #候选主节点的地址,在开启服务后可以被选为主节点
  15. discovery.seed_hosts: ["localhost:9301", "localhost:9302"]
  16. discovery.zen.fd.ping_timeout: 1m
  17. discovery.zen.fd.ping_retries: 5
  18. #集群内的可以被选为主节点的节点列表
  19. #cluster.initial_master_nodes: ["node-1", "node-2","node-3"]
  20. #跨域配置
  21. #action.destructive_requires_name: true
  22. http.cors.enabled: true
  23. http.cors.allow-origin: "*"

1.5 查看部署情况

分别访问不同端口的elasticsearch健康查询情况

  1. http://127.0.0.1:1001/_cluster/health
  2. http://127.0.0.1:1002/_cluster/health
  3. http://127.0.0.1:1003/_cluster/health

3. 部署集群 - 图3
green:所有的主分片和副本分片都正常运行。
yellow:所有的主分片都正常运行,但不是所有的副本分片都正常运行。
red:有主分片没能正常运行。

1.6 集群部署测试

向node1001端口创建test索引

  1. put请求 http://127.0.0.1:1001/test
  2. get请求 http://127.0.0.1:1002/test
    3. 部署集群 - 图4
    3. 部署集群 - 图5啊啊