Elasticsearch 配置文件详解

本文详细介绍了Elasticsearch的.yml配置文件,包括集群、节点、路径、内存、网络等方面的配置。指出es为多数参数设了合理默认值,此配置文件列出生产环境重要配置,还说明了yaml格式文件的书写规范,以及1.*和2.*版本配置文件的差异。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

此elasticsearch-.yml配置文件,是在$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 see the documentation for further information on configuration options:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration.html>
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
# 集群名称,默认是elasticsearch
# cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
# 节点名称,默认从elasticsearch-2.4.3/lib/elasticsearch-2.4.3.jar!config/names.txt中随机选择一个名称
# node.name: node-1
#
# Add custom attributes to the node:

# node.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
# 可以指定es的数据存储目录,默认存储在es_home/data目录下
# path.data: /path/to/data
#
# Path to log files:
# 可以指定es的日志存储目录,默认存储在es_home/logs目录下
# path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
# 锁定物理内存地址,防止elasticsearch内存被交换出去,也就是避免es使用swap交换分区
# bootstrap.memory_lock: true
#
#
#
# 确保ES_HEAP_SIZE参数设置为系统可用内存的一半左右
# Make sure that the `ES_HEAP_SIZE` environment variable 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.
#
# ---------------------------------- Network -----------------------------------
#
#
# 为es设置ip绑定,默认是127.0.0.1,也就是默认只能通过127.0.0.1 或者localhost才能访问
# es1.x版本默认绑定的是0.0.0.0 所以不需要配置,但是es2.x版本默认绑定的是127.0.0.1,需要配置
# Set the bind address to a specific IP (IPv4 or IPv6):
#
# network.host: 192.168.0.1
#
#
# 为es设置自定义端口,默认是9200
# 注意:在同一个服务器中启动多个es节点的话,默认监听的端口号会自动加1:例如:9200,9201,9202...
# Set a custom port for HTTP:
#
# http.port: 9200
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html>
#
# --------------------------------- Discovery ----------------------------------
#
# 当启动新节点时,通过这个ip列表进行节点发现,组建集群
# 默认节点列表:
# 127.0.0.1,表示ipv4的回环地址。
# [::1],表示ipv6的回环地址
#
# 在es1.x中默认使用的是组播(multicast)协议,默认会自动发现同一网段的es节点组建集群,
# 在es2.x中默认使用的是单播(unicast)协议,想要组建集群的话就需要在这指定要发现的节点信息了。
# 注意:如果是发现其他服务器中的es服务,可以不指定端口[默认9300],如果是发现同一个服务器中的es服务,就需要指定端口了。
# 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]"]
#
# discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
#
#
#
# 通过配置这个参数来防止集群脑裂现象 (集群总节点数量/2)+1
# Prevent the "split brain" by configuring the majority of nodes (total number of nodes / 2 + 1):
#
# discovery.zen.minimum_master_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery.html>
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
# 一个集群中的N个节点启动后,才允许进行数据恢复处理,默认是1
# gateway.recover_after_nodes: 3
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-gateway.html>
#
# ---------------------------------- Various -----------------------------------
# 在一台服务器上禁止启动多个es服务
# Disable starting multiple nodes on a single system:
#
# node.max_local_storage_nodes: 1
#
# 设置是否可以通过正则或者_all删除或者关闭索引库,默认true表示必须需要显式指定索引库名称
# 生产环境建议设置为true,删除索引库的时候必须显式指定,否则可能会误删索引库中的索引库。
# Require explicit names when deleting indices:
#
# action.destructive_requires_name: true

#spring集成Elasticsearch需增加配置

transport.tcp.port: 9300
transport.tcp.compress: true
http.cors.enabled: true 
http.cors.allow-origin: "*"
node.master: true
node.data: true

总结

  1、es已经为大多数参数设置合理的默认值

  2、这个配置文件中列出来了针对生产环境下的一些重要配置

  3、注意:这个文件是yaml格式的文件

    (1):属性顶格写,不能有空格

    (2):缩进一定不能使用tab制表符

    (3):属性和值之间的:后面需要有空格

        network.host: 192.168.80.200

  4、es的1.*版本比2.*版本,这个配置文件多了很多属性,为什么2.*版本没了呢,因为,es很多地方做了默认配置。

### Docker 中 Elasticsearch 配置文件详解 在 Docker 容器中运行 Elasticsearch 时,可以通过挂载主机上的配置文件来实现自定义设置。具体操作如下: #### 修改配置文件路径 默认情况下,Elasticsearch配置文件位于容器内的 `/usr/share/elasticsearch/config/` 目录下[^1]。 为了方便管理和持久化保存配置更改,建议将本地机器上的一份 `elasticsearch.yml` 文件映射到该目录。这可以通过启动容器时指定 `-v` 参数完成: ```bash docker run -d \ --name elasticsearch \ -v /path/to/local/conf:/usr/share/elasticsearch/config \ docker.elastic.co/elasticsearch/elasticsearch:7.10.2 ``` 上述命令会把宿主机的 `/path/to/local/conf` 目录下的所有内容挂载至容器内部对应的配置位置。 #### 关键配置项说明 对于安全性和网络访问控制方面,在 `elasticsearch.yml` 文件中有几个重要参数需要注意设置: - **集群名称**: 设置唯一的集群名以便区分不同环境中的节点。 ```yaml cluster.name: my-application-cluster ``` - **绑定地址与端口**: 控制哪些 IP 地址可以连接以及监听哪个端口号。 ```yaml network.host: 0.0.0.0 http.port: 9200-9300 ``` - **启用身份验证**: 如果启用了 X-Pack 或其他认证机制,则需在此处添加用户名密码等信息。 ```yaml xpack.security.enabled: true xpack.security.http.ssl.enabled: false ``` 通过以上方式可以在 Docker 环境里灵活调整 Elasticsearch 行为并确保其按照预期工作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值