Elasticsearch 多机集群配置

版权声明:本文为博主原创文章,转载请注明链接地址。谢谢! https://blog.csdn.net/wdy_2099/article/details/88637179

一.集群健康值

Elasticsearch 是有集群健康值的,红色,黄色,绿色
1)如果我们是单机单节点的Elasticsearch ,也就是说只有一个主节点的情况下,集群健康值是黄色的。也就是说只保存了一份数据。
2)如果此时我们新增一个节点,那么这个节点会默认成为主节点的副本节点,并同步对应数据。此时集群健康值是绿色的。即有2份数据可用。
3)如果一开始就有多个节点,一个主节点,多个字节点,此时往es集群里添加数据后。数据会被存储到不同的节点中去。若此时关闭其中有数据的一个子节点,那么就会出现数据丢失的情况,此时es集群健康值就是红色的了。

二.集群配置

1)首先得先将Elasticsearch 安装部署到2台服务器中(注意:不是一个机器安装2次)。

具体安装参见:Elasticsearch从概念到安装启动 https://blog.csdn.net/wdy_2099/article/details/85321763
此外,我们用到了head插件,安装直通车:https://blog.csdn.net/wdy_2099/article/details/85334014

2)假设我们安装到了2台机器,一台机器为192.168.1.101,该机器设置为主节点,即对外暴露的节点;一台机器为192.168.1.102,该机器为子节点。
那么我们进入Elasticsearch的根目录下的config/目录下,修改elasticsearch.yml配置文件,其中

192.168.1.101的配置如下:

# ======================== 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: my-es-search
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-001
node.master: true
node.data: true
#
# 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/elasticsearch-5.6.1/data
#
# Path to log files:
#
path.logs: /usr/local/elasticsearch-5.6.1/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
#
# 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: 192.168.1.101
#
# Set a custom port for HTTP:
#
http.port: 9200
transport.tcp.port: 9300 
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
discovery.zen.ping.unicast.hosts: ["192.168.1.101"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 3
#
# For more information, consult the zen discovery 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.max_local_storage_nodes: 2

192.168.1.102节点的配置信息如下:

	# ======================== 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: my-es-search
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: node-002
node.master: false
node.data: true
#
# 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/elasticsearch-5.6.1/data
#
# Path to log files:
#
path.logs: /usr/local/elasticsearch-5.6.1/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
#
# 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: 192.168.1.102
#
# Set a custom port for HTTP:
#
http.port: 9200
#transport.tcp.port: 9300 
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
discovery.zen.ping.unicast.hosts: ["192.168.1.101"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 3
#
# For more information, consult the zen discovery 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.max_local_storage_nodes: 2

配置文件注意:

两台台机器务必是新安装的es,且子节点的data log目录务必重新生成
1)discovery.zen.ping.unicast.hosts: [“192.168.1.101”] 必须配置与主节点相同,且为主节点的IP地址
2)cluster.name: my-es-search 集群名称必须相同
3)node.master: false 主节点为true,子节点为false
4)node.data: true 配置一样即可。
其余按照实际配置即可。

三.集群启动

配置完成后,先启动主节点。如下:

