ElasticSearch 7.2 安装与集群配置

https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-install.html

安装及启动

shell> wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.2.0-darwin-x86_64.tar.gz
shell> tar zxvf elasticsearch-7.2.0-darwin-x86_64.tar.gz
shell> ln -s elasticsearch-7.2.0 elasticsearch
shell> cd elasticsearch/bin
shell> ./elasticsearch

配置集群

elasticsearch

elasticsearch1elasticsearch2elasticsearch3

# 复制多两个节点,注意elasticsearch-7.2.0/data,不要复制,或者复制后清空
shell> sudo cp -r elasticsearch-7.2.0 elasticsearch2
shell> sudo cp -r elasticsearch-7.2.0 elasticsearch3

统一的cluster.name

不同的node.name、path.data、path.logs

http.cors.enabled: true

http.cors.allow-origin: /.*/

设置可参选master的节点,discovery.seed_hosts

设置初始化住节点cluster.initial_master_nodes: [“test1”]

编辑节点1的elasticsearch.yml

shell> vim elasticsearch.yml
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: estest
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: test1
#
# Add custom attributes to the node:
#
node.attr.rack: r1
#node.master: true
#node.data: true
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /usr/local/elasticsearch/data
#
# Path to log files:
#
path.logs: /usr/local/elasticsearch/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
http.port: 9200
# 内部节点通信端口
transport.tcp.port: 9300
# 开启安全防护
http.cors.enabled: true
http.cors.allow-origin: /.*/
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
# 设置可参选master的节点
#discovery.seed_hosts: ["127.0.0.1:9300","127.0.0.1:9301","127.0.0.1:9302"]
discovery.seed_hosts: ["127.0.0.1", "[::1]"]
# ping超时时长,默认3S,适当修改,防止脑裂
discovery.zen.ping_timeout: 120s
client.transport.ping_timeout: 60s
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
cluster.initial_master_nodes: ["test1","test2","test3"]
#cluster.initial_master_nodes: ["127.0.0.1:9300","127.0.0.1:9301","127.0.0.1:9302"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true

编辑节点2的elasticsearch.yml

======================== Elasticsearch Configuration =========================
 #
 NOTE: Elasticsearch comes with reasonable defaults for most settings.
 Before you set out to tweak and tune the configuration, make sure you
 understand what are you trying to accomplish and the consequences.
 #
 The primary way of configuring a node is via this file. This template lists
 the most important settings you may want to configure for a production cluster.
 #
 Please consult the documentation for further information on configuration options:
 https://www.elastic.co/guide/en/elasticsearch/reference/index.html
 #
 ---------------------------------- Cluster -----------------------------------
 #
 Use a descriptive name for your cluster:
 #
 cluster.name: estest
 #
 ------------------------------------ Node ------------------------------------
 #
 Use a descriptive name for the node:
 #
 node.name: test2
 #
 Add custom attributes to the node:
 #
 node.attr.rack: r1
 #
 ----------------------------------- Paths ------------------------------------
 #
 Path to directory where to store the data (separate multiple locations by comma):
 #
 path.data: /usr/local/elasticsearch2/data
 #
 Path to log files:
 #
 path.logs: /usr/local/elasticsearch2/logs
 #
 ----------------------------------- Memory -----------------------------------
 #
 Lock the memory on startup:
 #
 bootstrap.memory_lock: true
 #
 Make sure that the heap size is set to about half the memory available
 on the system and that the owner of the process is allowed to use this
 limit.
 #
 Elasticsearch performs poorly when the system is swapping the memory.
 #
 ---------------------------------- Network -----------------------------------
 #
 Set the bind address to a specific IP (IPv4 or IPv6):
 #
 network.host: 0.0.0.0
 #
 Set a custom port for HTTP:
 #
 http.port: 9201
 内部节点通信端口
 transport.tcp.port: 9301
 开启安全防护
 http.cors.enabled: true
 http.cors.allow-origin: /.*/
 #
 For more information, consult the network module documentation.
 #
 --------------------------------- Discovery ----------------------------------
 #
 Pass an initial list of hosts to perform discovery when this node is started:
 The default list of hosts is ["127.0.0.1", "[::1]"]
 #
 设置可参选master的节点
 discovery.seed_hosts: ["127.0.0.1:9300","127.0.0.1:9301","127.0.0.1:9302"]
