大数据学习初级入门教程(九) —— Elasticsearch 7.6.2 伪分布式集群的安装、配置、启动和测试

本文主要是介绍大数据学习初级入门教程(九) —— Elasticsearch 7.6.2 伪分布式集群的安装、配置、启动和测试,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

在前一篇文章《大数据学习初级入门教程(八) —— Elasticsearch 7.6.2 单节点的安装、启动和测试》中,简要说明了在一台测试服务器上如何安装单节点 Elasticsearch 并做了简单的测试,这篇主要说下在一台机器上如何配置多个节点,需要在前一篇文章操作后的基础上,搭建 Elasticsearch 伪分布式集群,这里配置 3 个代理节点。

特别注意:由于需要在一台机器上同时启动 3 个及以上 es 实例节点,所以建议机器内存>=4g。

第一步:复制节点

以上篇文章中搭建的节点为第一节点,再完全复制两个节点出来,并重命名。详细如下:

$ cd /opt/es/

$ cp -R elasticsearch-7.6.2 elasticsearch-7.6.2-2

$ cp -R elasticsearch-7.6.2 elasticsearch-7.6.2-3

第二步:修改配置

分别修改 elasticsearch-7.6.2-2 和 elasticsearch-7.6.2-2 实例下的配置文件,修改后三个节点的配置分别如下:

elasticsearch-7.6.2/config/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: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
# 设置节点名称,集群内节点名称必须唯一
node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# 表示该节点会不会作为主节点,true表示会;false表示不会
node.master: true
# 当前节点是否用于存储数据,是:true、否:false
node.data: true
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
# 索引数据存放的位置
#path.data: /path/to/data
#
# Path to log files:
#
# 日志文件存放的位置
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
# 需要锁住物理内存,是:true、否:false
#bootstrap.memory_lock: true
# 系统调用过滤器检查,是:true、否: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):
#
# 监听地址,用于访问该es
network.host: 192.168.220.242
#
# Set a custom port for HTTP:
#
# es对外提供的http端口,默认 9200
http.port: 9200
#
# For more information, consult the network module documentation.
#
# TCP的默认监听端口,默认 9300
transport.tcp.port: 9300
#
# 是否支持跨域,是:true,在使用head插件时需要此配置
http.cors.enabled: true
# “*” 表示支持所有域名
http.cors.allow-origin: "*"
#
# --------------------------------- Discovery ----------------------------------
#
# 设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,对于大的集群来说,可以设置大一点的值(2-4)
discovery.zen.minimum_master_nodes: 2
#
# 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]"]
#
# es7.x 之后新增的配置,写入候选主节点的设备地址,在开启服务后可以被选为主节点
discovery.seed_hosts: ["192.168.220.242:9300", "192.168.220.242:9301", "192.168.220.242:9302"]
# 判断结点是否脱离时间配置
discovery.zen.fd.ping_timeout: 60s
# 判断结点是否脱离次数配置
discovery.zen.fd.ping_retries: 5
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
# es7.x 之后新增的配置,初始化一个新的集群时需要此配置来选举master
cluster.initial_master_nodes: ["node-1", "node-2", "node-3"]
#
# 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

elasticsearch-7.6.2-2/config/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: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
# 设置节点名称,集群内节点名称必须唯一
node.name: node-2
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# 表示该节点会不会作为主节点,true表示会;false表示不会
node.master: true
# 当前节点是否用于存储数据,是:true、否:false
node.data: true
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
# 索引数据存放的位置
#path.data: /path/to/data
#
# Path to log files:
#
# 日志文件存放的位置
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
# 需要锁住物理内存,是:true、否:false
#bootstrap.memory_lock: true
# 系统调用过滤器检查,是:true、否: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):
#
# 监听地址,用于访问该es
network.host: 192.168.220.242
#
# Set a custom port for HTTP:
#
# es对外提供的http端口,默认 9200
http.port: 9201
#
# For more information, consult the network module documentation.
#
# TCP的默认监听端口,默认 9300
transport.tcp.port: 9301
#
# 是否支持跨域,是:true,在使用head插件时需要此配置
http.cors.enabled: true
# “*” 表示支持所有域名
http.cors.allow-origin: "*"
#
# --------------------------------- Discovery ----------------------------------
#
# 设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,对于大的集群来说,可以设置大一点的值(2-4)
discovery.zen.minimum_master_nodes: 2
#
# 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]"]
#
# es7.x 之后新增的配置,写入候选主节点的设备地址,在开启服务后可以被选为主节点
discovery.seed_hosts: ["192.168.220.242:9300", "192.168.220.242:9301", "192.168.220.242:9302"]
# 判断结点是否脱离时间配置
discovery.zen.fd.ping_timeout: 60s
# 判断结点是否脱离次数配置
discovery.zen.fd.ping_retries: 5
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
# es7.x 之后新增的配置,初始化一个新的集群时需要此配置来选举master
cluster.initial_master_nodes: ["node-1", "node-2", "node-3"]
#
# 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

