ES 提供了很多默认的参数设置,使我们不用添加任何参数就可以成功的启动 ES 。 作为一个认真的学习者。我们还是来一起看看 如何更好的自定义 ES 配置。 详细的配置内容,可以参考 https://www.elastic.co/guide/en/elasticsearch/reference/current/settings.html.
ES 的属性,分为 静态属性 和 动态属性。
所有的静态属性,都必须重启后才能生效。
对于动态属性可以通过调用
1 2 3 4
POST _nodes/reload_secure_settings { "secure_settings_password": "s3cr3t" }
# 创建一个keystore > ./elasticsearch-keystore create -p ## //输入密码 Enter new password for the elasticsearch keystore (empty for no password): ## // 确认密码 Enter same password again: ## // 已经有keystore文件了,是否要覆盖 An elasticsearch keystore already exists. Overwrite? [y/N]y Created elasticsearch keystore in /Users/bjhl/fxb_applicaton/fxb_program/elasticsearch-7.10.1/config/elasticsearch.keystore
# 查看秘钥库 > ./elasticsearch-keystore list ## // 输入密码 Enter password for the elasticsearch keystore : keystore.seed # 秘钥库
# 添加设置到秘钥库中 > ./elasticsearch-keystore add settings.name ## // 输入密码 Enter password for the elasticsearch keystore : ## 输入添加的设置的value Enter value for settings.name:
# 添加文件到秘钥库 > ./elasticsearch-keystore add-file file.name xxx.xx Enter password for the elasticsearch keystore :
# 删除配置 > ./elasticsearch-keystore remove settings.name Enter password for the elasticsearch keystore :
# 更新keystore > ./elasticsearch-keystore upgrade Enter password for the elasticsearch keystore :
# - 内存相关 - # Lock the memory on startup: bootstrap.memory_lock:true # 确保将堆大小设置为系统上可用内存的一半左右,并确保进程的所有者可以使用此限制。系统交换内存时,Elasticsearch的性能较差。 # ---------------------------------- Network ----------------------------------- # Set the bind address to a specific IP (IPv4 or IPv6): network.host:192.168.0.1 # 启动端口 http.port:9200 # 更多可以参考: https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html
# --------------------------------- Discovery ---------------------------------- # 提供群集中符合主机资格的节点的地址列表。 # The default list of hosts is ["127.0.0.1", "[::1]"] discovery.seed_hosts: ["host1", "host2"] # 设置初始的符合主机资格的节点集,【静态属性】 cluster.initial_master_nodes: ["node-1", "node-2"] # 更多关于发现相关的配置,参考:https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-settings.html # ---------------------------------- Gateway ----------------------------------- # Block initial recovery after a full cluster restart until N nodes are started: gateway.recover_after_nodes:3 # # 更多内容,参考https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-gateway.html # # ---------------------------------- Various ----------------------------------- # Require explicit names when deleting indices: action.destructive_requires_name:true
################################################################ ## IMPORTANT: JVM heap size ################################################################ ## 参考 https://www.elastic.co/guide/en/elasticsearch/reference/current/important-settings.html#heap-size-settings # Xms represents the initial size of total heap space # Xmx represents the maximum size of total heap space -Xms1g -Xmx1g
## G1GC Configuration # NOTE: G1 GC is only supported on JDK version 10 or later # to use G1GC, uncomment the next two lines and update the version on the # following three lines to your version of the JDK # 10-13:-XX:-UseConcMarkSweepGC # 10-13:-XX:-UseCMSInitiatingOccupancyOnly 14-:-XX:+UseG1GC 14-:-XX:G1ReservePercent=25 14-:-XX:InitiatingHeapOccupancyPercent=30
# 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=data
# specify an alternative path for JVM fatal error logs -XX:ErrorFile=logs/hs_err_pid%p.log
除了对 ES 的配置之外,如果想要更好的提升 ES 性能,还需对 ES 所依赖的宿主机进行一些属性配置。
比如:比如禁止 swap 等。更多内容,参考:https://www.elastic.co/guide/en/elasticsearch/reference/current/system-config.html.