杂谈 - ElasticSearch安装,附带七个常见问题

前言

我们开发的时候,有时候需要自己安装elasticsearch作为开发环境,这时就不得不面对安装的一些小问题了。文章里列举了常见的几个问题,以及解决方案,希望对你有帮助。

安装

安装 ElasticSearch:

后台启动es

  • ./bin/elasticsearch -d

kibana安装

重启kibana

  • 使用 fuser -n tcp 5601,找到相应进程,kill
  • nohup ./bin/kibana &

x-pack安装

  1. 官网下载x-pack-5.2.2.zip
  2. 安装到es:./bin/elasticsearch-plugin install file:///home/es/x-pack-5.2.2.zip 【每个节点都需要安装】
  3. 安装到kibana:./bin/kibana-plugin install file:///home/es/x-pack-5.2.2.zip

JVM参数设置

在elasticsearch/config/jvm.options文件中设置最大堆内存

  • -Xms32600m
  • -Xmx32600m

ES 日志配置

elasticsearch/config/log4j2.properties加上慢查询日志记录:

  • index.search.slowlog.level: info
  • index.search.slowlog.threshold.query.warn: 10s
  • index.search.slowlog.threshold.query.info: 5s
  • index.search.slowlog.threshold.query.debug: 2s
  • index.search.slowlog.threshold.query.trace: 500ms
  • index.search.slowlog.threshold.fetch.warn: 1s
  • index.search.slowlog.threshold.fetch.info: 800ms
  • index.search.slowlog.threshold.fetch.debug:500ms
  • index.search.slowlog.threshold.fetch.trace: 200ms

安装问题

  1. 启动异常:max number of threads 1024 for user es is too low, increase to at least 2048

解决:

js 复制代码
cat << EOF > /etc/security/limits.d/90-nproc.conf
 *          soft    nproc     4096
 root       soft    nproc     unlimited
 EOF

soft nproc 默认配置为1024

  1. 启动异常:max virtual memory areas vm.max_map_count 65530 is too low, increase to at least 262144

解决:

[root@localhost ~]# sysctl -w vm.max_map_count=655360 【临时修改】

或者永久修改:

  1. echo 'vm.max_map_count=655360' >> /etc/sysctl.conf
  2. sysctl -p 使之生效

查看修改结果:

js 复制代码
[root@localhost ~]# sysctl -a|grep vm.max_map_count

 vm.max_map_count = 262144

虚拟内存块介绍:

进程内存管理的对象是进程线性地址空间上的内存镜像,这些内存镜像其实就是进程使用的虚拟内存区域(memory region)。进程虚拟空间是个32或64位的"平坦"(独立的连续区间)地址空间(空间的具体大小取决于体系结构)。要统一管理这么大的平坦空间可绝非易事,为了方便管理,虚拟空间被划分为许多大小可变的(但必须是4096的倍数)内存区域,这些区域在进程线性地址中像停车位一样有序排列。这些区域的划分原则是"将访问属性一致的地址空间存放在一起",所谓访问属性在这里无非指的是"可读、可写、可执行等"。

如果你要查看某个进程占用的内存区域,可以使用命令cat /proc//maps获得(pid是进程号)

  1. 异常:max file descriptors 1024 for elasticsearch process likely too low, increase to at least 65536

解决:

js 复制代码
cat << EOF > /etc/security/limits.conf
 * soft nofile 655360
 * hard nofile 655360
 * soft memlock unlimited
 * hard memlock unlimited
 EOF
  1. 异常:system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk

解决:

在elasticsearch.yml里添加配置:bootstrap.system_call_filter: false

  1. 启动告警:设置jvm锁住内存时启动警告

当设置bootstrap.mlockall: true时,启动es报警告Unknown mlockall error 0,因为linux系统默认能让进程锁住的内存为45k。

解决:

设置为无限制,linux命令:ulimit -l unlimited

  1. 异常:写入es时告警:No data nodes with HTTP-enabled available

分析:查看源码得知,在初始化写入实例时,默认会去寻找data node,但是我们集群部署时dn并没有开启http服务。找不到dn,校验通不过就会告警了。想绕过此校验,默认es.nodes.data.only是true,在客户端中将其设置为false即可。

解决:在客户端中es.nodes.data.only设置为false

  1. 修改线程池的队列大小和核心线程数量
  • 查看各线程池的状态:GET _cat/thread_pool?v&h=id,host,name,port,type,size,queue,queue_size,min,max,active,rejected,completed
  • 查看单个线程池的状态,比如search:GET _cat/thread_pool/search?v&h=id,host,name,port,type,size,queue,queue_size,min,max,active,rejected,completed

修复:

ES5.0以后不支持用接口动态修改此参数,需要在ES数据节点上,写入下面配置并重启

  • thread_pool.search.size: 50
  • thread_pool.search.queue_size: 5000
相关推荐
步行cgn17 分钟前
Spring MVC + Thymeleaf 模板解析失败:从 500 错误到页面正常显示
java·spring·mvc
lgcgkCQ1 小时前
【AI 转型实战 1】SpringAI 入门:搭建基础大模型对话能力
java·ai·agent·rag·spring ai·mcp·langchain4j
Wang's Blog1 小时前
Java 项目实战:交友项目 - 用户体系集成总结
java·开发语言·交友
学到老活到老1 小时前
第 24 集:配置文件写了 80,Spring Boot 为什么读到 90?
java·后端·spring
tongyiixiaohuang1 小时前
供应商主数据同步实战:从易快报到金蝶云星空的单一策略落地
java·网络·数据库
鱼宵2 小时前
取集合第一个元素,Java 为什么要写三种写法?
java·windows·python·java21
学长毕设2 小时前
基于SpringBoot的餐厅管理系统-附源码
java·spring boot·后端
刚入门的大一新生3 小时前
Linux-线程互斥
java·开发语言
Flynn Liang3 小时前
内存/Redis/PGVector/Milvus/ES 怎么选?Spring AI VectorStore 抽象与向量库选型对照表
redis·elasticsearch·milvus·rag·springai·pgvector·向量库
赵小哥要冲啦3 小时前
社区邻里互助小程序从 0 到 1 复盘:需求拆解与信任机制设计
java·小程序·需求分析