elasticsearch-7.6.2-3/config/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: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
# 设置节点名称,集群内节点名称必须唯一
node.name: node-3
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# 表示该节点会不会作为主节点,true表示会;false表示不会
node.master: true
# 当前节点是否用于存储数据,是:true、否:false
node.data: true
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
# 索引数据存放的位置
#path.data: /path/to/data
#
# Path to log files:
#
# 日志文件存放的位置
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
# 需要锁住物理内存,是:true、否:false
#bootstrap.memory_lock: true
# 系统调用过滤器检查,是:true、否: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):
#
# 监听地址,用于访问该es
network.host: 192.168.220.242
#
# Set a custom port for HTTP:
#
# es对外提供的http端口,默认 9200
http.port: 9202
#
# For more information, consult the network module documentation.
#
# TCP的默认监听端口,默认 9300
transport.tcp.port: 9302
#
# 是否支持跨域,是:true,在使用head插件时需要此配置
http.cors.enabled: true
# “*” 表示支持所有域名
http.cors.allow-origin: "*"
#
# --------------------------------- Discovery ----------------------------------
#
# 设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,对于大的集群来说,可以设置大一点的值(2-4)
discovery.zen.minimum_master_nodes: 2
#
# 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]"]
#
# es7.x 之后新增的配置,写入候选主节点的设备地址,在开启服务后可以被选为主节点
discovery.seed_hosts: ["192.168.220.242:9300", "192.168.220.242:9301", "192.168.220.242:9302"]
# 判断结点是否脱离时间配置
discovery.zen.fd.ping_timeout: 60s
# 判断结点是否脱离次数配置
discovery.zen.fd.ping_retries: 5
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
# es7.x 之后新增的配置,初始化一个新的集群时需要此配置来选举master
cluster.initial_master_nodes: ["node-1", "node-2", "node-3"]
#
# 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

第三步:启动集群

依次启动 3 个 es 节点实例:

./bin/elasticsearch

如果启动中发生如下错误,说明机器内存配置不足:

[elastic@test242 elasticsearch-7.6.2-2]$ ./bin/elasticsearch
Exception in thread "main" java.lang.RuntimeException: starting java failed with [1]
output:
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 986513408 bytes for committing reserved memory.
# An error report file with more information is saved as:
# logs/hs_err_pid4427.log
error:
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c5330000, 986513408, 0) failed; error='Not enough space' (errno=12)
        at org.elasticsearch.tools.launchers.JvmErgonomics.flagsFinal(JvmErgonomics.java:123)
        at org.elasticsearch.tools.launchers.JvmErgonomics.finalJvmOptions(JvmErgonomics.java:88)
        at org.elasticsearch.tools.launchers.JvmErgonomics.choose(JvmErgonomics.java:59)
        at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:95)

解决方法:

第一种,增加机器内存配置。

第二种,修改配置文件 elasticsearch-7.6.2/config/jvm.options 中的配置,调小内存需求。详细如下:

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space-Xms512m
-Xmx512m

如果启动中出现如下错误,信息如下:

org.elasticsearch.cluster.coordination.CoordinationStateRejectedException: not enough nodes discovered to form a quorum in the initial configuration

可以看到三个节点都报这个错误,这就是所谓的“脑裂”。脑裂是指在主备切换时,由于切换不彻底或其他原因,导致客户端和 Slave 误以为出现两个 active master,最终使得整个集群处于混乱状态。

discovery.zen.minimum_master_nodes 配置的数量如何才为最优?自动发现 master 节点的最小数,如果这个集群中配置进来的 master 节点少于这个数目,es 的日志会一直报 master 节点数目不足。(默认为1)为了避免脑裂,个数请遵从该公式 =》 total number of master - eligible nodes / 2 + 1,可以尝试修改该值为1。

