≡菜单

如何安装和配置具有多个节点的Elasticsearch集群

[Elasticsearch集群设置]在之前的Elasticsearch教程中,我们讨论了如何安装和设置独立的Elasticsearch实例。

尽管独立安装对于开发人员/测试而言是一件好事,但对于生产而言,建议您设置Elasticsearch集群。 Elasticsearch集群比独立集群具有许多优势。

Elastisearch集群的优势

  1. 分布式数据:在集群中,数据已分发,复制到其他服务器。因此,在一个节点发生故障的情况下,可以从副本节点还原数据。它避免了单点故障。
  2. 专用节点角色:每个节点都分配有专用角色,以确保特定的角色和基于角色的负载分配,从而提高性能。这是两个重要的节点角色
  3. 数据节点:这些节点仅存储数据,并执行与数据相关的操作,搜索和数据操作。
  4. 主节点:所有节点的主节点,负责整个群集,从群集中添加和删除节点,跟踪活动节点,在适当情况下重新选择主机。
  5. 可扩展性:集群模型可以轻松地扩展到多个节点。从而提高了弹性搜索的性能和可靠性。

在本教程中,我们’ll设置三节点elasticsearch集群。

节点1–安装和配置

让我们开始安装elasticsearch,在安装过程中,我将展示每个步骤

遵循我们之前的文章 如何安装Elasticsearch 并下载elasticsearch zip归档文件,将其解压缩到服务器上或使用deb信息库进行安装。

现在,在解压缩的文件夹中打开Elasticsearch配置文件,如果直接从repo安装,则打开/ etc / elasticsearch。

vim /etc/elasticsearch/elasticsearch.yml

现在我们必须将其配置为群集节点,需要在以上文件中修改以下条目。

设置集群名称:

cluster-name=TGS

设置第一个节点名称:

node.name=tgs-1

设置此节点是否将充当主节点:

node.master=true

设置此节点是否将充当数据节点:

node.data=true

设置第一个节点’s ip and port:

network.host=192.168.101.51
http.port=9200

群集节点发现协议和节点列表:

discovery.zen.ping.unicast.hosts: ["192.168.101.51", "192.168.101.52","192.168.101.53"]

这些都是群集中所有节点的一部分,这使节点发现变得容易。

现在启动elasticsearch服务器,以下是安装日志的重要部分:

[INFO ][o.e.c.s.ClusterApplierService] [tgs-1] new_master {tgs-1}{7IqQvmfdSb66AFcP0u0AZQ}{OveP8d_SR0WIjVupZcW35g}{192.168.101.51}{192.168.101.51:9300}{ml.machine_memory=134986862592xpack.installed=trueml.max_open_jobs=20ml.enabled=true}reason: apply cluster state (from master [master {tgs-1}{7IqQvmfdSb66AFcP0u0AZQ}{OveP8d_SR0WIjVupZcW35g}{192.168.101.51}{192.168.101.51:9300}{ml.machine_memory=134986862592xpack.installed=trueml.max_open_jobs=20ml.enabled=true} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])
[INFO ][o.e.h.n.Netty4HttpServerTransport] [tgs-1] publish_address {192.168.101.51:9200}bound_addresses {192.168.101.51:9200}
[INFO ][o.e.n.Node               ] [tgs-1] started
[WARN ][o.e.x.s.a.s.m.NativeRoleMappingStore] [tgs-1] Failed to clear cache for realms [[]]
[INFO ][o.e.l.LicenseService     ] [tgs-1] license [77777777-dddd-4444-aaaa-888888888888] mode [basic] - valid
[INFO ][o.e.g.GatewayService     ] [tgs-1] recovered [0] indices into cluster_state
[INFO ][o.e.c.s.MasterService    ] [tgs-1] zen-disco-node-join[{tgs-2}{S64iPm03Qtq0-bvJipk-_A}{eAChESS6TceLHHTHyfMU7g}{192.168.101.52}{192.168.101.52:9300}{ml.machine_memory=134986862592ml.max_open_jobs=20xpack.installed=trueml.enabled=true}]reason: added {{tgs-2}{S64iPm03Qtq0-bvJipk-_A}{eAChESS6TceLHHTHyfMU7g}{192.168.101.52}{192.168.101.52:9300}{ml.machine_memory=134986862592ml.max_open_jobs=20xpack.installed=trueml.enabled=true},}
[INFO ][o.e.c.s.ClusterApplierService] [tgs-1] added {{tgs-2}{S64iPm03Qtq0-bvJipk-_A}{eAChESS6TceLHHTHyfMU7g}{192.168.101.52}{192.168.101.52:9300}{ml.machine_memory=134986862592ml.max_open_jobs=20xpack.installed=trueml.enabled=true},}reason: apply cluster state (from master [master {tgs-1}{7IqQvmfdSb66AFcP0u0AZQ}{OveP8d_SR0WIjVupZcW35g}{192.168.101.51}{192.168.101.51:9300}{ml.machine_memory=134986862592xpack.installed=trueml.max_open_jobs=20ml.enabled=true} committed version [4] source [zen-disco-node-join[{tgs-2}{S64iPm03Qtq0-bvJipk-_A}{eAChESS6TceLHHTHyfMU7g}{192.168.101.52}{192.168.101.52:9300}{ml.machine_memory=134986862592ml.max_open_jobs=20xpack.installed=trueml.enabled=true}]]])

节点2–安装和配置

登录第二台服务器,安装elasticsearch或从下载的zip存档中提取

相应地编辑配置文件。

设置集群名称:

cluster-name=TGS

设置第二个节点名称:

node.name=tgs-2

设置此节点是否将充当主节点:

node.master=true

