小白学ES 03 - ES主要配置文件详解(以5.6.10版本为例)

1 elasticsearch.yml(ES服务配置)

文件位置: ${ELASTIC_SEARCH_HOME}/config/elasticsearch.yml

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#

1.1 Cluster集群配置

# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
# ES集群的名称, ES中各节点通过此项配置来自动地加入同名称的集群, 默认是"elasticsearch"
cluster.name: HealGou-ES-Cluster
#

1.2 Node节点配置

# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
# 本ES节点的名称, 同一集群中各个node的名称不允许重复. 不配置则系统默认分配. 
node.name: node-1
#
# Add custom attributes to the node:
# 指定节点的部落属性 --- 一个比集群更大的范围, 即定义一些通用属性, 用于集群分配碎片时的过滤. 
#node.attr.rack: r1
# 
# 指定本节点是否有资格被选举为主节点, 默认是true. 
# ES集群中第一台机器被默认为master, 若此节点挂掉, 将重新选举master. 
# node.master=true
# 
# 指定本节点在集群中是否存储数据, 默认为true. 
# node.data=true
#
# 配置文件中给出了三种配置高性能集群拓扑结构的模式, 如下: 
# 1. 如果想让节点不被选举为主节点, 只用来存储数据, 可作为负载器:  
# node.master: false 
# node.data: true 
# node.ingest: true  # 默认为true
#
# 2. 如果想让节点成为主节点, 且不存储任何数据, 并保有空闲资源,可作为协调器: 
# node.master: true 
# node.data: false
# node.ingest: true
#
# 3. 如果想让节点既不作主节点,又不作数据节点, 那么可将其作为搜索器, 从节点中获取数据, 生成搜索结果等:  
# node.master: false 
# node.data: false 
# node.ingest: true
#
# 4. 仅作为协调器: 
# node.master: false 
# node.data: false
# node.ingest: false
# 

1.3 Paths路径配置


# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):\
# 如果不配置下述两项, ES将在其主目录下创建. 建议将程序与数据分离配置, 方便系统迁移与升级. 
# 存放索引数据的目录
path.data: /data/elk/data
#
# Path to log files: 存放日志信息的目录
path.logs: /data/elk/logs
#

1.4 Memory内存配置

# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
# 启动时是否锁定ES运行所需的内存, 默认为false. 
# true: 锁定---防止ES使用Swap交换空间, 效率较高. 此时要确保当前用户具有memlock的权限. 
# false: 将使用Swap交换空间.
bootstrap.memory_lock: false 
bootstrap.system_call_filter: false
# 
# 确保ES_HEAP_SIZE参数的值设置为系统可用内存的一半左右, 不要超过, 因为Lucene底层索引和检索还需要一定的内存. 
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
# 
# 当系统使用内存交换, ES的性能将变得很差
# Elasticsearch performs poorly when the system is swapping the memory.
#

1.5 Network网络配置

# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
# 对外网关IP, 默认为localhost, 此时只能通过localhost或127.0.0.1访问. 
# 设置为0.0.0.0, 即可被外部网络访问
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
# 对外提供的HTTP访问端口, 默认为9200. 为提高安全性, 建议设置为其他值. 
#http.port: 9200
# 
# 集群节点之间通信的TCP传输端口. 下述Discovery部分的设置、ES的Java API 也通过此端口传输数据. 默认为9300. 
# transport.tcp.port: 9300
# 
# For more information, consult the network module documentation.
#

1.6 Discovery节点发现配置

# --------------------------------- Discovery ----------------------------------
# 
# 启动新节点时, 通过ip列表进行节点发现, 组建集群
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
# '127.0.0.1'是ipv4的回环地址, '[::1]'是ipv6的回环地址
# 
# 1.x中默认使用多播(multicast)协议: 自动发现同一网段中的ES节点并组建集群; 
# 2.x中默认使用单播(unicast)协议: 要组建集群, 就需要在这里指定集群的节点信息 -- 安全高效, 但不够灵活. 
# 
# 默认已经关闭了自动发现节点的多播协议功能: 
# discovery.zen.ping.multicast.enabled: false
# 
# 设置ES集群中各个节点的IP地址(或hostname), 也可配置为: ["ip:port", "ip:port"]. 若port未设置, 将使用transport.tcp.port的值. 
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
# 
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
# 配置此参数以防止集群出现"脑裂现象":集群被分为2个独立的集群, 将导致数据丢失. 
# 选举master的最少节点数 = (可成为master的节点数 / 2) + 1
#discovery.zen.minimum_master_nodes: 
# 
# discovery ping的超时时间, 网络不佳时可调高一点
#discovery.zen.ping.timeout: 3s
# 
# For more information, consult the zen discovery module documentation.
#

1.7 Gateway网关配置

# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
# 配置集群中的N个节点启动后, 才允许进行数据恢复处理. 默认是1.
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#

1.8 Various其他配置

# ---------------------------------- Various -----------------------------------
#

# 在一台服务器上禁止启动多个es服务
# Disable starting multiple nodes on a single system:
#
# node.max_local_storage_nodes: 1
#
# 设置是否可以通过正则或者_all删除或者关闭索引库,默认true表示必须需要显式指定索引库名称
# 
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
  • 注意:

    在2.x版本的配置文件中, 存在 Index 配置项, 可配置包括分片数、副本分片数在内的配置.

    在5.x版本中, 不支持在配置文件中设置此类配置项了, 请注意此区别.

  • 修改完之后使用命令查看具体修改了哪些值

    # 查看某个文件上次修改的内容: 
    grep '^[a-z]' /data/elk/es-node1/config/elasticsearch.yml
    

2 jvm.options(JVM参数配置)

文件位置: ${ELASTIC_SEARCH_HOME}/config/jvm.options

关于JVM常见参数的配置, 可参考博主文章:

对Tomcat 8.0进行JVM层面的优化(基于Oracle JDK 8)

GC学习入门 看这一篇就够了(基于Oracle JDK 8)

## JVM configuration

################################################################
## IMPORTANT: JVM heap size
################################################################
##
## You should always set the min and max JVM heap
## size to the same value. For example, to set
## the heap to 4 GB, set:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
# 下述配置最好不要超过内存的50%, 留出50%供Lucene底层索引与检索使用 
-Xms2g
-Xmx2g

################################################################
## Expert settings
################################################################
##
## All settings below this section are considered
## expert settings. Don't tamper with them unless
## you understand what you are doing
##
################################################################

## GC configuration
-XX:+UseConcMarkSweepGC
-XX:CMSInitiatingOccupancyFraction=75
-XX:+UseCMSInitiatingOccupancyOnly

## optimizations

# disable calls to System#gc
-XX:+DisableExplicitGC

# pre-touch memory pages used by the JVM during initialization
-XX:+AlwaysPreTouch

## basic

# force the server VM (remove on 32-bit client JVMs)
-server

# explicitly set the stack size (reduce to 320k on 32-bit client JVMs)
-Xss1m

# set to headless, just in case
-Djava.awt.headless=true

# ensure UTF-8 encoding by default (e.g. filenames)
-Dfile.encoding=UTF-8

# use our provided JNA always versus the system one
-Djna.nosys=true

# use old-style file permissions on JDK9
-Djdk.io.permissionsUseCanonicalPath=true

# flags to configure Netty
-Dio.netty.noUnsafe=true
-Dio.netty.noKeySetOptimization=true
-Dio.netty.recycler.maxCapacityPerThread=0

# log4j 2
-Dlog4j.shutdownHookEnabled=false
-Dlog4j2.disable.jmx=true
-Dlog4j.skipJansi=true

## heap dumps

# generate a heap dump when an allocation from the Java heap fails
# heap dumps are created in the working directory of the JVM
-XX:+HeapDumpOnOutOfMemoryError

# specify an alternative path for heap dumps
# ensure the directory exists and has sufficient space
#-XX:HeapDumpPath=${heap.dump.path}

## GC logging

#-XX:+PrintGCDetails
#-XX:+PrintGCTimeStamps
#-XX:+PrintGCDateStamps
#-XX:+PrintClassHistogram
#-XX:+PrintTenuringDistribution
#-XX:+PrintGCApplicationStoppedTime

# log GC status to a file with time stamps
# ensure the directory exists
#-Xloggc:${loggc}

# Elasticsearch 5.0.0 will throw an exception on unquoted field names in JSON.
# If documents were already indexed with unquoted fields in a previous version
# of Elasticsearch, some operations may throw errors.
#
# WARNING: This option will be removed in Elasticsearch 6.0.0 and is provided
# only for migration purposes.
#-Delasticsearch.json.allow_unquoted_field_names=true

3 log4j2.properties(日志配置)

文件位置: ${ELASTIC_SEARCH_HOME}/config/log4j2.properties

一般使用默认日志配置即可.

参考

https://blog.csdn.net/qq_35393693/article/details/80143073

https://blog.csdn.net/xifeijian/article/details/49617775

https://www.cnblogs.com/xiaochina/p/6855591.html

https://blog.csdn.net/sunjiangangok/article/details/80261536

版权声明

作者: ma_shoufeng(马瘦风)

出处: CSDN 马瘦风的博客

您的支持是对博主的极大鼓励, 感谢您的阅读.

本文版权归博主所有, 欢迎转载, 但未经博主同意必须保留此段声明, 且在文章页面明显位置给出原文链接, 否则博主保留追究相关人员法律责任的权利.

猜你喜欢

转载自blog.csdn.net/ma_shou_feng/article/details/83783213