当前位置: 首页 > 编程文章 >

CentOS 7 安装 Elasticsearch 5.0.x 详细步骤与排错指南

CentOS 7 安装 Elasticsearch 5.0.x 详细步骤与排错指南

作者:林辰时间:2025-05-27 16:55:32浏览:347

本文介绍在 CentOS 7 虚拟机中安装 Elasticsearch 5.0.x 的完整流程。首先需预先安装 JDK,随后创建非 root 用户并下载解压软件包。重点讲解了如何修改 elasticsearch.yml 中的 network.host 和 http.port,以及处理启动时常见的 vm.max_map_count 限制、JVM 堆内存大小不匹配(heap size)以及文件描述符不足等报错问题,最终通过浏览器验证服务是否正常运行。

本文目录展开

CentOS 7 安装 Elasticsearch 5.0.x 详细步骤与排错指南

在 CentOS 7 虚拟机环境中部署 Elasticsearch 5.0.x 的安装过程详解。

请预先安装jdk详细步骤请参考:https://www.jb51.net/softjc/193398.html

出于安全考虑,必须创建一个非 root 用户来运行服务。

Elasticsearch 禁止以 root 权限启动,本例中创建名为 seven 的用户进行后续操作。


[root@localhost ~]# useradd seven
[root@localhost ~]# passwd seven

从官方渠道获取 Elasticsearch 安装包。


[root@localhost ~]# su seven
[seven@localhost root]$ cd /home/seven
[seven@localhost ~]$ mkdir download
[seven@localhost ~]$ cd download
[seven@localhost download]$ wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/5.0.0-alpha3/elasticsearch-5.0.0-alpha3.tar.gz

完成解压后,即可进入运行前的配置阶段。

使用 tar 命令解压下载的压缩包文件。


[seven@localhost download]$ tar -zxvf elasticsearch-5.0.0-alpha3.tar.gz

将解压后的目录移动至指定路径并重命名,以便于日常管理和维护。


[seven@localhost download]$ mv elasticsearch-5.0.0-alpha3 /usr/java/elasticsearch

需要调整配置文件,以便允许特定 IP 访问并设置监听端口。


[seven@localhost config]$ vim /usr/java/elasticsearch/config/elasticsearch.yml

编辑配置文件,找到 network.host 和 http.port 所在行,取消注释并根据需求修改 IP 地址及端口号。


# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 192.168.0.155
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, see the documentation at:
# 

切换到 bin 目录,直接执行 elasticsearch 脚本以尝试启动服务。


[seven@localhost bin]$ cd /usr/java/elasticsearch/bin/
[seven@localhost bin]$ ./elasticsearch

初次启动时可能会遇到报错导致进程退出。


[seven@localhost bin]$ ./elasticsearch
[2026-06-28 13:49:27,899][INFO ][node      ] [Mondo] version[5.0.0-alpha3], pid[3671], build[cad959b/2026-05-26T08:25:57.564Z], OS[Linux/3.10.0-327.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1 .0_91/25.91-b14]
▽2026-06-28 13:49:27,900][INFO ][node      ] [Mondo] initializing ...
[2026-06-28 13:49:28,941][INFO ][plugins     ] [Mondo] modules [percolator, lang-mustache, lang-painless, ingest-grok, reindex, lang-expression, lang-groovy], plugins []
[2026-06-28 13:49:28,963][INFO ][env      ] [Mondo] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [15.7gb], net total_space [17.4gb], spins? [unknown], types [rootfs]
[2026-06-28 13:49:28,963][INFO ][env      ] [Mondo] heap size [1.9gb], compressed ordinary object pointers [true]
[2026-06-28 13:49:31,980][INFO ][node      ] [Mondo] initialized
[2026-06-28 13:49:31,980][INFO ][node      ] [Mondo] starting ...
[2026-06-28 13:49:32,115][INFO ][transport    ] [Mondo] publish_address {192.168.0.155:9300}, bound_addresses {192.168.0.155:9300}
Exception in thread "main" java.lang.RuntimeException: bootstrap checks failed
initial heap size [268435456] not equal to maximum heap size [2147483648]; this can cause resize pauses and prevents mlockall from locking the entire heap
max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
please set [discovery.zen.minimum_master_nodes] to a majority of the number of master eligible nodes in your cluster
max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
  at org.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:125)
  at org.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:85)
  at org.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:65)
  at org.elasticsearch.bootstrap.Bootstrap$5.validateNodeBeforeAcceptingRequests(Bootstrap.java:183)
  at org.elasticsearch.node.Node.start(Node.java:337)
  at org.elasticsearch.bootstrap.Bootstrap.start(Bootstrap.java:198)
  at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:257)
  at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:96)
  at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:91)
  at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54)
  at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:91)
  at org.elasticsearch.cli.Command.main(Command.java:53)
  at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:70)
  at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:63)
Refer to the log for complete error details.
[2026-06-28 13:49:32,144][INFO ][node      ] [Mondo] stopping ...
[2026-06-28 13:49:32,198][INFO ][node      ] [Mondo] stopped
[2026-06-28 13:49:32,198][INFO ][node      ] [Mondo] closing ...
[2026-06-28 13:49:32,210][INFO ][node      ] [Mondo] closed