# 本例子是单机多节点,所以可以如下设置,否则采用上述设置
 discovery.seed_hosts: ["127.0.0.1", "[::1]"]
 ping超时时长,默认3S,适当修改,防止脑裂
 discovery.zen.ping_timeout: 120s
 client.transport.ping_timeout: 60s
 http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
 设置可参选master的节点
 #
 Bootstrap the cluster using an initial set of master-eligible nodes:
 #
 cluster.initial_master_nodes: ["node-1", "node-2"]
 cluster.initial_master_nodes: ["test1","test2","test3"]
 #
 For more information, consult the discovery and cluster formation module documentation.
 #
 ---------------------------------- Gateway -----------------------------------
 #
 Block initial recovery after a full cluster restart until N nodes are started:
 #
 gateway.recover_after_nodes: 3
 #
 For more information, consult the gateway module documentation.
 #
 ---------------------------------- Various -----------------------------------
 #
 Require explicit names when deleting indices:
 #
 action.destructive_requires_name: true
 node.master: false

编辑节点3的elasticsearch.yml

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: estest
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: test3
#
# Add custom attributes to the node:
#
node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: /usr/local/elasticsearch3/data
#
# Path to log files:
#
path.logs: /usr/local/elasticsearch3/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
http.port: 9202
# 内部节点通信端口
transport.tcp.port: 9302
# 开启安全防护
http.cors.enabled: true
http.cors.allow-origin: /.*/
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
#
# 设置可参选master的节点
discovery.seed_hosts: ["127.0.0.1:9300","127.0.0.1:9301","127.0.0.1:9302"]
#discovery.seed_hosts: ["host1", "host2"]
# ping超时时长,默认3S,适当修改,防止脑裂
discovery.zen.ping_timeout: 120s
client.transport.ping_timeout: 60s
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
cluster.initial_master_nodes: ["test1","test2","test3"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
node.master: false

安装elasticsearch-head 插件

shell> git clone https://github.com/mobz/elasticsearch-head
shell> cd elasticsearch-head
# 使用淘宝镜像 npm install cnpm --registry=https://registry.npm.taobao.org 
shell> npm install
# grunt 通过 npm install -g grunt-cli 安装
# http://127.0.0.1:9100/
shell> grunt server
  1. elasticsearch启动后查看是否启动成功:
    curl -XGET”http://$(hostname):9200/_cluster/health?pretty=true”
  2. 停止elasticsearch应用:
    curl -XPOST “http:// $(hostname):9200/_shutdown”
  3. 查看集群健康:
    curl $(hostname):9200/_cluster/health?pretty
  4. 检查集群状态:
    curl $(hostname):9200/_cluster/stats?pretty
  5. 节点状态:
    curl $(hostname):9200/_nodes/process?pretty
    curl $(hostname):9200/_nodes/node1/process?pretty
  6. 当你不知道有那些属性可以查看时:
    curl ‘$(hostname):9200/_cat/’,会返回可以查看的属性
{test1}{zXArX15XTiKTbkcOQDqiYg}{AjRq45q9Rz6jIH9hQ6Zl9A}{192.168.31.219}{192.168.31.219:9300}{ml.machine_memory=17179869184, rack=r1, xpack.installed=true, ml.max_open_jobs=20} with the same id but is a different node instance
这是因为,elasticsearch/data里已经有数据,复制节点的时候,该目录也复制过去了,需要清空节点下的数据 

Leave Comment

电子邮件地址不会被公开。 必填项已用*标注