Elasticsearch 7.9.2启动报错及解决方案

本文主要介绍了Elasticsearch在Linux(CentOS)系统中的常见问题及解决方法。包括不能以root用户启动、文件描述符和虚拟内存区域限制、默认发现设置不适用于生产环境、连接不上虚拟机里的Elasticsearch以及Elasticsearch - head连接不上等问题,并给出了相应的配置修改方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、can not run elasticsearch as root

elasticsearch不允许以root用户启动需要使用其他用户才行

root用户无法启动官方说明:

https://www.elastic.co/guide/en/elasticsearch/reference/7.9/modules-scripting-security.html#_do_not_run_as_root

配置elasticsearch启动用户

Elasticsearch为了安全考虑不允许使用root用户启动Elasticsearch,所以我们需要新建一个普通用户启动程序。新建的用户名和密码都是elastic。

[root@localhost elasticsearch-7.9.2]# adduser elastic
[root@localhost elasticsearch-7.9.2]# passwd elastic
更改用户 elastic 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。

使用passwd elastic 命令给elastic用户设置密码(需要输入两遍密码)时,如果密码过于简单会有提示,用 root 用户操作可忽略提示,继续输入第二遍密码强制设置密码。

将elasticsearch目录权限赋予elastic用户,并用elastic用户启动elasticsearch,启动参数后面-d表示后台启动。

[root@localhost elasticsearch-7.9.2]# chown -R elastic /usr/local/elasticsearch-7.9.2/
[root@localhost elasticsearch-7.9.2]# su elastic
[elastic@localhost elasticsearch-7.9.2]$ ./bin/elasticsearch -d

 2、max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]

1、修改limits.conf文件

[root@localhost elasticsearch-7.9.2]# vim /etc/security/limits.conf

2、在limits.conf文件末尾添加

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

修改配置后,断开连接,否则配置无效

3、max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

1、修改sysctl.conf文件

[root@localhost elasticsearch-7.9.2]# vim /etc/sysctl.conf

2、在sysctl.conf文件后面添加

vm.max_map_count=655360

3、刷新配置文件使之生效 

[root@localhost elasticsearch-7.9.2]# sysctl -p
vm.max_map_count = 655360

系统参数官方文档地址:

https://www.elastic.co/guide/en/elasticsearch/reference/current/system-config.html

 

4、the default discovery settings are unsuitable for production use; at least one of

修改elasticsearch配置文件

[elastic@localhost elasticsearch-7.9.2]$ vi /usr/local/elasticsearch-7.9.2/config/elasticsearch.yml 

修改node.name和 cluster.initial_master_nodes

node.name: node-1
cluster.initial_master_nodes: ["node-1"]

5、连接不上虚拟机里面的elasticsearch

修改elasticsearch配置文件

[elastic@localhost elasticsearch-7.9.2]$ vi /usr/local/elasticsearch-7.9.2/config/elasticsearch.yml 

将elasticsearch.yml 文件中network.host修改成如下配置

network.host: 0.0.0.0 # 绑定到0.0.0.0,允许任何ip来访问

关闭防火墙

systemctl stop firewalld.service

6、elasticsearch-head连接不上elasticsearch

确保上面第5步已经执行完成

修改elasticsearch配置文件

[elastic@localhost elasticsearch-7.9.2]$ vi /usr/local/elasticsearch-7.9.2/config/elasticsearch.yml 

在elasticsearch.yml 文件末尾增加以下内容

http.cors.enabled: true 
http.cors.allow-origin: "*"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值