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. 端口冲突处理: 如果应用程序可以配置端口,可以设置为自动选择未被使用的端口。 确保在进行任何更改之前,了解正在运行的服务及其端口的用途,以免影响系统的正常运行。

相关推荐
武子康1 天前
大数据-237 离线数仓 - Hive 广告业务实战:ODS→DWD 事件解析、广告明细与转化分析落地
大数据·后端·apache hive
大大大大晴天1 天前
Flink生产问题排障-Kryo serializer scala extensions are not available
大数据·flink
Elasticsearch2 天前
如何使用 Agent Builder 排查 Kubernetes Pod 重启和 OOMKilled 事件
elasticsearch
Elasticsearch3 天前
通用表达式语言 ( CEL ): CEL 输入如何改进 Elastic Agent 集成中的数据收集
elasticsearch
武子康3 天前
大数据-236 离线数仓 - 会员指标验证、DataX 导出与广告业务 ODS/DWD/ADS 全流程
大数据·后端·apache hive
武子康4 天前
大数据-235 离线数仓 - 实战:Flume+HDFS+Hive 搭建 ODS/DWD/DWS/ADS 会员分析链路
大数据·后端·apache hive
DianSan_ERP5 天前
电商API接口全链路监控:构建坚不可摧的线上运维防线
大数据·运维·网络·人工智能·git·servlet
够快云库5 天前
能源行业非结构化数据治理实战:从数据沼泽到智能资产
大数据·人工智能·机器学习·企业文件安全
AI周红伟5 天前
周红伟:智能体全栈构建实操:OpenClaw部署+Agent Skills+Seedance+RAG从入门到实战
大数据·人工智能·大模型·智能体
B站计算机毕业设计超人5 天前
计算机毕业设计Django+Vue.js高考推荐系统 高考可视化 大数据毕业设计(源码+LW文档+PPT+详细讲解)
大数据·vue.js·hadoop·django·毕业设计·课程设计·推荐算法