centos7安装 ES集群 elasticsearch
创始人
2024-11-05 15:11:27
0

这里写自定义目录标题

  • 编写启动脚本 elasticsearch.sh
  • 启动可能报错:elasticsearch 7.10启动报错 bootstrap checks failed
        • 解决方法
        • 问题原因:
        • 注意 退出xshell,重新登录: 上面两个配置项改完后,ES启动用户(es 或root) **重新登录**就会生效;

编写启动脚本 elasticsearch.sh

  • 懒人编写一个用于启动、停止和重启Elasticsearch服务的shell脚本
  • 脚本中设置环境变量,并使用su - es - c命令在es用户下执行操作
  • 通过赋予脚本执行权限,用户可以方便地对Elasticsearch进行控制
#!/bin/sh   export JAVA_HOME=/opt/software/java11/jdk-11.0.11 export PATH=$JAVA_HOME/bin:$PATH export ES_HOME=/opt/software/elasticsearch/elasticsearch-7.6.1 export PATH=$ES_HOME/bin:$PATH  if [ $# -lt 1 ] then 	echo "No Args Input..." 	exit ; fi     case $1 in     start)         su - es -c "$ES_HOME/bin/elasticsearch -d -p pid"         echo "elasticsearch is started"         ;;     stop)         pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`         kill -9 $pid         echo "elasticsearch is stopped"         ;;     restart)         pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`         kill -9 $pid         echo "elasticsearch is stopped"         sleep 1         su - es -c "$ES_HOME/bin/elasticsearch -d -p pid"         echo "elasticsearch is started"         ;;     *)         echo "start|stop|restart"         ;; esac exit 0 

赋予执行权限:

chmod +x elasticsearch.sh 

参数说明:

su - es -c “命令”, 这个表示脚本内切换es用户一次并执行 -c 后面的命令,然后退出es普通用户到当前用户。

启动可能报错:elasticsearch 7.10启动报错 bootstrap checks failed

elasticsearch 7.14启动报错 bootstrap checks failed
现象一
ES使用root用户安装报错如下

Caused by: java.lang.RuntimeException: can not run elasticsearch as root  [root@localhost elasticsearch-7.14.2]# ./bin/elasticsearch [2022-09-18T16:40:41,166][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [localhost.localdomain] 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.14.2.jar:7.14.2]         at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.14.2.jar:7.14.2]         at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:75) ~[elasticsearch-7.14.2.jar:7.14.2]         at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:116) ~[elasticsearch-cli-7.14.2.jar:7.14.2]         at org.elasticsearch.cli.Command.main(Command.java:79) ~[elasticsearch-cli-7.14.2.jar:7.14.2]         at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.14.2.jar:7.14.2]         at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:81) ~[elasticsearch-7.14.2.jar:7.14.2] Caused by: java.lang.RuntimeException: can not run elasticsearch as root         at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103) ~[elasticsearch-7.14.2.jar:7.14.2]         at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170) ~[elasticsearch-7.14.2.jar:7.14.2]         at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:399) ~[elasticsearch-7.14.2.jar:7.14.2]         at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.14.2.jar:7.14.2]         ... 6 more uncaught exception in thread [main] java.lang.RuntimeException: can not run elasticsearch as root         at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103)         at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170)         at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:399)         at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159)         at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150)         at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:75)         at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:116)         at org.elasticsearch.cli.Command.main(Command.java:79)         at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115)         at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:81) For complete error details, refer to the log at /opt/ES/elasticsearch-7.14.2/logs/elasticsearch.log 
解决方法

ES官方为了安全起见,禁止启用Root启动ES服务,因此我们需要进行普通用户的创建,才能正常启动ES服务。所以我们需要新建一个普通用户,并将ES安装目录授权给刚新建的用户。

[root@localhost ES]# useradd es

错误信息:

ERROR: [1] bootstrap checks failed [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535] [2]: max number of threads [3795] for user [es] is too low, increase to at least [4096] [3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] 
问题原因:

es高版本对资源要求较高,linux系统默认配置不能满足它的要求,所以需要单独配置

解决方法:

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

修改vi /etc/security/limits.conf 文件,加入配置

* hard nofile 65535  # *可以是es启动用户 * soft nofile 65535 

可以指定用户
在这里插入图片描述

[2]: max number of threads [3795] for user [es] is too low, increase to at least [4096] 

修改vi /etc/security/limits.conf 文件,加入配置

es - nproc 4096   # es是我的启动用户 
注意 退出xshell,重新登录: 上面两个配置项改完后,ES启动用户(es 或root) 重新登录就会生效;
[3]:max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] 

修改/etc/sysctl.config文件,加入下面配置

vi /etc/sysctl.conf

vm.max_map_count=262144 

执行命令,立即生效

/sbin/sysctl -p vm.max_map_count = 262144 

启动成功

相关内容

热门资讯

传递经验!wepoke软件透明... 传递经验!wepoke软件透明挂测试,太坑了原来是有挂(2024已更新)(哔哩哔哩);最新版2026...
黑科技辅助(wpk德州)外挂软... 黑科技辅助(wpk德州)外挂软件透明挂智能ai代打辅助器(透视)AA德州教程(2021已更新)(哔哩...
第一分钟了解!四川微乐自建房辅... 第一分钟了解!四川微乐自建房辅助器插件开挂,欢乐情怀辅助挂软件透视挂(最新版本2026)暗藏猫腻,小...
三分钟透视挂!皇豪互众插件,人... 三分钟透视挂!皇豪互众插件,人海大厅辅助插件(微信链接炸金花辅助开挂方法)1、每一步都需要思考,不同...
必备攻略“wpk辅助ios版”... 必备攻略“wpk辅助ios版”(透视)详细开挂辅助技巧通过上述步骤和技巧,相信大家都能顺利下载安装并...
今日头条!wpk脚本,太坑了原... 今日头条!wpk脚本,太坑了原生存在有挂(2023已更新)(哔哩哔哩);一、wpk脚本AI软件牌型概...
黑科技辅助(wpk俱乐部)外挂... 黑科技辅助(wpk俱乐部)外挂软件透明挂智能ai辅助安装插件(透视)靠谱教程(2026已更新)(哔哩...
五分钟了解!决战geo辅助插件... 五分钟了解!决战geo辅助插件开挂,潘潘讲故事app有挂吗软件透视挂(最新版本2026)1、潘潘讲故...
总算清楚“HHpoker开挂辅... 总算清楚“HHpoker开挂辅助”(透视)详细开挂辅助教程在使用时,启用透视功能通常需要进行一些设置...
第五分钟透视挂!火神大厅辅助,... 第五分钟透视挂!火神大厅辅助,新二号辅助软件怎么下载(微信链接炸金花辅助开挂app)小薇(透视辅助)...