configuration.asciidoc 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. [[setup-configuration]]
  2. == Configuration
  3. [float]
  4. === Environment Variables
  5. Within the scripts, Elasticsearch comes with built in `JAVA_OPTS` passed
  6. to the JVM started. The most important setting for that is the `-Xmx` to
  7. control the maximum allowed memory for the process, and `-Xms` to
  8. control the minimum allocated memory for the process (_in general, the
  9. more memory allocated to the process, the better_).
  10. Most times it is better to leave the default `JAVA_OPTS` as they are,
  11. and use the `ES_JAVA_OPTS` environment variable in order to set / change
  12. JVM settings or arguments.
  13. The `ES_HEAP_SIZE` environment variable allows to set the heap memory
  14. that will be allocated to elasticsearch java process. It will allocate
  15. the same value to both min and max values, though those can be set
  16. explicitly (not recommended) by setting `ES_MIN_MEM` (defaults to
  17. `256m`), and `ES_MAX_MEM` (defaults to `1gb`).
  18. It is recommended to set the min and max memory to the same value, and
  19. enable <<setup-configuration-memory,`mlockall`>>.
  20. [float]
  21. [[system]]
  22. === System Configuration
  23. [float]
  24. [[file-descriptors]]
  25. ==== File Descriptors
  26. Make sure to increase the number of open files descriptors on the
  27. machine (or for the user running elasticsearch). Setting it to 32k or
  28. even 64k is recommended.
  29. In order to test how many open files the process can open, start it with
  30. `-Des.max-open-files` set to `true`. This will print the number of open
  31. files the process can open on startup.
  32. Alternatively, you can retrieve the `max_file_descriptors` for each node
  33. using the <<cluster-nodes-info>> API, with:
  34. [source,js]
  35. --------------------------------------------------
  36. curl localhost:9200/_nodes/process?pretty
  37. --------------------------------------------------
  38. [float]
  39. [[setup-configuration-memory]]
  40. ==== Memory Settings
  41. There is an option to use
  42. http://opengroup.org/onlinepubs/007908799/xsh/mlockall.html[mlockall] to
  43. try to lock the process address space so it won't be swapped. For this
  44. to work, the `bootstrap.mlockall` should be set to `true` and it is
  45. recommended to set both the min and max memory allocation to be the
  46. same. Note: This option is only available on Linux/Unix operating
  47. systems.
  48. In order to see if this works or not, set the `common.jna` logging to
  49. DEBUG level. A solution to "Unknown mlockall error 0" can be to set
  50. `ulimit -l unlimited`.
  51. Note, `mlockall` might cause the JVM or shell
  52. session to exit if it fails to allocate the memory (because not enough
  53. memory is available on the machine).
  54. [float]
  55. [[settings]]
  56. === Elasticsearch Settings
  57. *elasticsearch* configuration files can be found under `ES_HOME/config`
  58. folder. The folder comes with two files, the `elasticsearch.yml` for
  59. configuring Elasticsearch different
  60. <<modules,modules>>, and `logging.yml` for
  61. configuring the Elasticsearch logging.
  62. The configuration format is http://www.yaml.org/[YAML]. Here is an
  63. example of changing the address all network based modules will use to
  64. bind and publish to:
  65. [source,yaml]
  66. --------------------------------------------------
  67. network :
  68. host : 10.0.0.4
  69. --------------------------------------------------
  70. [float]
  71. [[paths]]
  72. ==== Paths
  73. In production use, you will almost certainly want to change paths for
  74. data and log files:
  75. [source,yaml]
  76. --------------------------------------------------
  77. path:
  78. logs: /var/log/elasticsearch
  79. data: /var/data/elasticsearch
  80. --------------------------------------------------
  81. [float]
  82. [[cluster-name]]
  83. ==== Cluster name
  84. Also, don't forget to give your production cluster a name, which is used
  85. to discover and auto-join other nodes:
  86. [source,yaml]
  87. --------------------------------------------------
  88. cluster:
  89. name: <NAME OF YOUR CLUSTER>
  90. --------------------------------------------------
  91. [float]
  92. [[node-name]]
  93. ==== Node name
  94. You may also want to change the default node name for each node to
  95. something like the display hostname. By default Elasticsearch will
  96. randomly pick a Marvel character name from a list of around 3000 names
  97. when your node starts up.
  98. [source,yaml]
  99. --------------------------------------------------
  100. node:
  101. name: <NAME OF YOUR NODE>
  102. --------------------------------------------------
  103. Internally, all settings are collapsed into "namespaced" settings. For
  104. example, the above gets collapsed into `network.host`. This means that
  105. its easy to support other configuration formats, for example,
  106. http://www.json.org[JSON]. If JSON is a preferred configuration format,
  107. simply rename the `elasticsearch.yml` file to `elasticsearch.json` and
  108. add:
  109. [float]
  110. [[styles]]
  111. ==== Configuration styles
  112. [source,yaml]
  113. --------------------------------------------------
  114. {
  115. "network" : {
  116. "host" : "10.0.0.4"
  117. }
  118. }
  119. --------------------------------------------------
  120. It also means that its easy to provide the settings externally either
  121. using the `ES_JAVA_OPTS` or as parameters to the `elasticsearch`
  122. command, for example:
  123. [source,sh]
  124. --------------------------------------------------
  125. $ elasticsearch -Des.network.host=10.0.0.4
  126. --------------------------------------------------
  127. Another option is to set `es.default.` prefix instead of `es.` prefix,
  128. which means the default setting will be used only if not explicitly set
  129. in the configuration file.
  130. Another option is to use the `${...}` notation within the configuration
  131. file which will resolve to an environment setting, for example:
  132. [source,js]
  133. --------------------------------------------------
  134. {
  135. "network" : {
  136. "host" : "${ES_NET_HOST}"
  137. }
  138. }
  139. --------------------------------------------------
  140. The location of the configuration file can be set externally using a
  141. system property:
  142. [source,sh]
  143. --------------------------------------------------
  144. $ elasticsearch -Des.config=/path/to/config/file
  145. --------------------------------------------------
  146. [float]
  147. [[configuration-index-settings]]
  148. === Index Settings
  149. Indices created within the cluster can provide their own settings. For
  150. example, the following creates an index with memory based storage
  151. instead of the default file system based one (the format can be either
  152. YAML or JSON):
  153. [source,sh]
  154. --------------------------------------------------
  155. $ curl -XPUT http://localhost:9200/kimchy/ -d \
  156. '
  157. index :
  158. store:
  159. type: memory
  160. '
  161. --------------------------------------------------
  162. Index level settings can be set on the node level as well, for example,
  163. within the `elasticsearch.yml` file, the following can be set:
  164. [source,yaml]
  165. --------------------------------------------------
  166. index :
  167. store:
  168. type: memory
  169. --------------------------------------------------
  170. This means that every index that gets created on the specific node
  171. started with the mentioned configuration will store the index in memory
  172. *unless the index explicitly sets it*. In other words, any index level
  173. settings override what is set in the node configuration. Of course, the
  174. above can also be set as a "collapsed" setting, for example:
  175. [source,sh]
  176. --------------------------------------------------
  177. $ elasticsearch -Des.index.store.type=memory
  178. --------------------------------------------------
  179. All of the index level configuration can be found within each
  180. <<index-modules,index module>>.
  181. [float]
  182. [[logging]]
  183. === Logging
  184. Elasticsearch uses an internal logging abstraction and comes, out of the
  185. box, with http://logging.apache.org/log4j/[log4j]. It tries to simplify
  186. log4j configuration by using http://www.yaml.org/[YAML] to configure it,
  187. and the logging configuration file is `config/logging.yml` file.