针对部分系统限制错误,临时提高 vm.max_map_count 的值是常见的解决手段。

注意,修改内核参数需要 root 用户的权限才能执行。


[root@localhost ~]# sysctl -w vm.max_map_count=262144

执行 sysctl 命令查看当前修改后的结果是否生效。


[root@localhost ~]# sysctl -a|grep vm.max_map_count
vm.max_map_count = 262144

若希望重启后依然有效,可进行永久性的系统配置修改。


[root@localhost ~]# cat /etc/sysctl.conf | grep -v "vm.max_map_count" > /tmp/system_sysctl.conf
[root@localhost ~]# echo "vm.max_map_count=262144" >> /tmp/system_sysctl.conf
[root@localhost ~]# mv /tmp/system_sysctl.conf /etc/sysctl.conf
mv:是否覆盖"/etc/sysctl.conf"? y
[root@localhost ~]# cat /etc/sysctl.conf
# System default settings live in /usr/lib/sysctl.d/00-system.conf.
# To override those settings, enter new settings here, or in an /etc/sysctl.d/.conf file
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
vm.max_map_count=262144
[root@localhost ~]# sysctl -p
vm.max_map_count = 262144

另一个常见错误涉及 JVM 内存分配,提示 heap size [268435456] 不等于最大堆大小 [2147483648],需调整 jvm.options 配置。


[seven@localhost bin]$ vim /usr/java/elasticsearch/config/jvm.options

将 -Xmx2g 修改为 -Xmx256m,使其数值与报错信息中的 heap size [268435456] 除以 1024/1024 后的值保持一致。

修正内存配置后,可能又会遇到新的启动障碍。


Exception in thread "main" java.lang.RuntimeException: bootstrap checks failed
initial heap size [268435456] not equal to maximum heap size [2147483648]; this can cause resize pauses and prevents mlockall from locking the entire heap
max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
memory locking requested for elasticsearch process but memory is not locked
  at org.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:125)
  at org.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:85)
  at org.elasticsearch.bootstrap.BootstrapCheck.check(BootstrapCheck.java:65)
  at org.elasticsearch.bootstrap.Bootstrap$5.validateNodeBeforeAcceptingRequests(Bootstrap.java:183)
  at org.elasticsearch.node.Node.start(Node.java:337)
  at org.elasticsearch.bootstrap.Bootstrap.start(Bootstrap.java:198)
  at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:257)
  at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:96)
  at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:91)
  at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54)
  at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:91)
  at org.elasticsearch.cli.Command.main(Command.java:53)
  at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:70)
  at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:63)
Refer to the log for complete error details.
[2026-06-28 14:55:49,770][INFO ][node      ] [Goldbug] stopping ...
[2026-06-28 14:55:49,875][INFO ][node      ] [Goldbug] stopped
[2026-06-28 14:55:49,875][INFO ][node      ] [Goldbug] closing ...
[2026-06-28 14:55:49,887][INFO ][node      ] [Goldbug] closed

此问题耗时较长,解决方案在于回到 config/elasticsearch.yml 文件,开放 discovery.zen.ping.unicast.hosts 及 discovery.zen.minimum_master_nodes 的配置项。


# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
discovery.zen.ping.unicast.hosts: ["192.168.0.155"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of nodes / 2 + 1):
#
discovery.zen.minimum_master_nodes: 3
#
# For more information, see the documentation at:
# 

同时需解决 max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536] 的错误提示,这同样需要切换到 root 账户操作。


[root@localhost ~]# cp /etc/security/limits.conf /etc/security/limits.conf.bak
[root@localhost ~]# cat /etc/security/limits.conf | grep -v "seven" > /tmp/system_limits.conf
[root@localhost ~]# echo "seven hard nofile 65536" >> /tmp/system_limits.conf 
[root@localhost ~]# echo "seven soft nofile 65536" >> /tmp/system_limits.conf 
[root@localhost ~]# mv /tmp/system_limits.conf /etc/security/limits.conf

修改系统限制后重新登录 seven 用户,并使用相应命令检查文件描述符限制是否已更新成功。


[seven@localhost ~]$ ulimit -Hn
65536

确认所有配置无误后再次启动 Elasticsearch,启动成功后使用浏览器访问 http://192.168.0.155:9200 验证服务状态。


{
 "name" : "Vampire by Night",
 "cluster_name" : "elasticsearch",
 "version" : {
 "number" : "5.0.0-alpha3",
 "build_hash" : "cad959b",
 "build_date" : "2026-05-26T08:25:57.564Z",
 "build_snapshot" : false,
 "lucene_version" : "6.0.0"
 },
 "tagline" : "You Know, for Search"
}

以上即为完整的安装与排错内容,希望对读者有所帮助,欢迎支持本站。

上一篇
CentOS克隆Linux虚拟机完整步骤:配置IP与主机名

