Elasticsearch 集群
windows版伪集群部署
下载
下载地址:www.elastic.co/cn/download…
解压
解压并且复制成3份,分别代表3个节点
修改配置
修改每个节点的配置文件elasticsearch.yml,增加如下配置:
节点1:
#节点1的配置信息:
#集群名称,节点之间要保持一致
cluster.name: es-cluster
#节点名称,集群内要唯一
node.name: node-1001
node.master: true
node.data: true
#ip地址
network.host: localhost
#http端口
http.port: 1001
#tcp监听端口
transport.tcp.port: 9301
http.cors.enabled: true
http.cors.allow-origin: "*"
节点2:
#节点 2 的配置信息:
#集群名称,节点之间要保持一致
cluster.name: es-cluster
#节点名称,集群内要唯一
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: "*"
节点3:
#节点 2 的配置信息:
#集群名称,节点之间要保持一致
cluster.name: es-cluster
#节点名称,集群内要唯一
node.name: node-1003
node.master: true
node.data: true
#ip 地址
network.host: localhost
#http 端口
http.port: 1002
#tcp 监听端口
transport.tcp.port: 9303
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: "*"
启动集群
依次启动每个节点
测试集群
- GET http://127.0.0.1:1001/_cluster/health
- GET http://127.0.0.1:1002/_cluster/health
- GET http://127.0.0.1:1003/_cluster/health
响应结果皆为如下:
{
"cluster_name": "es-cluster",
"status": "green",
"timed_out": false,
"number_of_nodes": 3,
"number_of_data_nodes": 3,
"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
}
status字段指示着当前集群在总体上是否正常工作,它的三种颜色含义如下:
- green:所有的主分片和副本都正常运行
- yellow:所有的主分片都正常运行,但不是所有的副本都正常运行
- red:有主分片没能正常运行