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

2023年 9月 7日 46.7k 0

前言

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

安装

安装 ElasticSearch:

  • wget artifacts.elastic.co/downloads/e…
  •  sha1sum elasticsearch-7.2.2.tar.gz
  •  tar -xzf elasticsearch-7.2.2.tar.gz
  •  cd elasticsearch-7.2.2/

后台启动es

  •  ./bin/elasticsearch -d

kibana安装

  •  官网下载压缩包之后,解压即可,地址:artifacts.elastic.co/downloads/k…

重启kibana

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

x-pack安装

  • 官网下载x-pack-5.2.2.zip
  • 安装到es:./bin/elasticsearch-plugin install file:///home/es/x-pack-5.2.2.zip 【每个节点都需要安装】
  • 安装到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

    安装问题

  • 启动异常:max number of threads [1024] for user [es] is too low, increase to at least [2048]
  • 解决:

    cat  /etc/security/limits.d/90-nproc.conf
     *          soft    nproc     4096
     root       soft    nproc     unlimited
     EOF
    

     soft nproc 默认配置为1024

  • 启动异常: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 【临时修改】

     或者永久修改:

  •   echo 'vm.max_map_count=655360' >> /etc/sysctl.conf
  •   sysctl -p 使之生效
  •  查看修改结果:

    [root@localhost ~]# sysctl -a|grep vm.max_map_count
    
     vm.max_map_count = 262144
    

     虚拟内存块介绍:

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

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

  • 异常:max file descriptors [1024] for elasticsearch process likely too low, increase to at least [65536]
  • 解决:

    cat  /etc/security/limits.conf
     * soft nofile 655360
     * hard nofile 655360
     * soft memlock unlimited
     * hard memlock unlimited
     EOF
    
  • 异常: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

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

    解决:

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

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

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

  • 修改线程池的队列大小和核心线程数量
    • 查看各线程池的状态: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

    相关文章

    JavaScript2024新功能:Object.groupBy、正则表达式v标志
    PHP trim 函数对多字节字符的使用和限制
    新函数 json_validate() 、randomizer 类扩展…20 个PHP 8.3 新特性全面解析
    使用HTMX为WordPress增效:如何在不使用复杂框架的情况下增强平台功能
    为React 19做准备:WordPress 6.6用户指南
    如何删除WordPress中的所有评论

    发布评论