杂谈 - 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
相关推荐
xierui1231233 分钟前
AI Agent 隐私架构:本地化重点为什么是登录态与执行权限
java·人工智能·网络安全·架构
cfm_291414 分钟前
Spring AI Tool 调用架构全解
java·人工智能·spring
sun༒25 分钟前
Spring @Scheduled 定时任务详解:Cron表达式、执行顺序、优先级与并行调度
java·后端·spring
一次旅行35 分钟前
DeepSeek‑V4‑Flash‑Vision‑Exp 小白入门实战|3种传图方式、完整可跑代码、避坑排障
java·前端·人工智能
野生技术架构师1 小时前
Spring Boot 实现数据脱敏:自定义注解 + Jackson 序列化器
java·spring boot·后端
AI人工智能+电脑小能手1 小时前
大白话说Java设计模式-28-模板方法模式(业务实战篇)
java·设计模式·模板方法模式·spring源码·订单系统·代码复用
奥莱维1 小时前
KNX酒店方案_KNX专用线与高端酒店技术逻辑
java·服务器·前端·数据库
工业一体机老司机1 小时前
Linux工业一体机自启动服务配置:systemd服务单元编写与开机优化实战
java·linux·服务器
weixin_538601972 小时前
智能体测开Day56
java
杨丰玮4182 小时前
从零手写Java飞机躲障碍游戏|Swing绘图、鼠标跟随、计时器碰撞检测实战(五)
java·python·游戏·游戏引擎·图形渲染·动画·贴图