centos7安装 ES集群 elasticsearch

这里写自定义目录标题

  • [编写启动脚本 elasticsearch.sh](#编写启动脚本 elasticsearch.sh)
  • [启动可能报错:elasticsearch 7.10启动报错 bootstrap checks failed](#启动可能报错:elasticsearch 7.10启动报错 bootstrap checks failed)
        • 解决方法
        • 问题原因:
        • [注意 退出xshell,重新登录: 上面两个配置项改完后,ES启动用户(es 或root) **重新登录**就会生效;](#注意 退出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 文件,加入配置 ```bash * hard nofile 65535 # *可以是es启动用户 * soft nofile 65535 ``` 可以指定用户 ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/22790c57bdc64b4e9964bb90871f8f89.png) [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 启动成功 ## 其他报错: nested: BindException[地址已在使用]; Likely root cause: java.net.BindException: 地址已在使用 at java.base/sun.nio.ch.Net.bind0(Native Method) at java.base/sun.nio.ch.Net.bind(Net.java:555) at java.base/sun.nio.ch.ServerSocketChannelImpl.netBind(ServerSocketChannelImpl.java:337) at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:294) at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:134) at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:550) at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1334) at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:506) at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:491) at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:973) at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:248) at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:356) at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164) at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500) at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at java.base/java.lang.Thread.run(Thread.java:833) For complete error details, refer to the log at /data/db/elastic/node-1/logs/ltkj-search.log ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/6ead7f5656fd4690b268b95ef65f5c72.png) 报错解释: 这个错误表明应用程序尝试绑定到本地计算机上的19700端口失败,因为该端口已经被其他应用程序占用。 解决方法: 1. 查找并停止占用端口的进程: * 在Windows上,可以使用命令netstat -ano \| findstr :19700来查找占用端口的进程ID,然后通过任务管理器或taskkill /PID \<进程ID\> /F命令结束该进程。 * 在Linux或Mac上,可以使用lsof -i :19700或netstat -tulnp \| grep :19700来查找占用端口的进程,并使用kill命令结束它。 2. 更改应用程序配置: 如果可能,更改应用程序自身配置,使其使用不同的端口。 3. 端口冲突处理: 如果应用程序可以配置端口,可以设置为自动选择未被使用的端口。 确保在进行任何更改之前,了解正在运行的服务及其端口的用途,以免影响系统的正常运行。

相关推荐
AEMC马广川15 分钟前
关于综合能源服务认证证书的全解析专业认证团队
java·大数据·服务器·能源
黄雪超1 小时前
Flink介绍——实时计算核心论文之MillWheel论文总结
大数据·flink·论文笔记
lilye662 小时前
精益数据分析(10/126):深度剖析数据指标,驱动创业决策
大数据·人工智能·数据分析
Acrelgq234 小时前
工厂能耗系统智能化解决方案 —— 安科瑞企业能源管控平台
大数据·人工智能·物联网
D愿你归来仍是少年6 小时前
使用 PySpark 批量清理 Hive 表历史分区
大数据·数据仓库·hive·spark
End9287 小时前
Hadoop的三大结构及其作用?
大数据·hadoop·分布式
chat2tomorrow9 小时前
数据仓库 vs 数据湖:架构、应用场景与技术差异全解析
大数据·数据仓库·低代码·架构·数据湖·sql2api
塔能物联运维9 小时前
双轮驱动能源革命:能源互联网与分布式能源赋能工厂能效跃迁
大数据·运维
-曾牛10 小时前
Git Flow
大数据·git·学习·elasticsearch·个人开发
461K.10 小时前
spark与hadoop的区别
大数据·运维·hadoop·分布式·spark·intellij-idea