设置此节点是否将充当数据节点:

node.data=true

设置第二个节点’s ip and port:

network.host=192.168.101.52
http.port=9200

群集节点发现协议和节点列表:

discovery.zen.ping.unicast.hosts: ["192.168.101.51", "192.168.101.52","192.168.101.53"]

这些都是群集中所有节点的一部分,这使节点发现变得容易。

现在启动elasticsearch服务器,以下是安装日志的重要部分

[INFO ][o.e.c.s.ClusterApplierService] [tgs-2] detected_master {tgs-1}
[WARN ][o.e.x.s.a.s.m.NativeRoleMappingStore] [tgs-2] Failed to clear cache for realms [[]]
[INFO ][o.e.x.s.a.TokenService   ] [tgs-2] refresh keys
[INFO ][o.e.x.s.a.TokenService   ] [tgs-2] refreshed keys
[INFO ][o.e.l.LicenseService     ] [tgs-2] license [77777777-dddd-4444-aaaa-888888888888] mode [basic] - valid
[INFO ][o.e.h.n.Netty4HttpServerTransport] [tgs-2] publish_address {192.168.101.52:9200}, bound_addresses {192.168.101.52:9200}
[INFO ][o.e.n.Node               ] [tgs-2] started
[INFO ][o.e.c.s.ClusterApplierService] [tgs-2] added {{tgs-3}

节点3–安装和配置

登录到第三台服务器并安装elasticsearch或解压缩下载的zip存档

设置集群名称:

cluster-name=TGS

设置第三个节点名称:

node.name=tgs-3

设置此节点是否将充当主节点:

node.master=true

设置此节点是否将充当数据节点:

node.data=true

设置第二个节点’s ip and port:

network.host=192.168.101.53
http.port=9200

群集节点发现协议和节点列表

discovery.zen.ping.unicast.hosts: ["192.168.101.51", "192.168.101.52","192.168.101.53"]

这些都是群集中所有节点的一部分,这使节点发现变得容易。

现在启动elasticsearch服务器,以下是安装日志的重要部分

[INFO ][o.e.c.s.ClusterApplierService] [tgs-3] detected_master {tgs-1}
[WARN ][o.e.x.s.a.s.m.NativeRoleMappingStore] [tgs-3] Failed to clear cache for realms [[]]
[INFO ][o.e.x.s.a.TokenService   ] [tgs-3] refresh keys
[INFO ][o.e.x.s.a.TokenService   ] [tgs-3] refreshed keys
[INFO ][o.e.l.LicenseService     ] [tgs-3] license [77777777-dddd-4444-aaaa-888888888888] mode [basic] - valid
[INFO ][o.e.h.n.Netty4HttpServerTransport] [tgs-3] publish_address {192.168.101.53:9200}, bound_addresses {192.168.101.53:9200}
[INFO ][o.e.n.Node               ] [tgs-3] started

验证Elasticsearch集群状态

我们的集群已设置并且正在运行,让我们验证一下此集群设置,我们可以使用弹性搜索集群API来检查集群的状态(在ES系列文章中将详细介绍集群API)

curl -XGET 'http://localhost:9200/_cluster/state?pretty'

输出:

{
"cluster_name" : "TGS",
"cluster_uuid" : "vlt_bBfJRP268MFFA5XY4w",
"version" : 5,
"state_uuid" : "VxN1E51xRievom5n1BDiNQ",
"master_node" : "7IqQvmfdSb66AFcP0u0AZQ",
"blocks" : { },
"nodes" : {
"S64iPm03Qtq0-bvJipk-_A" : {
"name" : "tgs-2",
"ephemeral_id" : "eAChESS6TceLHHTHyfMU7g",
"transport_address" : "192.168.101.52:9300",
"attributes" : {
"ml.machine_memory" : "134986862592",
"ml.max_open_jobs" : "20",
"xpack.installed" : "true",
"ml.enabled" : "true"
}
},
"syxQbgRPS4q992NXkx3ptw" : {
"name" : "tgs-3",
"ephemeral_id" : "-uK6TjQ2Qz6o_6arfmRR3Q",
"transport_address" : "192.168.101.53:9300",
"attributes" : {
"ml.machine_memory" : "134986862592",
"ml.max_open_jobs" : "20",
"xpack.installed" : "true",
"ml.enabled" : "true"
}
},
"7IqQvmfdSb66AFcP0u0AZQ" : {
"name" : "tgs-1",
"ephemeral_id" : "OveP8d_SR0WIjVupZcW35g",
"transport_address" : "192.168.101.51:9300",
"attributes" : {
"ml.machine_memory" : "134986862592",
"xpack.installed" : "true",
"ml.max_open_jobs" : "20",
"ml.enabled" : "true"
}
}
},

这是状态API的重要部分,它显示集群,节点,传输地址和ID。

curl -XGET 'http://localhost:9200/_cluster/health'

输出:

{
"cluster_name" : "TGS",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 3,
"number_of_data_nodes" : 3,
"active_primary_shards" : 0,
"active_shards" : 0,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 100.0
}

上面的输出显示了群集及其整体的运行状况’当前状态为绿色。

如果您喜欢这篇文章,您可能还会喜欢..

  1. 50个Linux Sysadmin教程
  2. 50个最常用的Linux命令(包括示例)
  3. 排名前25位的最佳Linux性能监视和调试工具
  4. 妈妈,我找到了! – 15个实用的Linux Find命令示例
  5. Linux 101 Hacks第二版电子书 Linux 101黑客手册

Bash 101 Hacks书 Sed和Awk 101黑客手册 Nagios Core 3书 Vim 101黑客手册

{ 0 评论… 加一 }

发表评论