[time package info...] [node-001] initializing ...
[time package info...] [node-001] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [84.9gb], net total_space [98.3gb], spins? [unknown], types [rootfs]
[time package info...] [node-001] heap size [1.9gb], compressed ordinary object pointers [true]
[time package info...] [node-001] node name [node-001], node ID [uQOY64GASyaICyTvDHbNYw]
[time package info...] [node-001] version[5.6.1], pid[4456], build[667b497/2017-09-14T19:22:05.189Z], OS[Linux/3.10.0-693.2.2.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_171/25.171-b11]
[time package info...] [node-001] JVM arguments [-Xms2g, -Xmx2g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -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, -Des.path.home=/lhyt/servers/elasticsearch-5.6.1]
[time package info...] [node-001] loaded module [aggs-matrix-stats]
[time package info...] [node-001] loaded module [ingest-common]
[time package info...] [node-001] loaded module [lang-expression]
[time package info...] [node-001] loaded module [lang-groovy]
[time package info...] [node-001] loaded module [lang-mustache]
[time package info...] [node-001] loaded module [lang-painless]
[time package info...] [node-001] loaded module [parent-join]
[time package info...] [node-001] loaded module [percolator]
[time package info...] [node-001] loaded module [reindex]
[time package info...] [node-001] loaded module [transport-netty3]
[time package info...] [node-001] loaded module [transport-netty4]
[time package info...] [node-001] loaded plugin [analysis-ik]
[time package info...] [node-001] using discovery type [zen]
[time package info...] [node-001] initialized
[time package info...] [node-001] starting ...
[time package info...] [node-001] publish_address {192.168.1.101:9300}, bound_addresses {192.168.1.101:9300}
[time package info...] [node-001] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
[time package info...] [node-001] new_master {node-001}{uQOY64GASyaICyTvDHbNYw}{d_vvxD2nT_uOmfBfNQ9__Q}{192.168.1.101}{192.168.1.101:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
[time package info...ransport] [node-001] publish_address {192.168.1.101:9200}, bound_addresses {192.168.1.101:9200}
[time package info...] [node-001] started

启动主节点成功后,此时节点为黄色,如下图
在这里插入图片描述
接下来,启动子节点,启动日志如下:

[time package info...] [node-002] initializing ...
[time package info...] [node-002] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [62.8gb], net total_space [98.3gb], spins? [unknown], types [rootfs]
[time package info...] [node-002] heap size [1.9gb], compressed ordinary object pointers [true]
[time package info...] [node-002] node name [node-002], node ID [0_qZmfKjRiiQhz-19HhQDg]
[time package info...] [node-002] version[5.6.1], pid[11146], build[667b497/2017-09-14T19:22:05.189Z], OS[Linux/3.10.0-693.2.2.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_171/25.171-b11]
[time package info...] [node-002] JVM arguments [-Xms2g, -Xmx2g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -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, -Des.path.home=/usr/local/tg/tools/elasticsearch-5.6.1]
[time package info...] [node-002] loaded module [aggs-matrix-stats]
[time package info...] [node-002] loaded module [ingest-common]
[time package info...] [node-002] loaded module [lang-expression]
[time package info...] [node-002] loaded module [lang-groovy]
[time package info...] [node-002] loaded module [lang-mustache]
[time package info...] [node-002] loaded module [lang-painless]
[time package info...] [node-002] loaded module [parent-join]
[time package info...] [node-002] loaded module [percolator]
[time package info...] [node-002] loaded module [reindex]
[time package info...] [node-002] loaded module [transport-netty3]
[time package info...] [node-002] loaded module [transport-netty4]
[time package info...] [node-002] loaded plugin [analysis-ik]
[time package info...] [node-002] using discovery type [zen]
[time package info...] [node-002] initialized
[time package info...] [node-002] starting ...
[time package info...] [node-002] publish_address {192.168.1.102:9300}, bound_addresses {192.168.1.102:9300}
[time package info...] [node-002] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
[time package info...] [node-002] detected_master {node-001}{uQOY64GASyaICyTvDHbNYw}{d_vvxD2nT_uOmfBfNQ9__Q}{192.168.1.101}{192.168.1.101:9300}, added {{node-001}{uQOY64GASyaICyTvDHbNYw}{d_vvxD2nT_uOmfBfNQ9__Q}{192.168.1.101}{192.168.1.101:9300},}, reason: zen-disco-receive(from master [master {node-001}{uQOY64GASyaICyTvDHbNYw}{d_vvxD2nT_uOmfBfNQ9__Q}{192.168.1.101}{192.168.1.101:9300} committed version [12]])
[time package info...] [node-002] publish_address {192.168.1.102:9200}, bound_addresses {192.168.1.102:9200}
[time package info...] [node-002] started
[time package info...] try load config from /usr/local/tg/tools/elasticsearch-5.6.1/config/analysis-ik/IKAnalyzer.cfg.xml
[time package info...] try load config from /usr/local/tg/tools/elasticsearch-5.6.1/plugins/elasticsearch/config/IKAnalyzer.cfg.xml

注意:与此同时,在主节点的日志中会打印如下信息:

[time package info...] [node-001] added {{node-002}{0_qZmfKjRiiQhz-19HhQDg}{mln_Ctf-QGSi1N0K-IJ6Qg}{192.168.1.102}{192.168.1.102:9300},}, reason: zen-disco-node-join[{node-002}{0_qZmfKjRiiQhz-19HhQDg}{mln_Ctf-QGSi1N0K-IJ6Qg}{192.168.1.102}{192.168.1.102:9300}]
[time package info...] [node-001] Cluster health status changed from [YELLOW] to [GREEN] (reason: [shards started [[blog][4]] ...]).

看只管的看出,add了一个新的节点node-002, 且说Cluster health status changed from [YELLOW] to [GREEN] ,意思是:集群健康值从黄色变成了绿色。具体head中表现如下图:
在这里插入图片描述
那以上就是Elasticsearch的多机器集群配置了。还是比较简单的。

没有更多推荐了,返回首页