Elasticsearch cluster and head plugin

Download and install

Elasticsearch download

The installation of Elasticsearch is relatively simple, just download it and unzip it directly to the specified directory. The key lies in the configuration, here we are downloading the 7.1.1 version of Elasticsearch.

table of Contents

es directory

elasticsearch.yml configuration file

configuration

The most important thing in elasticsearch configuration is the first few items:

  1. cluster.name: indicates the name of the cluster, the default is elasticsearch, it is best to set it, because the client connection will use it
  2. node.name: indicates the name of the node, to facilitate the distinction between different nodes
  3. node.master: true means that this node is qualified as a master node
  4. node.data: true means this node can store data
  5. path.data: data directory
  6. path.logs: log directory

Different scenarios can use different combinations:

node.master node.data Description
true true Means to coordinate client requests and store data
false true Indicates that only data is stored, mainly to add, delete, modify, and check documents, and aggregate operations, etc.
true false Only coordinate client requests, do not store data, create or delete indexes, track which nodes are part of the cluster, and decide which shards are allocated to related nodes
false false Only process client requests, nodes can only process routing requests, process searches, distribute index operations, etc.
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html

cluster.name: my-es
node.name: node-1
node.master: true
node.data: true

# 数据存放目录,多个目录使用逗号分割
path.data: F:\component\esdata\data1

# 绑定HTTP端口
http.port: 9200

# 日志目录
path.logs: F:\component\esdata\logs1

# 绑定地址,以便于外网访问
#network.host: 0.0.0.0

#表示开启跨域访问支持,默认为false
http.cors.enabled: true

#表示跨域访问允许的域名地址,,可支持正则表达式,这里“*”表示允许所有域名访问
http.cors.allow-origin: "*"

#允许跨域访问头部信息
#http.cors.allow-headers: "X-Requested-With,Content-Type, Content-Length, Authorization" 

# 配置host以便于节点启动的时候更快发现其他节点,默认["127.0.0.1", "[::1]"]
#discovery.seed_hosts: ["host1", "host2"]

# Bootstrap the cluster using an initial set of master-eligible nodes:
#cluster.initial_master_nodes: ["node-1", "node-2","node-3"]

#设置true用来锁住物理内存
#bootstrap.memory_lock: true

#索引字段缓存大小
#indices.fielddata.cache.size: 50mb 

#设置集群中master节点初始列表,可通过这些
#discovery.zen.ping.unicast.hosts: ["192.168.37.134:9300","192.168.37.135:9300","192.168.37.136:9300"] 

#配置当前集群最少的master节点数,默认为1
#discovery.zen.minimum_master_nodes: 1

jvm.options configuration

The jvm configuration is mainly to configure the JVM parameters required to start Elasticsearch. Generally, there is no need to configure it. The most commonly used configuration -Xms and -Xmx are the initial and maximum memory values ​​used by Elasticsearch. The local test can be adjusted smaller, and the online test can be adjusted larger.

-Xms512M
-Xmx512M
-XX:+UseConcMarkSweepGC
-XX:CMSInitiatingOccupancyFraction=75
-XX:+UseCMSInitiatingOccupancyOnly
-XX:+DisableExplicitGC
-XX:+AlwaysPreTouch
-server
-Xss1m
-Djava.awt.headless=true
-Dfile.encoding=UTF-8
-Djna.nosys=true
-Djdk.io.permissionsUseCanonicalPath=true
-Dio.netty.noUnsafe=true
-Dio.netty.noKeySetOptimization=true
-Dio.netty.recycler.maxCapacityPerThread=0
-Dlog4j.shutdownHookEnabled=false
-Dlog4j2.disable.jmx=true
-Dlog4j.skipJansi=true
-XX:+HeapDumpOnOutOfMemoryError

After the configuration is complete, you can access it in the browser:
http://localhost:9200/

Cluster approach

A cluster is a set of nodes with the same cluster.name. They work together, share data and provide failover and expansion functions. Of course, one node can also form a cluster.

To start an Elasticsearch cluster, you only need to copy a few more Elasticsearch, and you can modify the basic configuration, mainly to modify the node name, log directory, and data directory.
Note that in the cluster mode, only one node needs to be configured with http.port: 9200, otherwise it will prompt that the port has been bound and cannot get up. Generally, the master node can be configured.

9200

elasticsearch-head tool

Elasticsearch provides an HTTP interaction method. We can directly send http requests through curl, postman and other tools to obtain related information, but in many cases it is troublesome. We can view related information through elasticsearch-head.
To download es-head , you can use git, or download the zip directly and unzip it.

es-head

Elasticsearch-head requires node.js to run. You need to install node.js first. By the way, npm is also installed. Enter the root directory of elasticsearch-head and execute the following command:

npm install
npm run start

Then you can visit:
http://localhost:9100/

The port can be modified in the Gruntfile.js file:

connect: {
    server: {
        options: {
            port: 9100,
            base: '.',
            keepalive: true
        }
    }
}

Note that because the port used by elasticsearch-head is 9100, and Elasticsearch uses 9200, there is a crossover problem when accessing JavaScript code, so when using elasticsearch-head, you must configure the following 2 items in the elasticsearch.yml configuration file of Elasticsearch.

http.cors.enabled: true
http.cors.allow-origin: "*"

We use elasticsearch-head to create 2 indexes, the shard is 3, and the replica is 1.

9100

As shown in the figure above, we can see that each of the 6 shards is evenly distributed on 3 nodes. The primary and replica shards are not on the same node, so that even if one node fails, the availability is guaranteed.

Guess you like

Origin blog.csdn.net/trayvontang/article/details/107998680