在Linux环境下搭建ElasticSearch集群

前提准备

能在Linux中成功运行单机的ElasticSearch服务

搭建概要

本次试验实3台机器上分别部署一个ElasticSearch服务做成集群

elasticsearch.yml配置

############ES1###############
cluster.name: my-application
node.name: node-1
network.host: 192.168.176.128
http.port: 9200
#集群个节点IP地址,也可以使用els、els.shuaiguoxia.com等名称,需要各节点能够解析
discovery.zen.ping.unicast.hosts: ["192.168.176.128","192.168.176.129","192.168.176.131"]
#为了避免脑裂,集群节点数最少为 半数+1
discovery.zen.minimum_master_nodes: 2

############ES2###############
cluster.name: my-application
node.name: node-2
network.host: 192.168.176.129
http.port: 9200
discovery.zen.ping.unicast.hosts: ["192.168.176.128","192.168.176.129","192.168.176.131"]
discovery.zen.minimum_master_nodes: 2

############ES3###############
cluster.name: my-application
node.name: node-3
network.host: 192.168.176.131
http.port: 9200
discovery.zen.ping.unicast.hosts: ["192.168.176.128","192.168.176.129","192.168.176.131"]
discovery.zen.minimum_master_nodes: 2

全部启动成功后,访问
http://192.168.176.128:9200/_cat/nodes?pretty
返回结果(*号表示为当前节点为主节点的意思):
192.168.176.128 29 92 17 0.17 0.16 0.14 mdi - node-2
192.168.176.129 11 93 7 0.74 0.55 0.41 mdi * node-1
192.168.176.131 11 93 4 0.52 0.34 0.29 mdi - node-3

通过API(http://192.168.176.128:9200/_cluster/health?pretty)可以查看集群的状态,通常集群的状态分为三种:
• Red,表示有主分片没有分配,某些数据不可用。
• Yellow,表示主分片都已分配,数据都可用,但是有复制分片没有分配。
• Green,表示主分片和复制分片都已分配,一切正常。

{
"cluster_name" : "my-application",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 3,
"number_of_data_nodes" : 3,
"active_primary_shards" : 5,
"active_shards" : 10,
"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
}

集群搭建过程

你可能感兴趣的:(在Linux环境下搭建ElasticSearch集群)