ElasticSearch cluster -Windows

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

    An index can store a large amount of data exceeds a single node hardware limitations. For example, a document having an index 1000000000 1TB occupy disk space, and any node are not such a large disk space; or a single processing node search request, the response is too slow. To solve this problem, Elasticsearch provides the ability to index into multiple copies, these copies is called fragmentation. When you create an index, you can specify the number you want to slice. Each fragment is itself a fully functional and independent "Index", the "Index" may be placed on any node in the cluster. Fragmentation is very important, mainly for two reasons: 1) allows you to split horizon / expand your content capacity. 2) allows you distributed, parallel operation of slicing (potentially, a plurality of nodes) above, thereby improving the performance / throughput. As for how a fragmented distribution, how its documentation polymerization back to the search request, is managed entirely by Elasticsearch for you as a user, these are transparent.
    In a network / cloud environment, the failure can happen at any time, in a slice / node do not know how it is offline, or for any reason disappear, in this case, there is a failover mechanism is very useful and it is highly recommended. For this purpose, Elasticsearch allows you to create slices in one or more copies, replicate these copies is called fragmentation, or directly called replication. Copy is important for two main reasons: in the case of fragmentation / node failure, providing high availability. For this reason, noting that fragmentation never replicated on the same node is very important and original / main (original / primary) fragment placed. Expand your search volume / throughput, because the search can be run in parallel on all of the copy. In summary, each index may be divided into a plurality of slices. An index can also be copied 0 times (meaning no copy) or more times. Once copied, there is a master index of each slice (the original copy source fragmentation) and replication slice (primary slice copy) of difference. Fragmentation and number of copies can be specified when the index was created. After the index is created, you can dynamically change the number of copies at any time, but afterwards you can not change the number of slices.
    By default, Elasticsearch each index is fragmented five main fragmentation and a copy, which means that if you have at least two nodes of the cluster, you will have five main index fragmentation and five additional copy slicing (a full copy), so there are a total of 10 index each slice.

Cluster structures

  1. Prepare three elasticsearch server

    Creating elasticsearch-cluster folder, and copy services within three elasticsearch
      

  2. Modify each server configuration

    Modify confifig \ elasticsearch.yml profile

      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 效果实现

      

       

Guess you like

Origin www.cnblogs.com/wnwn/p/12368091.html