环境:
jdk11
Elasticsearch-7.16.3
window10
window 实现Elasticsearch伪集群
一、部署
创建 Elasticsearch ,复制三份,分别命名node-1、node-2、node-3
node-1 节点
新建Elasticsearch 集群 node-1 节点
修改 node-1/config/elasticsearch.yml
cluster.name: es-cluster # 集群名称,节点之间保持一致
node.name: node-1 # 节点名称,每个节点不能相同node.master: true # 是否可以成为master节点,master节点用于控制整个集群的操作。比如创建或删除索引,管理其它非master节点等
node.data: true # 是否可以成为data节点,data节点主要用于执行数据相关的操作。比如文档的CRUDnetwork.host: localhost # IP
http.port: 9200 # port http端口号
#tcp监听端口
transport.tcp.port: 5200#候选主节点的地址,在开启服务后可以被选为主节点
discovery.zen.ping.unicast.hosts: ["localhost:5200","localhost:5201","localhost:5202"] # 集群ip列表,注意:为tcp 端口号
discovery.zen.minimum_master_nodes: 2 # 可以成为master节点的数量, 配置规则 n/2+1# 设置cors
http.cors.enabled: true
http.cors.allow-origin: "*"
检查集群健康,打开 http://localhost:9200/_cluster/health
{
"cluster_name": "es-cluster", //集群名称
"status": "green", //green:所有分片、复制分片都可用,yellow:主分片可用,复制分片不全可用,red:不是所有主分片可用
"timed_out": false,
"number_of_nodes": 1, //节点数量
"number_of_data_nodes": 1, //数据节点数量
"active_primary_shards": 2,
"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-2 节点
这里http.port 端口号不一致是因为是在同一台电脑配置集群缘故,不同服务器部署,port端口号默认系统即可
修改 node-2/config/elasticsearch.yml
cluster.name: es-cluster # 集群名称
node.name: node-2 # 节点名称node.master: true # 是否可以成为master节点,master节点用于控制整个集群的操作。比如创建或删除索引,管理其它非master节点等
node.data: true # 是否可以成为data节点,data节点主要用于执行数据相关的操作。比如文档的CRUDnetwork.host: localhost # IP
http.port: 9201 # port http端口号
#tcp监听端口
transport.tcp.port: 5201#候选主节点的地址,在开启服务后可以被选为主节点
discovery.zen.ping.unicast.hosts: ["localhost:5200","localhost:5201","localhost:5202"] # 集群ip列表,注意:为tcp 端口号
discovery.zen.minimum_master_nodes: 2 # 可以成为master节点的数量, 配置规则 n/2+1# 设置cors
http.cors.enabled: true
http.cors.allow-origin: "*"
查看集群状态:
http://localhost:9200/_cluster/health
http://localhost:9201/_cluster/health
可以看到集群已经存在两个节点了
node-3 节点
这里http.port 端口号不一致是因为是在同一台电脑配置集群缘故,不同服务器部署,port端口号默认系统即可
修改 node-3/config/elasticsearch.yml
cluster.name: es-cluster # 集群名称
node.name: node-3 # 节点名称node.master: true # 是否可以成为master节点,master节点用于控制整个集群的操作。比如创建或删除索引,管理其它非master节点等
node.data: true # 是否可以成为data节点,data节点主要用于执行数据相关的操作。比如文档的CRUDnetwork.host: localhost # IP
http.port: 9202 # port http端口号
#tcp监听端口
transport.tcp.port: 5202#候选主节点的地址,在开启服务后可以被选为主节点
discovery.zen.ping.unicast.hosts: ["localhost:5200","localhost:5201","localhost:5202"] # 集群ip列表,注意:为tcp 端口号
discovery.zen.minimum_master_nodes: 2 # 可以成为master节点的数量, 配置规则 n/2+1# 设置cors
http.cors.enabled: true
http.cors.allow-origin: "*"
查看集群健康状态
http://localhost:9200/_cluster/health
http://localhost:9201/_cluster/health
http://localhost:9202/_cluster/health
可以看到节点数量已经为3个