Linux下安装elasticsearch(Elasticsearch 7.17.23)

Elasticsearch 是一个分布式的搜索和分析引擎,能够以近乎实时的速度存储、搜索和分析大量数据。它被广泛应用于日志分析、全文搜索、应用程序监控等场景。

本文将带你一步步在 Linux 系统上安装 Elasticsearch 7.17.23 版本,并完成基本的配置,为后续的使用打下基础。

你将学到:

  • 如何在 Linux 系统上下载和安装 Elasticsearch 7.17.23

  • 如何配置 Elasticsearch 的基本参数

  • 如何启动和停止 Elasticsearch 服务

  • 如何验证 Elasticsearch 是否安装成功

准备工作:

  • 一台运行 Linux 系统的服务器

  • 确保服务器上已经安装了 Java 8 或更高版本

  • 以 root 用户或具有 sudo 权限的用户身份登录

接下来,我们将按照以下步骤进行安装:

  1. 下载 Elasticsearch 7.17.23 安装包

  2. 解压安装包并配置环境变量

  3. 修改 Elasticsearch 配置文件

  4. 启动 Elasticsearch 服务

  5. 验证 Elasticsearch 是否安装成功

1. 下载 Elasticsearch 7.17.23 安装包

Elasticsearch 7.17.23 | Elastic

直接在官方下载对应安装包。

2. 解压安装包并配置环境变量

把安装包上传到服务器后,拷贝到/usr/local目录下,执行解压命令:

bash 复制代码
tar -xzf elasticsearch-7.3.2-linux-x86_64.tar.gz

由于ES不允许用root账号启动,这里需要创建用户,例如:elastic

创建过程如下:

bash 复制代码
sudo useradd -m -d /home/elastic -s /bin/bash elastic
sudo passwd elastic  # 设置密码
sudo chown -R elastic:elastic /usr/local/elasticsearch-7.17.23

切换elastic账号

bash 复制代码
su - elastic

3.修改 Elasticsearch 配置文件

进入 Elasticsearch目录:

bash 复制代码
cd /usr/local/elasticsearch/config

例如:

开始修改配置文件elasticsearch.yml:

记得自己创建好对应路径的文件夹分配好权限!!!!

bash 复制代码
sudo chown -R elastic:elastic /usr/local/elasticsearch/
sudo chmod -R 755 /usr/local/elasticsearch/

修改配置文件jvm.options:

4.启动 Elasticsearch 服务

执行以下命令。如果不报错,则跳转到第五点看结果。

bash 复制代码
/usr/local/elasticsearch-7.17.23/bin/elasticsearch -d

5.如何验证 Elasticsearch 是否安装成功

一切正常的情况下,配置完成后,运行 **:**curl -X GET "localhost:9200",出现如下图,则表示安装完成!

但是,肯定不会有正常情况

我们来说一下常见的错误:

(1)如果系统配置的是jdk8,启动会出现jdk版本不匹配等错误,如下:

XML 复制代码
warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME
Future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/java/jdk1.8.0_144/jre] does not meet this requirement. Consider switching to a distribution of Elasticsearch with a bundled JDK. If you are already using a distribution with a bundled JDK, ensure the JAVA_HOME environment variable is not set.
warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME
Future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/java/jdk1.8.0_144/jre] does not meet this requirement. Consider switching to a distribution of Elasticsearch with a bundled JDK. If you are already using a distribution with a bundled JDK, ensure the JAVA_HOME environment variable is not set.

解决办法就是,修改jdk指向路径,默认使用es自带的JDK,找到文件

/usr/local/elasticsearch-7.17.23/bin下的:elasticsearch-env编辑,

bash 复制代码
vim elasticsearch-env

注释掉一部分配置,如下图:

这样就解决jdk问题了。这个是常见问题。。另外还有几个不常见的:

(1) 两项系统限制值过低 ,需要调整 max file descriptorsvm.max_map_count

错误信息如下:

XML 复制代码
ERROR: [2] bootstrap checks failed. You must address the points described in the following [2] lines before starting Elasticsearch.
bootstrap check failure [1] of [2]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
bootstrap check failure [2] of [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
ERROR: Elasticsearch did not exit normally - check the logs at /usr/local/elasticsearch/logs/my-cluster.log

直接切换root账号调整:

bash 复制代码
sudo vi /etc/security/limits.conf

在文件末尾添加以下两行:

bash 复制代码
elastic soft nofile 65535
elastic hard nofile 65535

退出保存!解决

(2)vm.max_map_count 的值太低,错误信息如下:

bash 复制代码
ERROR: [1] bootstrap checks failed. You must address the points described in the following [1] lines before starting Elasticsearch.
bootstrap check failure [1] of [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
ERROR: Elasticsearch did not exit normally - check the logs at /usr/local/elasticsearch/logs/my-cluster.log

切换root,编辑sysctl.conf

bash 复制代码
 vi /etc/sysctl.conf

添加:vm.max_map_count=262144

保存退出!解决!!

最后,我们得给es配置个密码吧,有密码才像那么一回事!

设置密码方式有三种,我们选择最稳妥的通过 elasticsearch-setup-passwords 工具设置密码

修改配置文件

bash 复制代码
sudo vi /usr/local/elasticsearch-7.17.23/config/elasticsearch.yml

新增一下内容:

bash 复制代码
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true

如图:

运行命令:

bash 复制代码
/usr/local/elasticsearch-7.17.23/bin/elasticsearch-setup-passwords interactive

提示是否设置密码。如图:

会让设置很多账号的密码:

依次输入密码。建议同一个密码!

修改完成后,重启es服务!大功告成。。

相关推荐
重生之绝世牛码4 分钟前
Linux软件安装 —— SSH免密登录
大数据·linux·运维·ssh·软件安装·免密登录
StarChainTech18 分钟前
无人机租赁平台:开启智能租赁新时代
大数据·人工智能·微信小程序·小程序·无人机·软件需求
Hello.Reader27 分钟前
Flink DynamoDB Connector 用 Streams 做 CDC,用 BatchWriteItem 高吞吐写回
大数据·python·flink
早日退休!!!28 分钟前
内存泄露(Memory Leak)核心原理与工程实践报告
大数据·网络
发哥来了1 小时前
主流AI视频生成工具商用化能力评测:五大关键维度对比分析
大数据·人工智能·音视频
無森~1 小时前
MapReduce
大数据·mapreduce
重生之绝世牛码1 小时前
Linux软件安装 —— zookeeper集群安装
大数据·linux·运维·服务器·zookeeper·软件安装
!chen2 小时前
大数据技术领域发展与Spark的性能优化
大数据·性能优化·spark
重生之绝世牛码2 小时前
Linux软件安装 —— kafka集群安装(SASL密码验证)
大数据·linux·运维·服务器·分布式·kafka·软件安装
行业探路者2 小时前
如何利用二维码提升富媒体展示的效果?
大数据·人工智能·学习·产品运营·软件工程