杂谈 - 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
相关推荐
鸥梨菌Honevid4 分钟前
UVM 中 REQ 和 RSP 类型详解:从通信模型到 item_done 与 put_response
java·前端·servlet
瑞克-桑切斯13 分钟前
真实企业场景 运维安全与管理
java·网络·github
老板一杯拿铁36 分钟前
Java 八股文面试详解:从基础到进阶的全面梳理
java·面试
const_qiu37 分钟前
第 2.5 章 2.5.4-2.5.5:JWT 双 Token 与声明式权限守卫
java·人工智能
bug菌38 分钟前
一个周末就想把短链服务推到 10 万 QPS,真能靠加 Redis 做到吗?
java·redis·go
撸串-研究生39 分钟前
springboot福利院管理系统73979
java·spring boot·后端·福利院管理系统
不得了zz2 小时前
04-Spring AI Alibaba ReactAgent 生产级实践:工具调用、结构化输出、HITL 与上下文管理
java·ai编程·springaialibaba
猿究院_夏燊2 小时前
SpringMVC 到底是怎么干活的?
java·网络·职场和发展
鶴哥只手遮天2 小时前
Spring Framework 7.0.9 深度剖析-05-配置元数据解析:XML、注解与 JavaConfig
java·后端·开源
NGINX开源社区2 小时前
与我们交流:NGINX Gateway Fabric 与 NGINX Ingress Controller 社区会议
java·服务器·前端