configuration.asciidoc 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. [[settings]]
  2. == Configuring Elasticsearch
  3. Elasticsearch ships with good defaults and requires very little configuration.
  4. Most settings can be changed on a running cluster using the
  5. <<cluster-update-settings>> API.
  6. The configuration files should contain settings which are node-specific (such
  7. as `node.name` and paths), or settings which a node requires in order to be
  8. able to join a cluster, such as `cluster.name` and `network.host`.
  9. [float]
  10. === Config file location
  11. Elasticsearch has two configuration files:
  12. * `elasticsearch.yml` for configuring Elasticsearch, and
  13. * `log4j2.properties` for configuring Elasticsearch logging.
  14. These files are located in the config directory, whose location defaults to
  15. `$ES_HOME/config/`. The Debian and RPM packages set the config directory
  16. location to `/etc/elasticsearch/`.
  17. The location of the config directory can be changed with the `path.conf`
  18. flag, as follows:
  19. [source,sh]
  20. -------------------------------
  21. ./bin/elasticsearch --path.conf /path/to/my/config/
  22. -------------------------------
  23. [float]
  24. === Config file format
  25. The configuration format is http://www.yaml.org/[YAML]. Here is an
  26. example of changing the path of the data and logs directories:
  27. [source,yaml]
  28. --------------------------------------------------
  29. path:
  30. data: /var/lib/elasticsearch
  31. logs: /var/log/elasticsearch
  32. --------------------------------------------------
  33. Settings can also be flattened as follows:
  34. [source,yaml]
  35. --------------------------------------------------
  36. path.data: /var/lib/elasticsearch
  37. path.logs: /var/log/elasticsearch
  38. --------------------------------------------------
  39. [float]
  40. === Environment variable substitution
  41. Environment variables referenced with the `${...}` notation within the
  42. configuration file will be replaced with the value of the environment
  43. variable, for instance:
  44. [source,yaml]
  45. --------------------------------------------------
  46. node.name: ${HOSTNAME}
  47. network.host: ${ES_NETWORK_HOST}
  48. --------------------------------------------------
  49. [float]
  50. === Prompting for settings
  51. For settings that you do not wish to store in the configuration file, you can
  52. use the value `${prompt.text}` or `${prompt.secret}` and start Elasticsearch
  53. in the foreground. `${prompt.secret}` has echoing disabled so that the value
  54. entered will not be shown in your terminal; `${prompt.text}` will allow you to
  55. see the value as you type it in. For example:
  56. [source,yaml]
  57. --------------------------------------------------
  58. node:
  59. name: ${prompt.text}
  60. --------------------------------------------------
  61. When starting Elasticsearch, you will be prompted to enter the actual value
  62. like so:
  63. [source,sh]
  64. --------------------------------------------------
  65. Enter value for [node.name]:
  66. --------------------------------------------------
  67. NOTE: Elasticsearch will not start if `${prompt.text}` or `${prompt.secret}`
  68. is used in the settings and the process is run as a service or in the background.
  69. [float]
  70. [[logging]]
  71. == Logging configuration
  72. Elasticsearch uses https://logging.apache.org/log4j/2.x/[Log4j 2] for
  73. logging. Log4j 2 can be configured using the log4j2.properties
  74. file. Elasticsearch exposes three properties, `${sys:es.logs.base_path}`,
  75. `${sys:es.logs.cluster_name}`, and `${sys:es.logs.node_name}` (if the node name
  76. is explicitly set via `node.name`) that can be referenced in the configuration
  77. file to determine the location of the log files. The property
  78. `${sys:es.logs.base_path}` will resolve to the log directory,
  79. `${sys:es.logs.cluster_name}` will resolve to the cluster name (used as the
  80. prefix of log filenames in the default configuration), and
  81. `${sys:es.logs.node_name}` will resolve to the node name (if the node name is
  82. explicitly set).
  83. For example, if your log directory (`path.logs`) is `/var/log/elasticsearch` and
  84. your cluster is named `production` then `${sys:es.logs.base_path}` will resolve
  85. to `/var/log/elasticsearch` and
  86. `${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}.log`
  87. will resolve to `/var/log/elasticsearch/production.log`.
  88. [source,properties]
  89. --------------------------------------------------
  90. appender.rolling.type = RollingFile <1>
  91. appender.rolling.name = rolling
  92. appender.rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}.log <2>
  93. appender.rolling.layout.type = PatternLayout
  94. appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %marker%.-10000m%n
  95. appender.rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-%d{yyyy-MM-dd}-%i.log.gz <3>
  96. appender.rolling.policies.type = Policies
  97. appender.rolling.policies.time.type = TimeBasedTriggeringPolicy <4>
  98. appender.rolling.policies.time.interval = 1 <5>
  99. appender.rolling.policies.time.modulate = true <6>
  100. appender.rolling.policies.size.type = SizeBasedTriggeringPolicy <7>
  101. appender.rolling.policies.size.size = 256MB <8>
  102. appender.rolling.strategy.type = DefaultRolloverStrategy
  103. appender.rolling.strategy.fileIndex = nomax
  104. appender.rolling.strategy.action.type = Delete <9>
  105. appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path}
  106. appender.rolling.strategy.action.condition.type = IfFileName <10>
  107. appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-* <11>
  108. appender.rolling.strategy.action.condition.nested_condition.type = IfAccumulatedFileSize <12>
  109. appender.rolling.strategy.action.condition.nested_condition.exceeds = 2GB <13>
  110. --------------------------------------------------
  111. <1> Configure the `RollingFile` appender
  112. <2> Log to `/var/log/elasticsearch/production.log`
  113. <3> Roll logs to `/var/log/elasticsearch/production-yyyy-MM-dd-i.log`; logs
  114. will be compressed on each roll and `i` will be incremented
  115. <4> Use a time-based roll policy
  116. <5> Roll logs on a daily basis
  117. <6> Align rolls on the day boundary (as opposed to rolling every twenty-four
  118. hours)
  119. <7> Using a size-based roll policy
  120. <8> Roll logs after 256 MB
  121. <9> Use a delete action when rolling logs
  122. <10> Only delete logs matching a file pattern
  123. <11> The pattern is to only delete the main logs
  124. <12> Only delete if we have accumulated too many compressed logs
  125. <13> The size condition on the compressed logs is 2 GB
  126. NOTE: Log4j's configuration parsing gets confused by any extraneous whitespace;
  127. if you copy and paste any Log4j settings on this page, or enter any Log4j
  128. configuration in general, be sure to trim any leading and trailing whitespace.
  129. Note than you can replace `.gz` by `.zip` in `appender.rolling.filePattern` to
  130. compress the rolled logs using the zip format. If you remove the `.gz`
  131. extension then logs will not be compressed as they are rolled.
  132. If you want to retain log files for a specified period of time, you can use a
  133. rollover strategy with a delete action.
  134. [source,properties]
  135. --------------------------------------------------
  136. appender.rolling.strategy.type = DefaultRolloverStrategy <1>
  137. appender.rolling.strategy.action.type = Delete <2>
  138. appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path} <3>
  139. appender.rolling.strategy.action.condition.type = IfFileName <4>
  140. appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-* <5>
  141. appender.rolling.strategy.action.condition.nested_condition.type = IfLastModified <6>
  142. appender.rolling.strategy.action.condition.nested_condition.age = 7D <7>
  143. --------------------------------------------------
  144. <1> Configure the `DefaultRolloverStrategy`
  145. <2> Configure the `Delete` action for handling rollovers
  146. <3> The base path to the Elasticsearch logs
  147. <4> The condition to apply when handling rollovers
  148. <5> Delete files from the base path matching the glob
  149. `${sys:es.logs.cluster_name}-*`; this is the glob that log files are rolled
  150. to; this is needed to only delete the rolled Elasticsearch logs but not also
  151. delete the deprecation and slow logs
  152. <6> A nested condition to apply to files matching the glob
  153. <7> Retain logs for seven days
  154. Multiple configuration files can be loaded (in which case they will get merged)
  155. as long as they are named `log4j2.properties` and have the Elasticsearch config
  156. directory as an ancestor; this is useful for plugins that expose additional
  157. loggers. The logger section contains the java packages and their corresponding
  158. log level. The appender section contains the destinations for the logs.
  159. Extensive information on how to customize logging and all the supported
  160. appenders can be found on the
  161. http://logging.apache.org/log4j/2.x/manual/configuration.html[Log4j
  162. documentation].
  163. [float]
  164. [[deprecation-logging]]
  165. === Deprecation logging
  166. In addition to regular logging, Elasticsearch allows you to enable logging
  167. of deprecated actions. For example this allows you to determine early, if
  168. you need to migrate certain functionality in the future. By default,
  169. deprecation logging is enabled at the WARN level, the level at which all
  170. deprecation log messages will be emitted.
  171. [source,properties]
  172. --------------------------------------------------
  173. logger.deprecation.level = warn
  174. --------------------------------------------------
  175. This will create a daily rolling deprecation log file in your log directory.
  176. Check this file regularly, especially when you intend to upgrade to a new
  177. major version.
  178. The default logging configuration has set the roll policy for the deprecation
  179. logs to roll and compress after 1 GB, and to preserve a maximum of five log
  180. files (four rolled logs, and the active log).
  181. You can disable it in the `config/log4j2.properties` file by setting the deprecation
  182. log level to `error`.