企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 配置Elasticsearch Elasticsearch提供了不错的默认值,且仅需较少的配置。 可以使用[群集的更新设置API](../Cluster_APIs/Cluster_Update_Settings.md)在正在运行的群集上更改大多数配置。 配置文件中可能需要包含特定于节点的配置(例如:`node.name`和`paths`)与节点为了能够加入群集而需要的配置,例如:`cluster.name`和`network.host`。 ## 配置文件位置 Elasticsearch有三个配置文件: - 用于配置Elasticsearch的`elasticsearch.yml`; - jvm.options for configuring Elasticsearch JVM settings - log4j2.properties用于配置Elasticsearch日志记录的`log4j2.properties`。 这些文件位于配置文件目录中,其位置默认为`$ES_HOME/config/`。Debian和RPM软件包将config目录位置设置为`/etc/elasticsearch/`。 可以使用`path.conf`设置更改配置文件目录的位置,如下所示: ``` ./bin/elasticsearch -Epath.conf=/path/to/my/config/ ``` Alternatively, you can export the `ES_PATH_CONF` environment variable via the command line or via your shell profile. For the package distributions, the config directory location defaults to `/etc/elasticsearch`. The location of the config directory can also be changed via the ES_PATH_CONF environment variable, but note that setting this in your shell is not sufficient. Instead, this variabled is sourced from `/etc/default/elasticsearch` (for the Debian package) and `/etc/sysconfig/elasticsearch` (for the RPM package). You will need to edit the `ES_PATH_CONF=/etc/elasticsearch` entry in one of these files accordingly to change the config directory location. ## 配置文件格式 配置格式为[YAML](http://www.yaml.org/)。 下面是更改数据目录和日志目录路径的示例: ``` path: data: /var/lib/elasticsearch logs: /var/log/elasticsearch ``` 设置也可以展平开如下: ``` path.data: /var/lib/elasticsearch path.logs: /var/log/elasticsearch ``` ## 环境变量替换 配置文件中可以使用`${...}`符号来引用环境变量的值,例如: ``` node.name: ${HOSTNAME} network.host: ${ES_NETWORK_HOST} ``` ## 交互式配置 对于您不希望保存在配置文件中的设置,您可以使用`${prompt.text}`或`${prompt.secret}`这样的值并在控制台启动Elasticsearch。`${prompt.secret}`禁用了打印,所以输入的值不会在终端显示; `${prompt.text}`将允许您在键入时看到值。例如: ``` node: name: ${prompt.text} ``` 当启动Elasticsearch时,将提示您进行输入,如下所示: ``` Enter value for [node.name]: ``` > 注意 > > 如果在配置文件中使用`${prompt.text}`或`${prompt.secret}`,Elasticsearch将不能作为服务进程运行或者是在后台运行。