Elasticsearch 7.* 常见错误以及解决方案

Elasticsearch 7.* 常见错误以及解决方案,第1张

Elasticsearch 7.* 常见错误以及解决方案

下载官网:
https://www.elastic.co/cn/downloads/elasticsearch

文章目录
    • 异常1
        • 异常
        • 解决
    • 异常2
        • 问题
        • 原因
        • 解决方案

异常1 异常

启动 bin 目录下的 elasticsearch 报错(这是ES的一种安全措施,不让用root用户

[root@localhost bin]# ./elasticsearch

future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/java/jdk1.8.0_201/jre] does not meet this requirement
[WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [node-1] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:163) ~[elasticsearch-7.2.0.jar:7.2.0]
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.2.0.jar:7.2.0]
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.2.0.jar:7.2.0]
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-7.2.0.jar:7.2.0]
        at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.2.0.jar:7.2.0]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.2.0.jar:7.2.0]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.2.0.jar:7.2.0]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105) ~[elasticsearch-7.2.0.jar:7.2.0]
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:172) ~[elasticsearch-7.2.0.jar:7.2.0]
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349) ~[elasticsearch-7.2.0.jar:7.2.0]
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.2.0.jar:7.2.0]

解决

创建非root用户

创建一个 javapub 用户并设置初始密码
useradd -c 'this is javapub user' -d /home/javapub evapub 
passwd javapub 

将 elasticsearch 安装目录属主权限改为 javapub 用户
chown -R javapub 

切换用户到 javapub 
su javapub 

使用 javapub 用户重启 elasticsearch


异常2 问题
max file descriptors [4096] for elasticsearch process is too low,

increase to at least [65536]
原因

每个进程最大同时打开文件数默认值太小, 查看当前系统同时打开进程数的默认值:

ulimit -Hn
ulimit -Sn
解决方案

切换到 root 账户,修改 /etc/security/limits.conf 文件 增加配置,用户退出后重新登录生效 su root 输入密码
vi /etc/security/limits.conf 在文件最后,增加如下配置:

#                 
#

#*               soft    core            0
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#@student        -       maxlogins       4
javapub        hard    nofile   65536
javapub        soft    nofile   65536
javapub        soft    nproc    4096
javapub        hard    nproc    4096

# End of file

第一列表示用户和组(@开头) * 号表示全部用户。第二列表示软限制还是硬限制,第三列表示限制的资源类型,第四列表示限制的最大值

hard和soft的区别: soft是一个警告值,而hard则是一个真正意义的阀值,超过就会报错,一般情况下都是设为同一个值。

core是内核文件,nofile是文件描述符,noproc是进程,一般情况下只限制文件描述符数和进程数就够了

一下具体介绍

-----------分割线,上面是配置文件的模板,下面是自己添加的------------------------

* 			    soft 	nofile         655350      #表示任何一个用户可以打开的最大的文件描述符数量
*	 		    hard    nofile         655350

* 			    soft    nproc          655350      #表示任何一个用户可以打开的最大的进程数
*		        hard    nproc          655350


@student        hard    nofile          65535       #student组中的任何人最多能打开文件描述符数量是65535,并且会在打开65000个时发出警告
@student        soft    nofile          65000

@student        hard    nproc           50	        #student组中的任何人不能拥有超过50个进程,并且会在拥有30个进程时发出警告
@student        soft    nproc           30
```


欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/zaji/5654642.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存