大数据环境搭建系列【六】Elasticsearch集群搭建

前言

本文记录搭建ES集群的过程,系统使用centos7

集群规划

本文通过三个节点搭建ES集群,集群规划如下

hostnameIP
ES1192.168.88.60
ES2192.168.88.61
ES3192.168.88.62

JDK环境

安装ES需要jdk环境,首先每台机器都需要准备安装jdk,这里不做详细描述了
jdk版本和es的兼容性

关闭防火墙、hosts配置

(略)

ES安装

  • 下载
    下载地址
    选择linux x86 版本,我下载的版本号是8.2.3
  • 安装
    解压到指定安装目录,我这里安装在opt下
tar -zxvf elasticsearch-8.2.3-linux-x86_64.tar.gz -C /opt/

ES配置

ES的配置文件在config目录下,以下介绍几个重点配置

  • elasticsearch.yml es的核心配置
    首先新建ES的数据目录及日志存储路径
mkdir -p /home/es/data
mkdir -p /home/es/logs
# ======================== 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: ES-1
#
# 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: /home/es/data
#
# Path to log files:
#
path.logs: /home/es/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 -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#
network.host: ES1
#
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#
http.port: 9200
#
# 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]"]
#
discovery.seed_hosts: ["ES1", "ES2","ES3"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["ES-1", "ES-2","ES-3"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# --------------------------------- Readiness ----------------------------------
#
# Enable an unauthenticated TCP readiness endpoint on localhost
#
#readiness.port: 9399
#
# ---------------------------------- Various -----------------------------------
#
# Allow wildcard deletion of indices:
#
#action.destructive_requires_name: false

  • jvm.options es的jvm参数配置
    主要配置一下jvm heap的大小
################################################################
## IMPORTANT: JVM heap size
################################################################
##
## The heap size is automatically configured by Elasticsearch
## based on the available memory in your system and the roles
## each node is configured to fulfill. If specifying heap is
## required, it should be done through a file in jvm.options.d,
## which should be named with .options suffix, and the min and
## max should be set to the same value. For example, to set the
## heap to 4 GB, create a new file in the jvm.options.d
## directory containing these lines:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/8.2/heap-size.html
## for more information
##
################################################################

创建ES用户修改权限

首先要说明的是elasticsearch 不能使用root启动,所以启动前或者安装前创建一个elasticsearch用户,然后把文件所有者都改为该用户

useradd esuser
chown -R esuser:esuser /opt/elasticsearch-8.2.3
chown -R esuser:esuser /home/es

启动集群

三台机器都安装配置好以后都执行以下启动操作

su esuser
/opt/elasticsearch-8.2.3/bin/elasticsearch

启动异常解决

  • max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
    字面意思是最大虚拟内存空间为65530,太低了,需要增加到至少262144。那就增加到大于这个值就可以了,至于大多少就根据自己服务器的情况看了,具体就是配置sysctl.conf文件
vim /etc/sysctl.conf 

#文件末尾追加
vm.max_map_count=655360

加载配置

sysctl -p
  • max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
    elasticsearch进程的最大文件描述符[4096]太低,增加到至少[65535],修改以下文件进行配置
vim /etc/security/limits.conf

#末尾追加
esuser hard nofile 65536
esuser soft nofile 65536

esuser 表示运行 elasticsearch 的用户,hard 与 soft 表示限制的类型,nofile 表示 max number of open file descriptors,65536 表示设置的大小。

查看集群的状态

http://192.168.88.60:9200/_cat/health?v

页面返回以上内容status为green表示集群目前在最佳状态

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
概述: Elasticsearch是一个高度可扩展的开源全文搜索和分析引擎,它可以处理大量结构化和非结构化数据。在本文中,我们将了解如何在Linux环境中搭建Elasticsearch集群。 步骤: 步骤1:安装Java 在安装Elasticsearch之前,Java是必需的。您可以使用以下命令从命令行安装Java: ``` sudo apt-get update sudo apt-get install default-jre ``` 步骤2:下载和安装Elasticsearch 您可以从Elasticsearch官方网站下载最新版本的Elasticsearch。下载完成后,您可以使用以下命令安装它: ``` sudo dpkg -i elasticsearch-7.10.1-amd64.deb ``` 步骤3:配置Elasticsearch 默认情况下,Elasticsearch将在本地主机上运行。您可以通过编辑以下文件来更改默认配置: ``` sudo nano /etc/elasticsearch/elasticsearch.yml ``` 在此文件中,您可以更改以下设置: - cluster.name:设置集群名称。 - node.name:设置节点名称。 - network.host:设置网络接口。 - http.port:设置HTTP端口。 步骤4:启动Elasticsearch 要启动Elasticsearch,请使用以下命令: ``` sudo systemctl start elasticsearch ``` 要检查Elasticsearch是否正在运行,请使用以下命令: ``` sudo systemctl status elasticsearch ``` 步骤5:配置Elasticsearch集群 要配置Elasticsearch集群,请编辑以下文件: ``` sudo nano /etc/elasticsearch/elasticsearch.yml ``` 在该文件中,您可以使用以下设置来配置集群: - cluster.name:设置集群名称。 - node.name:设置节点名称。 - network.host:设置网络接口。 - http.port:设置HTTP端口。 - discovery.seed_hosts:设置种子主机列表。 在配置文件中,您还需要更改以下设置: ``` cluster.initial_master_nodes: ["node-1", "node-2"] ``` 此设置定义了集群中的初始主节点。您需要在每个节点上设置不同的名称。 步骤6:启动Elasticsearch集群 要启动Elasticsearch集群,请使用以下命令: ``` sudo systemctl start elasticsearch ``` 要检查Elasticsearch集群是否正在运行,请使用以下命令: ``` curl -X GET "http://localhost:9200/_cluster/health?pretty=true" ``` 此命令将显示有关集群的健康状态信息。 结论: 在本文中,我们了解了如何在Linux环境中搭建Elasticsearch集群。我们从安装Java开始,然后下载和安装Elasticsearch。接下来,我们配置了Elasticsearch,并启动了它。最后,我们配置了Elasticsearch集群,并启动了它。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值