二、Elasticsearch安装及配置-Set up Elasticsearch

一、概述

本篇参考链接:
https://www.elastic.co/guide/en/elasticsearch/reference/current/setup.html
es各个版本所支持的操作系统清单见下面链接:
https://www.elastic.co/cn/support/matrix
这里不做安装的介绍,涉及如下内容

  • 配置ES

二、Configuring Elasticsearch 配置ES

官方说默认配置已经优化的不错了,稍微改点儿就得了,而且大部分的配置可以通过
Cluster Update Settings API进行修改
ES有三个配置文件:

  • elasticsearch.yml es基础配置
  • jvm.options jvm配置
  • log4j2.properties 日志配置
    默认的配置文件路径在$ES_HOME/config,也可以通过修改ES_PATH_CONF环境变量来执行配置文件的路径,例:export ES_PATH_CONF=/path/to/my/config. ./bin/elasticsearch
    配置文件采用YAML的格式

1、各种配置:

后续用到了再详细看吧

  • 1、Setting JVM options
    官网讲,一般不用你配置,一般要调整的是heap size,堆的大小
    有几个约定的东西:
#表示JDK8启用
8:-Xmx2g
#表示JDK版本大于8启用
8-:-Xmx2g
#表示JDK版本大于介于8和9之间启用
8-9:-Xmx2g

另一种指定JVM参数的方式是添加环境变量 ES_JAVA_OPTS,例子:

export ES_JAVA_OPTS="$ES_JAVA_OPTS -Djava.io.tmpdir=/path/to/temp/dir"
./bin/elasticsearch
  • 2、Secure settings
    有一些敏感的配置不行暴露,可以用elasticsearch-keystore进行管理
  • 3、Logging configuration
  • 4、Auditing settings
  • 5、Cross-cluster replication settings
  • 6、Index lifecycle management settings
  • 7、License settings
  • 8、Machine learning settings
  • 9、Monitoring settings
  • 10、Monitoring settings
  • 11、Security settings
  • 12、SQL access settings
  • 13、Watcher settings

三、Important Elasticsearch configuration 重要配置

在上生产之前,下面几个配置是需要考虑的:

1、Path settings 路径配置

path.data 和 path.log是必须配置的,而且可以配置多个路径,以path.data为例

path:
  data:
    - /mnt/elasticsearch_1
    - /mnt/elasticsearch_2
    - /mnt/elasticsearch_3

2、cluster.name 集群名称

默认为elasticsearch,用于集群的管理

3、network.host 节点的IP

用于其他节点发现或者连接

4、Discovery and cluster formation settings 集群发现配置

下面两个配置主要用于集群见发现及master的选举

  • discovery.seed_hosts
    默认配置下,会从本机找本机9300 ~ 9305端口的es实例,但是生产上一般是不同的host,这个时候就需要手工指定集群中所有可能成为master的节点,格式为host1:port1,host2:port2(逗号分隔),也可以不写port,这时候会使用transport.profiles.default.port,如果这个也没有,那么会使用默认的transport.port,如果使用IPV6,则需要用括号包起来
  • cluster.initial_master_nodes
    生产模式下,第一次启动的时候要指定可能成为master的node
    例子:
discovery.seed_hosts:
   - 192.168.1.10:9300
   - 192.168.1.11 
   - seeds.mydomain.com 
cluster.initial_master_nodes: 
   - master-node-a
   - master-node-b
   - master-node-c

这个配置在搭建集群的时候详细讲解,这里不过多深入

5、Setting the heap size 设置堆内存大小

  • Xmx 和 Xms设置成物理内存的一半(50%),因为ES还会使用额外的内存做一些操作,会利用操作系统的缓存来优化文件的读取,降低网络的开销,这些都会耗费额外的内存
  • 大小不要超过JVM的瓶颈(大约32GB)
  • 不要超过zero-based compressed oops的大小
    可以设置-XX:+UnlockDiagnosticVMOptions -XX:+PrintCompressedOopsMode来观察zero-based compressed oops的大小,通常26GB是最佳选择,原则上最大不超过30GB,CompressedOopsMode至少需要4G内存,所以,如果分配给ES的内存小于4GB,是不会启用Oops的

