Windos中部署 Elasticsearch(7.8.0)集群

  • 下载ES
    Elasticsearch 7.8.0下载地址
  • 创建D:\Elasticsearch\elasticsearch-7.0.8-cluster目录
  • 将下载的ES压缩包解压到该目录下
    在这里插入图片描述
  • 将解压后的elasticsearch-7.8.0-windows-x86_64文件夹名称修改为node-1001

在这里插入图片描述

  • node-1001分别复制成两份,并命名为node-1002,node-1003
    在这里插入图片描述

  • 分别修改node-1001,node-1002,node-1003目录下的\elasticsearch-7.8.0\config\elasticsearch.yml文件
    - **
    node-1001的elasticsearch.yml文件

#节点 1 的配置信息:
#集群名称,节点之间要保持一致
cluster.name: my-elasticsearch
#节点名称,集群内要唯一
node.name: node-1001
node.master: true
node.data: true
#ip 地址
network.host: localhost
#http 端口
http.port: 1001
#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: "*"

node-1002的elasticsearch.yml文件

#节点 2 的配置信息:
#集群名称,节点之间要保持一致
cluster.name: my-elasticsearch
#节点名称,集群内要唯一
node.name: node-1002
node.master: true
node.data: true
#ip 地址
network.host: localhost
#http 端口
http.port: 1002
#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: "*"

node-1003的elasticsearch.yml文件

#节点 3 的配置信息:
#集群名称,节点之间要保持一致
cluster.name: my-elasticsearch
#节点名称,集群内要唯一
node.name: node-1003
node.master: true
node.data: true
#ip 地址
network.host: localhost
#http 端口
http.port: 1003
#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: "*"

  • 启动集群
    分别依次双击执行node-1001,node-1002,node-1003节点的elasticsearch-7.8.0\bin\elasticsearch.bat, 启动节点服务器(可以编写一个脚本启动),启动后,会自动加入指定名称的集群。
  • 测试集群
请求类型: GET
请求地址:http://127.0.0.1:1001/_cluster/health

返回结果:

{
    "cluster_name": "my-elasticsearch",
    "status": "green",
    "timed_out": false,
    "number_of_nodes": 3,//当前节点数
    "number_of_data_nodes": 3,
    "active_primary_shards": 0,
    "active_shards": 0,
    "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
}

status字段指示着当前集群在总体上是否工作正常。
它的三种颜色含义如下:

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

  • 测试集群存储数据
    1.在节点一上存储数据
请求类型: PUT
请求地址:http://127.0.0.1:1001/user

2.在节点二获取刚才存储的数据

请求类型: GET 
请求地址:http://127.0.0.1:1002/user

返回结果:

{
    "user": {
        "aliases": {},
        "mappings": {},
        "settings": {
            "index": {
                "creation_date": "1656315804754",
                "number_of_shards": "1",
                "number_of_replicas": "1",
                "uuid": "N4RDkbwdQiq-zoolXtYRyQ",
                "version": {
                    "created": "7080099"
                },
                "provided_name": "user"
            }
        }
    }
}

3.在节点三获取刚才存储的数据

请求类型: GET 
请求地址:http://127.0.0.1:1003/user

返回结果:

{
    "user": {
        "aliases": {},
        "mappings": {},
        "settings": {
            "index": {
                "creation_date": "1656315804754",
                "number_of_shards": "1",
                "number_of_replicas": "1",
                "uuid": "N4RDkbwdQiq-zoolXtYRyQ",
                "version": {
                    "created": "7080099"
                },
                "provided_name": "user"
            }
        }
    }
}

同样,反过来在1003,1002上创建数据,1001也能获取。

  • 至此搭建成功
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

亿只王菜菜

各位爷,赏口饭吃吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值