1 elasticsearch.yml(ES服務配置)
文件位置: ${ES_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:
# 集群名稱, 具有相同名稱的節點才能組成一個邏輯集群, 默認是"elasticsearch", 建議修改為與項目相關的名稱.
cluster.name: heal_es
1.2 Node節點配置
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
# 本節點的名稱, 同一集群中各個node的名稱不允許重復. 不配置則系統默認分配.
# node.name: node-1
#
# Add custom attributes to the node:
# 指定節點的部落屬性 --- 一個比集群更大的范圍, 即定義一些通用屬性, 用於集群分配碎片時的過濾.
#node.attr.rack: r1
Elasticsearch 6.6.0版本中取消了下述配置:
# 指定本節點是否有資格被選舉為主節點, 默認是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-6.6.0/data
#
# Path to log files: 存放日志信息的目錄
path.logs: /data/elk-6.6.0/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
#network.host: 192.168.0.1
#
# Set a custom port for HTTP:
# 對外提供的HTTP訪問端口, 默認為9200. 為提高安全性, 建議設置為其他值.
# 可以指定一個值或一個區間, 如果是區間就會采取區間內第一個可用的端口.
#http.port: 9200
#
# For more information, consult the network module documentation.
Elasticsearch 6.6.0版本取消了transport.tcp.port
的設置:
#
# 集群節點之間通信的TCP傳輸端口. 下述Discovery部分的設置、ES的Java API 也通過此端口傳輸數據. 默認為9300.
# 可以指定一個值或一個區間, 如果是區間就會采取區間內第一個可用的端口.
# transport.tcp.port: 9300
① 舊版本的Java API中客戶端
TransportClient
使用的是9300端口, 它執行的是序列化的Java請求, 性能較低, 在7.x版本中將過期, 8.x版本中將移除;
② 新版本推薦使用Java High Level REST Client客戶端, 也就是RestHighLevelClient
, 它執行HTTP請求, 使用的端口是http.port, 默認就是9200.
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
#
# 指定單播模式的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的最少節點數 = (具有master資格的節點數 / 2) + 1
#discovery.zen.minimum_master_nodes:
#
# 設置集群中自動發現其他節點的連接超時時長, 默認是3秒.
# 在網絡不佳時增加這個值, 會增加節點等待響應的時間, 可以減少誤判.
# discover.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
# 是否壓縮TCP傳輸的數據, 默認是false:
# transport.tcp.compress: false
# 是否使用HTTP協議對外提供服務, 默認是true:
# http.cors.enabled: true
# http傳輸內容的最大容量, 默認是100MB:
# http.max_content_length: 100mb
-
注意:
在2.x版本的配置文件中, 存在 Index 配置項, 可配置包括分片數、副本分片數在內的配置.
在5.x版本中, 不支持在配置文件中設置此類配置項了, 請注意此區別. -
修改完之后使用命令查看具體修改了哪些值:
# 查看某個文件上次修改的內容: grep '^[a-z]' /data/elk-6.6.0/es-node/config/elasticsearch.yml
2 jvm.options(JVM參數配置)
文件位置: ${ES_HOME}/config/jvm.options
關於JVM常見參數的配置, 可參考博主文章:
## 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底層索引與檢索使用
-Xms1g
-Xmx1g
################################################################
## 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
## G1GC Configuration
# NOTE: G1GC is only supported on JDK version 10 or later.
# To use G1GC uncomment the lines below.
# 10-:-XX:-UseConcMarkSweepGC
# 10-:-XX:-UseCMSInitiatingOccupancyOnly
# 10-:-XX:+UseG1GC
# 10-:-XX:InitiatingHeapOccupancyPercent=75
## DNS cache policy
# cache ttl in seconds for positive DNS lookups noting that this overrides the
# JDK security property networkaddress.cache.ttl; set to -1 to cache forever
-Des.networkaddress.cache.ttl=60
# cache ttl in seconds for negative DNS lookups noting that this overrides the
# JDK security property networkaddress.cache.negative ttl; set to -1 to cache
# forever
-Des.networkaddress.cache.negative.ttl=10
## optimizations
# pre-touch memory pages used by the JVM during initialization
-XX:+AlwaysPreTouch
## basic
# 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
# turn off a JDK optimization that throws away stack traces for common
# exceptions because stack traces are important for debugging
-XX:-OmitStackTraceInFastThrow
# 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
# 生產環境中指定當發生OOM異常時, Heap的Dump Path, 默認是 -XX:HeapDumpPath=data
-XX:HeapDumpPath=/var/lib/elasticsearch
# specify an alternative path for JVM fatal error logs
-XX:ErrorFile=logs/hs_err_pid%p.log
## JDK 8 GC logging
8:-XX:+PrintGCDetails
8:-XX:+PrintGCDateStamps
8:-XX:+PrintTenuringDistribution
8:-XX:+PrintGCApplicationStoppedTime
8:-Xloggc:logs/gc.log
8:-XX:+UseGCLogFileRotation
8:-XX:NumberOfGCLogFiles=32
8:-XX:GCLogFileSize=64m
# JDK 9+ GC logging
9-:-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m
# due to internationalization enhancements in JDK 9 Elasticsearch need to set the provider to COMPAT otherwise
# time/date parsing will break in an incompatible way for some date patterns and locals
9-:-Djava.locale.providers=COMPAT
# temporary workaround for C2 bug with JDK 10 on hardware with AVX-512
10-:-XX:UseAVX=2
Elasticsearch 6.6.0中已經移除了下述優化配置:
# disable calls to System#gc
-XX:+DisableExplicitGC
# force the server VM (remove on 32-bit client JVMs)
-server
# use old-style file permissions on JDK9
-Djdk.io.permissionsUseCanonicalPath=true
其他說明:
-Xmx2g # 這種參數沒有限制JVM版本
8: -Xmx2g # 限制JVM版本為8
8-: -Xmx2g # 限制JVM版本為8及8以上
8-10: -Xmx2g # 限制JVM版本在8-10之間
3 log4j2.properties(日志配置)
文件位置: ${ES_HOME}/config/log4j2.properties
一般使用默認日志配置即可.
參考資料
版權聲明
出處: 博客園 馬瘦風的博客(https://www.cnblogs.com/shoufeng)
感謝閱讀, 如果文章有幫助或啟發到你, 點個[好文要頂👆] 或 [推薦👍] 吧😜
本文版權歸博主所有, 歡迎轉載, 但 [必須在文章頁面明顯位置標明原文鏈接], 否則博主保留追究相關人員法律責任的權利.