Linux 下 ElasticSearch 集群部署

目录

1. ElasticSearch下载

2. 环境准备

3. ElasticSearch部署

3.1 修改系统配置

3.2 开放端口

3.3 安装 ElasticSearch

4. 验证


本文将以三台服务器为例,介绍在 linux 系统下ElasticSearch的部署方式。

1. ElasticSearch下载

    下载地址:Past Releases of Elastic Stack Software | Elastic

    选择需要的介质下载,这里以 elasticsearch-7.17.3 为例

2. 环境准备

   部署 ElasticSearch 需要先部署JDK ,JDK部署可以参考Linux下JDK 安装-CSDN博客 。

3. ElasticSearch部署

注:以下操作三台机器均需要修改

3.1 修改系统配置

(1)编辑 limits.conf文件

         vi /etc/security/limits.conf

  加入以下内容:

* soft nofile 65536
* hard nofile 131072
* soft nproc 4096
* hard nproc 4096

* soft memlock unlimited
* hard memlock unlimited

(2)编辑 sysctl.conf 文件

         vi /etc/sysctl.conf

 加入以下内容

vm.max_map_count=262144
vm.swappiness=0

(3)配置立即生效

         sysctl –p

3.2 开放端口

ElasticSearch 默认需要开通节点 9200 和 9300 端口。

(1)查看防火墙状态

        systemctl status firewalld

(2)开放端口

       firewall-cmd --zone=public --add-port=9200/tcp --permanent  

       firewall-cmd --zone=public --add-port=9300/tcp --permanent

(3)防火墙重新加载配置

       firewall-cmd --reload  

(4) 查看防火墙所有开放的端口

       firewall-cmd --zone=public --list-ports

3.3 安装 ElasticSearch

(1) 创建用户

       adduser es

       passwd es

(2) 创建数据目录

       mkdir -p /data/elasticsearch/data

       mkdir -p /data/elasticsearch/logs

       chown es:es -R /data/

(3) 解压

       上传elasticsearch介质(elasticsearch-7.17.3-linux-x86_64.tar.gz)到 /opt 目录

       tar zxvf elasticsearch-7.17.3-linux-x86_64.tar.gz

(4) 目录授权给 es 用户

       chown es:es -R /opt/elasticsearch-7.17.3

(5) 修改配置文件

       vi /opt/elasticsearch-7.17.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: es 
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#节点名称,其余两个节点分别为node-2 和node-3
node.name: node-1
#
# Add custom attributes to the node:
#
# 指定该节点是否有资格被选举成为master节点,默认为true
node.master: true
# 允许该节点存储数据(默认开启)
node.data: true
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
# 索引数据的存储路径
path.data: /data/elasticsearch/data
# Path to log files:
#
# 日志文件的存储路径
path.logs: /data/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 -----------------------------------
#
# By default Elasticsearch is only accessible on localhost. Set a different
# address here to expose this node on the network:
#当前机器节点的IP地址
network.host: IP
#当前机器节点的IP地址
network.publish_host: IP
# By default Elasticsearch listens for HTTP traffic on the first free port it
# finds starting at 9200. Set a specific HTTP port here:
#设置对外服务的http端口
http.port: 9200
# 设置节点间交互的tcp端口,默认为9300
transport.tcp.port: 9300
#
# 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]"]
#集群的所有机器节点的IP地址
discovery.seed_hosts: ["IP1","IP2","IP3"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
cluster.initial_master_nodes: ["node-1", "node-2", "node-3"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
#
# ---------------------------------- Security ----------------------------------
#
#                                 *** WARNING ***
#
# Elasticsearch security features are not enabled by default.
# These features are free, but require configuration changes to enable them.
# This means that users don’t have to provide credentials and can get full access
# to the cluster. Network connections are also not encrypted.
#
# To protect your data, we strongly encourage you to enable the Elasticsearch security features. 
# Refer to the following documentation for instructions.
#
# https://www.elastic.co/guide/en/elasticsearch/reference/7.16/configuring-stack-security.html


#通过配置大多数节点(符合主节点数/ 2 + 1)来防止分裂。
discovery.zen.minimum_master_nodes: 2

#设置为true锁住内存。因为内存交换到磁盘对服务器性能是致命的
bootstrap.memory_lock: true

(6) 配置 jvm.option

       vi /opt/elasticsearch-7.17.3/config/jvm.options

      配置ES占用物理内存大小

      -Xms10g

      -Xmx10g

     修正CVE-2021-44228漏洞

     -Dlog4j2.formatMsgNoLookups=true

(7)启动

       一定要切换到 es 用户

       su es

       cd /opt/elasticsearch-7.17.3

       bin/elasticsearch -d -p pid

4. 验证

(1) 验证启动

       jps 

出现如下内容说明已经启动 

(2) 验证集群状态

       查询集群所有节点及主节点信息

       curl -XGET 'http://IP:9200/_cat/nodes?pretty'

        查询集群状态信息

        集群状态:

       -green正常,表示集群一切正常。

       -yellow黄表示集群不可靠但可用,一般单节时候就是这个状态。

       -red红表示集群不可用,有故障

相关推荐

  1. linux系统部署Elasticsearch

    2024-07-18 08:10:03       43 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-18 08:10:03       66 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-18 08:10:03       70 阅读
  3. 在Django里面运行非项目文件

    2024-07-18 08:10:03       57 阅读
  4. Python语言-面向对象

    2024-07-18 08:10:03       68 阅读

热门阅读

  1. Excel表格导出

    2024-07-18 08:10:03       18 阅读
  2. 将一个tensor可视化

    2024-07-18 08:10:03       22 阅读
  3. Tomcat长连接源码解析

    2024-07-18 08:10:03       20 阅读
  4. 华为欧拉openEuler24.03 rpm安装 MySQL8.4

    2024-07-18 08:10:03       24 阅读
  5. 深入解析Apache Hive架构

    2024-07-18 08:10:03       23 阅读
  6. strncpy 和 snprintf 的区别

    2024-07-18 08:10:03       22 阅读
  7. Kafka系列之:Kafka存储数据相关重要参数理解

    2024-07-18 08:10:03       17 阅读
  8. Oracle(8)什么是Oracle实例(Instance)?

    2024-07-18 08:10:03       22 阅读
  9. python 迭代器介绍 map() 函数

    2024-07-18 08:10:03       19 阅读
  10. Linux chmod 命令简介

    2024-07-18 08:10:03       24 阅读
  11. QT+winodow 代码适配调试总结(三)

    2024-07-18 08:10:03       21 阅读
  12. 代码随想录学习 54day 图论 A star算法

    2024-07-18 08:10:03       16 阅读