杂谈 - 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
相关推荐
懂得节能嘛.3 分钟前
【动态配置中心】Java+Redis构建动态配置中心
java·开发语言·redis
专注于大数据技术栈4 分钟前
Java中JDK、JRE、JVM概念
java·开发语言·jvm
YuanlongWang7 分钟前
C# 基础——值类型与引用类型的本质区别
java·jvm·c#
Kay_Liang32 分钟前
大语言模型如何精准调用函数—— Function Calling 系统笔记
java·大数据·spring boot·笔记·ai·langchain·tools
自由的疯1 小时前
Java 如何学习Docker
java·后端·架构
自由的疯1 小时前
Java Docker本地部署
java·后端·架构
007php0071 小时前
猿辅导Java面试真实经历与深度总结(二)
java·开发语言·python·计算机网络·面试·职场和发展·golang
摇滚侠1 小时前
Spring Boot 3零基础教程,WEB 开发 内容协商机制 笔记34
java·spring boot·笔记·缓存
一勺菠萝丶1 小时前
在 macOS 上用 Docker 为 Java 后端 & 常见开发需求搭建完整服务(详尽教程)
java·macos·docker
顾漂亮1 小时前
JVM底层攻坚
java·jvm·spring