目录
[1. ElasticSearch下载](#1. ElasticSearch下载)
[2. 环境准备](#2. 环境准备)
[3. ElasticSearch部署](#3. ElasticSearch部署)
[3.1 修改系统配置](#3.1 修改系统配置)
[3.2 开放端口](#3.2 开放端口)
[3.3 安装 ElasticSearch](#3.3 安装 ElasticSearch)
[4. 验证](#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红表示集群不可用,有故障