再次启动集群,可以看到 3 个节点均已正常启动,无报错。通过浏览访问地址:http://192.168.220.242:9200/_cat/nodes,可以看到集群运行节点信息,如图:

备注:带 * 的为 master节点,即当前 node-2 节点为 master 节点。

这篇关于大数据学习初级入门教程(九) —— Elasticsearch 7.6.2 伪分布式集群的安装、配置、启动和测试的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/953304

相关文章

Java注解之超越Javadoc的元数据利器详解

《Java注解之超越Javadoc的元数据利器详解》本文将深入探讨Java注解的定义、类型、内置注解、自定义注解、保留策略、实际应用场景及最佳实践,无论是初学者还是资深开发者,都能通过本文了解如何利用... 目录什么是注解?注解的类型内置注编程解自定义注解注解的保留策略实际用例最佳实践总结在 Java 编程

一文教你Python如何快速精准抓取网页数据

《一文教你Python如何快速精准抓取网页数据》这篇文章主要为大家详细介绍了如何利用Python实现快速精准抓取网页数据,文中的示例代码简洁易懂,具有一定的借鉴价值,有需要的小伙伴可以了解下... 目录1. 准备工作2. 基础爬虫实现3. 高级功能扩展3.1 抓取文章详情3.2 保存数据到文件4. 完整示例

使用Java将各种数据写入Excel表格的操作示例

《使用Java将各种数据写入Excel表格的操作示例》在数据处理与管理领域,Excel凭借其强大的功能和广泛的应用,成为了数据存储与展示的重要工具,在Java开发过程中,常常需要将不同类型的数据,本文... 目录前言安装免费Java库1. 写入文本、或数值到 Excel单元格2. 写入数组到 Excel表格

Win安装MySQL8全过程

《Win安装MySQL8全过程》:本文主要介绍Win安装MySQL8全过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Win安装mysql81、下载MySQL2、解压文件3、新建文件夹data,用于保存数据库数据文件4、在mysql根目录下新建文件my.ini

SpringBoot3.4配置校验新特性的用法详解

《SpringBoot3.4配置校验新特性的用法详解》SpringBoot3.4对配置校验支持进行了全面升级,这篇文章为大家详细介绍了一下它们的具体使用,文中的示例代码讲解详细,感兴趣的小伙伴可以参考... 目录基本用法示例定义配置类配置 application.yml注入使用嵌套对象与集合元素深度校验开发

python处理带有时区的日期和时间数据

《python处理带有时区的日期和时间数据》这篇文章主要为大家详细介绍了如何在Python中使用pytz库处理时区信息,包括获取当前UTC时间,转换为特定时区等,有需要的小伙伴可以参考一下... 目录时区基本信息python datetime使用timezonepandas处理时区数据知识延展时区基本信息

Qt实现网络数据解析的方法总结

《Qt实现网络数据解析的方法总结》在Qt中解析网络数据通常涉及接收原始字节流,并将其转换为有意义的应用层数据,这篇文章为大家介绍了详细步骤和示例,感兴趣的小伙伴可以了解下... 目录1. 网络数据接收2. 缓冲区管理(处理粘包/拆包)3. 常见数据格式解析3.1 jsON解析3.2 XML解析3.3 自定义

SpringMVC 通过ajax 前后端数据交互的实现方法

《SpringMVC通过ajax前后端数据交互的实现方法》:本文主要介绍SpringMVC通过ajax前后端数据交互的实现方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价... 在前端的开发过程中,经常在html页面通过AJAX进行前后端数据的交互,SpringMVC的controll

C#使用StackExchange.Redis实现分布式锁的两种方式介绍

《C#使用StackExchange.Redis实现分布式锁的两种方式介绍》分布式锁在集群的架构中发挥着重要的作用,:本文主要介绍C#使用StackExchange.Redis实现分布式锁的... 目录自定义分布式锁获取锁释放锁自动续期StackExchange.Redis分布式锁获取锁释放锁自动续期分布式

IntelliJ IDEA 中配置 Spring MVC 环境的详细步骤及问题解决

《IntelliJIDEA中配置SpringMVC环境的详细步骤及问题解决》:本文主要介绍IntelliJIDEA中配置SpringMVC环境的详细步骤及问题解决,本文分步骤结合实例给大... 目录步骤 1:创建 Maven Web 项目步骤 2:添加 Spring MVC 依赖1、保存后执行2、将新的依赖