Elasticsearch配置文件详解

本文详细介绍了Elasticsearch配置文件elasticsearch.yml中的各项配置参数及其作用,包括集群配置、节点配置、索引配置等,帮助读者理解如何正确配置Elasticsearch以适应不同场景的需求。

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

/usr/local/elasticsearch-5.4.0/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
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
#配置Elasticsearch的集群名称,默认是"elasticsearch",Elasticsearch会自动发现在同
#一网段下的Elasticsearch节点,如果在同一网段下有多个集群,就可以用这个属性来区分不同的集群。
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
#配置Elasticsearch的节点名,默认随机指定一个漫威漫画里的3000多个角色的名字。
#和集群名称一样可以自定义,同一个集群的集群名称要配置统一,节点名称取不同值便于区分。
# Add custom attributes to the node:
#
#node.attr.rack: r1

#node.master: true
#指定该节点是否是master节点,默认是true,Elasticsearch默认集群中第一台机器为master,
#如果这台机器出现故障就会重新选举master
#node.data: true
#指定该节点是否存储索引数据,默认true

# 注意:master和data的配置
# 1) 当master为false,而data为true时,会对该节点产生严重负荷;
# 2) 当master为true,而data为false时,该节点作为一个协调者;
# 3) 当master为false,data也为false时,该节点就变成了一个负载均衡器。
#

#------------------------------------ Index ------------------------------------
#index.number_of_shards: 5
#设置默认索引分片个数,默认值为5,每个索引分成5个分片。5.0版本以前有效,
#5.0版本以后会报参数异常,提示节点中不能指定索引级别配置
#
#index.number_of_replicas: 1
#设置默认索引副本个数,默认为1.和分片配置一样,只有在5.0之前的版本配置有效


# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#设置索引数据的存储路径,默认是Elasticsearch根目录下的data文件夹,可以设置多个存储路径,
#用逗号隔开,比如:/path/to/data1,path/to/data2
# Path to log files:
#
#path.logs: /path/to/logs
#设置日志文件的存储路径,默认是Elasticsearch根目录下的logs文件夹
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#设置为true来锁住内存。因为当jvm开始swapping时Elasticsearch的效率会降低,
#所以要保证它不swap,可以把ES_MIN_MEM和ES_MAX_MEM两个环境变量设置成同一个值,
#并且保证机器有足够的内存分配给Elasticsearch
# 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.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
network.host:  0.0.0.0
#设置外网访问的ip地址,可以是IPv4或IPv6,
#在我的版本中需要手动设置成 0.0.0.0才会允许外网访问
# Set a custom port for HTTP:
#
#http.port: 9200
#设置对外服务的HTTP端口,默认为 9200
# 
#transport.tcp.port: 9300
#设置节点间交互的TCP端口,也是Java API中使用的端口,默认是9300
#
#transport.tcp.compress: true
#设置是否压缩TCP传输时的数据,默认为false,不压缩
#
#http.max_content_length: 100mb
#设置内容的最大容量,默认100mb
#
#http.enabled: true
#是否使用HTTP协议对外提供服务,默认为true
#
#For more information, consult the network module documentation.
# --------------------------------- Discovery ----------------------------------
#
# 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"]
#设置集群中master节点的初始列表,可以通过这些节点来自动发现新加入集群的节点
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes:  1
#设置这个参数来保证集群中的节点可以知道其他N个有master资格的节点。默认为1
#
#discovery.zen.ping_timeout: 3s
#设置集群中自动发现其他节点时ping连接超时时间,默认为3秒,对于比较差的网络环境
#可以提高该值来防止自动发现时出错
#
#discovery.zen.ping.multicast.enabled: false
#设置是否打开多播发现节点,默认是true。
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#设置集群中N个节点启动时进行数据恢复,默认为1。
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true





### 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 行为并确保其按照预期工作。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值