Linux下安装elasticsearch(Elasticsearch 7.17.23)

ops/2025/3/10 19:01:52/

       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目录下,执行解压命令:

tar -xzf elasticsearch-7.3.2-linux-x86_64.tar.gz

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

创建过程如下:

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账号

su - elastic

3.修改 Elasticsearch 配置文件

进入Elasticsearch目录:

cd /usr/local/elasticsearch/config

例如:

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

 

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

sudo chown -R elastic:elastic /usr/local/elasticsearch/
sudo chmod -R 755 /usr/local/elasticsearch/

 修改配置文件jvm.options:

4.启动 Elasticsearch 服务

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

/usr/local/elasticsearch-7.17.23/bin/elasticsearch -d

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

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

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

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

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

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编辑,

vim elasticsearch-env

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

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

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

错误信息如下:

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账号调整:

sudo vi /etc/security/limits.conf

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

elastic soft nofile 65535
elastic hard nofile 65535

退出保存!解决

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

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

 vi /etc/sysctl.conf

添加:vm.max_map_count=262144

保存退出!解决!!

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

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

修改配置文件

sudo vi /usr/local/elasticsearch-7.17.23/config/elasticsearch.yml

新增一下内容:

http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true

如图: 

 运行命令:

/usr/local/elasticsearch-7.17.23/bin/elasticsearch-setup-passwords interactive

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

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

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

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


http://www.ppmy.cn/ops/164731.html

相关文章

【Git】合并冲突

合并冲突 可是,在实际分支合并的时候,并不是想合并就能合并成功的,有时候可能会遇到代码冲突的问题。 为了演示这问题,创建一个新的分支 dev1 ,并切换至目标分支,我们可以使用 git checkout -b dev1 一步…

高考數學。。。

2024上 具体来说,直线的参数方程可以写为: x1t y−t z1t 二、简答题(本大题共5小题,每小题7分,共35分。) 12.数学学习评价不仅要关注结果评价,也要关注过程评价。简要说明过程评价应关注哪几个方面。…

【Linux-网络】HTTP的清风与HTTPS的密语

🎬 个人主页:谁在夜里看海. 📖 个人专栏:《C系列》《Linux系列》《算法系列》 ⛰️ 道阻且长,行则将至 目录 📚 引言 📚 一、HTTP 📖 1.概述 📖 2.URL &#x1f5…

聊天室Python脚本——ChatGPT,好用

下面提供两个 Python 脚本,一个作为服务器端(chat_server.py),一个作为客户端(chat_client.py)。你可以在一台电脑上运行服务器脚本,然后在不同电脑上运行客户端脚本(连接时指定服务…

使用 Spring Boot 和 Spring Security 构建安全的 Web 应用:OAuth2、”记住我”与 JWT 集成指南

使用 Spring Boot 和 Spring Security 构建安全的 Web 应用:OAuth2、记住我与 JWT 集成指南 在现代 Web 应用中,安全性是至关重要的。Spring Security 是一个功能强大且高度可定制的安全框架,能够帮助我们轻松实现认证、授权以及其他安全功能…

【面试】Zookeeper

Zookeeper 1、ZooKeeper 介绍2、znode 节点里面的存储3、znode 节点上监听机制4、ZooKeeper 集群部署5、ZooKeeper 选举机制6、何为集群脑裂7、如何保证数据一致性8、讲一下 zk 分布式锁实现原理吧9、Eureka 与 Zk 有什么区别 1、ZooKeeper 介绍 ZooKeeper 的核心特性 高可用…

【贪心算法2】

力扣122.买卖股票最佳时机Ⅱ 链接: link 思路 要求最大利润,可以分解成子问题求解,在最低价格买入,最高价格卖出。 假如第0天价格最低,第3天价格最高,利润prices[3] - pricnes[0], 可以将利润公式拆解成 (prices[3]…

AI 智能:开拓未知疆域的科技先锋

在当今科技迅猛发展的浪潮中,AI 智能无疑是最耀眼的弄潮儿,持续重塑着我们生活与工作的方方面面。然而,在这片广袤的技术海洋里,还有诸多潜藏在深处、尚未被广泛挖掘与讨论的领域,它们代表着 AI 智能未来发展的新方向&…