Outline
ES cluster P2 is a type of distributed system, in addition to the cluster state management, all other requests can be sent to the Renyiyitai cluster node that can find their own need to be forwarded to which nodes, and these nodes communicate directly with . So, from the network infrastructure and service configuration, the need to build a cluster configuration and simple. Before Elasticsearch2.0, without hindering the network, all the nodes of the same configuration cluster.name are automatically belong to a cluster. After version 2.0, based on safety considerations to avoid the development of environmental problems caused by too casual, from version 2.0, the default auto-discovery mode to a unicast (unicast) mode. Provides several configuration in the node address, ES see it as gossip router role, in order to complete the discovery of the cluster. Since this is just a small feature in the ES, so the role of gossip router does not need to be configured separately, each node can serve ES. Therefore, the use of cluster unicast mode, each node configured with the same list as a router to a few nodes.
There is no limit in the number of cluster nodes, generally greater than or equal to two nodes of the cluster can be seen. Usually in performance and availability aspects to consider the number of nodes in the cluster are typically three or more and 3.
A cluster of related concepts
1. Cluster cluster
A cluster is composed of one or more nodes together organizations, which together have the whole data, and provides indexing and searching functions together. A cluster has a unique identity name, the default name is "elasticsearch". The name is important, because only one node by specifying a cluster name to join the cluster.
2. Node node
A node is a server in the cluster as part of a cluster, it stores data, indexing and search capabilities to participate in the cluster. And clusters similar to a node is identified by one name, and by default, the name is the name of a random Marvel characters, the name will be given to the node at startup. The name for the management is very important, because in this management process, you will go to confirm the network server which correspond to which nodes in the cluster elasticsearch;
A node can join a cluster specified by the cluster name of fashion. By default, each node will be added to the schedule called "elasticsearch" cluster, which means that if you start a number of nodes in the network, and assuming they can find each other, they will automatically form and add to the one called "elasticsearch" cluster;
In a cluster, as long as you want, you can have any number of nodes. And, if your network does not currently run any elasticsearch node, which is a start node are created by default and add one called "elasticsearch" clusters.
3. Copy and fragmentation shards & replicas
Cluster structures
1. Prepare three elasticsearch server
2. Modify each server configuration
node1 node:
# Cluster name, the only guarantee
cluster.name: my-elasticsearch
# Node name, must not the same
node.name: node-1
# Ip address of this machine must
network.host: 127.0.0.1
# Server port number, must not be the same as in the machine
http.port: 9200
# Cluster communication between the port number, and the same machine must not be the same
transport.tcp.port: 9300
# Setting up a cluster automatically discovers the set of machine ip
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300","127.0.0.1:9301","127.0.0.1:9302"]
http.cors.enabled: true
http.cors.allow-origin: "*"
node2 Node:
# Cluster name, the only guarantee
cluster.name: my-elasticsearch
# Node name, must not the same
node.name: node-2
# Ip address of this machine must
network.host: 127.0.0.1
# Server port number, must not be the same as in the machine
http.port: 9201
# Cluster communication between the port number must be the same machine is not the same
transport.tcp.port: 9301
# ip setting up a cluster automatically discovers machine collection
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300","127.0.0.1:9301","127.0.0.1:9302"]
http.cors.enabled: true
http.cors.allow-origin: "*"
node3 node:
# Cluster name, the only guarantee
cluster.name: My - elasticsearch
# node name, must not the same
node.name: Node - . 3 IP address of the machine #
network.host: 127.0.0.1
# Server port number
http.port: 9202
Inter-cluster communication port number #
transport.tcp.port: 9302 # ip setting up a cluster automatically discovers collection of machines
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300","127.0.0.1:9301","127.0.0.1:9302"]
http.cors.enabled: true
http.cors.allow-origin: "*"
Note: If you are copying a previously used elasticsearch, you need to delete the folder [data] are the three clusters, or there will be an exception;
3. Start the server elasticsearch.bat were three clusters
Use the following address to view the status of the cluster
http://127.0.0.1:9200/_cat/nodes?v
4. Start Service elasticsearch-head-master
5. Add indexing and mapping
url 5.1 request (request method PUT)
http://localhost:9200/wn_1
5.2 Request body
{
"mappings": {
"article": {
"properties": {
"id": {
"type": "long",
"store": true,
"index":"not_analyzed"
},
"title": {
"type": "text",
"store": true,
"index":"analyzed",
"analyzer":"ik_max_word"
},
"content": {
"type": "text",
"store": true,
"index":"analyzed",
"analyzer":"ik_max_word"
}
}
}
}
}
5.3 效果实现
6.添加文档
6.1 请求的url(请求方式post)
http://localhost:9200/wn_1/article/1
6.2 请求体
{
"id":1,
"title":"ElasticSearch是一个基于Lucene的搜索服务器",
"content":"它提供了一个分布式多用户能力的全文搜索引擎,基于RESTfulweb接口。Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布,是当前流行的企业级搜索引擎。设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。"
}
6.3 效果实现