本文介绍在CentOS系统中完成一台Linux虚拟机基础设置后,如何通过克隆方式快速创建多台新虚拟机。重点讲解克隆后的关键配置步骤,包括删除旧的网卡规则、修改网络配置文件中的MAC地址与IP、更新主机名以及重启验证,确保每台克隆机拥有独立的网络身份。

下一篇
CentOS设置程序开机自启动的三种方法

在CentOS系统中,可通过修改/etc/rc.d/rc.local、将脚本放入/etc/rc.d/init.d/并使用chkconfig管理,或编辑/etc/rc.d/rc.sysinit文件来实现程序开机自启动。其中chkconfig命令支持--add、--del等参数,用于检查、添加或删除系统服务及其在各运行级的状态。

相关文章

更多
CentOS 7 配置 NIS 集中管理账号的详细步骤

NIS(Network Information Service)用于在多台 Linux 服务器环境中集中管理系统账号信息,解决多主机账号管理混乱的问题。本文详细介绍在 CentOS 7 中部署 NIS 服务器的完整流程,包括关闭防火墙和 SELinux、安装 ypserv 包、配置域名称及权限、初始化数据库,以及客户端的 ypbind 配置与服务验证方法。

2026.11.05 667
CentOS 7 安装 Nginx 详细步骤

本文介绍在 CentOS 7 系统中安装 Nginx Web 服务器的完整流程。首先需通过 yum 安装 gcc-c++、pcre-devel、zlib-devel 和 openssl-devel 等编译依赖库。随后下载源码包,使用 ./configure、make 和 make install 命令进行编译安装,默认路径为 /usr/local/nginx。最后说明如何进入安装目录以启动或停止服务。

2025.05.08 496
CentOS 7 安装与卸载 Apache (httpd) 服务详细步骤

本文介绍在 CentOS 7 系统中对 Apache (httpd) 服务的卸载与安装流程。首先通过 rpm 或 yum 命令检查并停止服务,随后执行卸载操作;接着使用 yum install 重新安装 httpd,并通过 systemctl 管理启动状态,最后验证默认目录下的网页访问是否正常。

2025.09.25 976
CentOS 7.2 安装 Nginx 及 systemctl 服务管理指南

本文记录了在 CentOS 7.2 系统中通过 yum 安装 Nginx 的具体步骤。首先需添加官方资源库并配置 nginx.repo 文件,随后使用 yum install 完成安装。文章还详细说明了如何使用 nginx -t 测试配置文件语法,以及在 CentOS 7 环境下利用 systemctl 命令实现服务的启动、停止、重启、状态检查以及开机自启设置。

2025.11.18 972
Windows Server 2003 IIS中创建Web虚拟目录的详细步骤

在Windows Server 2003环境中,通过Internet信息服务(IIS)管理器创建Web虚拟目录可灵活扩展站点内容。该过程涉及打开IIS管理器、指定别名与物理路径、配置访问权限及完成向导五个关键步骤,支持跨分区或网络路径映射,最终通过URL别名即可访问目标资源。

2025.12.21 970
CentOS 7 增加 Swap 空间的操作指南

本文介绍在 CentOS 7 系统中通过创建 swap 文件来扩展虚拟内存的方法。内容涵盖 swap 的作用、大小选择策略、使用 fallocate 或 dd 命令创建文件、设置权限及启用 swap,以及如何配置 vm.swappiness 参数以优化系统性能。

2025.11.09 969

专题推荐

更多
PHP 类与对象定义及继承

先看类声明、对象实例与属性访问。理解对象的创建和销毁后,再读继承、方法重载和关键字对照。已有代码遇到继承行为差异时,可进一步查看 final 方法与反射实例。

PHP 定时任务配置与运行

先确定任务运行间隔以及是否允许重叠。固定时间触发先看 Cron 案例,框架内和常驻服务再读对应示例。

Yii2 队列配置与常驻运行

先用一个最小任务跑通入队和消费,再检查 Web 与 Console 是否加载了相同的队列配置。确认命令能手动运行后再配置 Supervisor,最后验证进程重启时的处理情况。

PHP Session 过期时间设置方法

浏览器关闭、服务端回收和业务规定的闲置超时,可能在不同时间发生。对照配置项与应用层时间戳的做法,检查会话何时仍可读、何时应要求重新登录。

PHP URL 编码和解码方法

URL 路径片段和查询参数对空格的处理方式不同。先比较 urlencode 与 rawurlencode,再沿解码过程核对中文、加号和百分号,检查地址是否被重复编码或提前解码。

在线工具箱

更多
键码查询
键码查询

按下键盘按键时查看浏览器记录的键名和事件信息。

.env 配置检查
.env 配置检查

本地检查 .env 键值语法、引号、重复键及空值,预览解析结果,辅助排查 PHP 和 Laravel 环境配置。

进制转换
进制转换

转换二进制、十进制、十六进制等数值表示,辅助程序调试与进制学习。

HTML 标签安全清理
HTML 标签安全清理

清理 HTML 片段中的标签或危险内容,辅助整理待展示的文本。

文件 Base64 转换
文件 Base64 转换

把文件转为 Base64 文本,也可将编码内容还原为文件,方便接口传输与调试。