6、JVM heap dump path

可以在 jvm.options 中通过 -XX:HeapDumpPath=xxxxx来指定

7、GC logging

ES默认打开GC logging,每个日志文件64MB,最多2GB,超过2GB,覆盖原有日志

8、Temp directory

es启动的时候会在系统的临时目录下建立es专用的临时目录,但是有些linux发行版本会定时清理,这个不是我们想看到的,所以最好指定一个es的专用临时目录,可以通过 $es_tmpdir 环境变量来指定,并且设置只有启动es的用户可以访问。

9、JVM fatal error logs

JVM致命错误日志,可以通过修改 jvm.options中的-XX:ErrorFile=xxxx来指定

四、Important System Configuration 重要的系统设置

1、Configuring system settings 系统设置

  • ulimit设置
    设置linux允许打开的文件个数的限制 ulimit -n 65535
    永久修改:/etc/security/limits.conf 增加:elasticsearch - nofile 65535
    elasticsearch 为启动es的用户

2、Disable swapping 禁用swapping

这个东西会增加JVM进行GC的持续时间,机器反应慢,甚至宕机
禁用swap的几种方式

  • Disable all swap files
    临时设置:sudo swapoff -a
    永久设置:修改 /etc/fstab ,将所有含有 swap 的行注释掉
  • Configure swappiness
    将 vm.swappiness 设置为 1
  • Enable bootstrap.memory_lock 锁定es使用的内存不被swap
    在config/elasticsearch.yml中新增一行:bootstrap.memory_lock: true
    切记这个锁住的内存不能大于JVM的能力,否则会启动失败
    启动后可以用下面的命令查询状态
GET _nodes?filter_path=**.mlockall

3、File descriptors 设置

修改/etc/security/limits.conf,增加ulimit -n 65535或者将nofile 设置为65535
可以通过下面的命令查看设置

GET _nodes/stats/process?filter_path=**.max_file_descriptors

4、Virtual memory 虚拟内存设置

es默认使用mmapfs路径存储索引,系统中mmap的设置太低,需要加大

  • 临时设置:sysctl -w vm.max_map_count=262144
  • 永久设置:修改/etc/sysctl.conf,修改 vm.max_map_count

5、Number of threads 线程数量设置

修改/etc/security/limits.conf,将nproc设置为4096 (这个值是es推荐的)

6、DNS cache settings

7、JNA temporary directory not mounted with noexec

五、Bootstrap Checks 启动前的检查

一旦设置了transport.host(不是localhost或者127.0.0.1),es认为你启用了生产模式,生产模式就会启用Bootstrap Checks,如果不符合,则拒绝启动

  • Single-node discovery
    将 discovery.type 修改为 single-node即可,这种情况下,不会进行检查
  • Force the bootstrap checks 强制检查
    如果设置了single-node discovery,但是又想检查,可以设置给ES_JAVA_OPTS环境变量增加一条:-Des.enforce.bootstrap.checks=true

1、heap size check

会检查 -Xms与-Xmx是否一致,不一致巴拉巴拉会产生一堆问题等等

2、File descriptors check

3、Memory lock check

在做Full GC的时候,JVM会检查所有的heap,如果这些heap的一部分被swap出去,则需要在GC的时候先swap回来,这样会增加系统间的文件传输的开销,所以会检查bootstrap.memory_lock

4、Maximum number of theads check

5、Max file size check

6、Maximum size virtual memory check

7、Maximum map count check

8、Client JVM check

9、Use serial collector check

杜绝使用 serial collector,使用CMS,并发垃圾回收机制

10、System call filter check

11、OnError and OnOutOfMemoryError checks

12、Early-access check

13、G1GC check

14、All permission check

15、Discovery configuration check

你可能感兴趣的:(二、Elasticsearch安装及配置-Set up Elasticsearch)