configuration.asciidoc 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. The Linux kernel tries to use as much memory as possible for file system
  42. caches and eagerly swaps out unused application memory, possibly resulting
  43. in the elasticsearch process being swapped. Swapping is very bad for
  44. performance and for node stability, so it should be avoided at all costs.
  45. There are three options:
  46. * **Disable swap**
  47. +
  48. --
  49. The simplest option is to completely disable swap. Usually Elasticsearch
  50. is the only service running on a box, and its memory usage is controlled
  51. by the `ES_HEAP_SIZE` environment variable. There should be no need
  52. to have swap enabled. On Linux systems, you can disable swap temporarily
  53. by running: `sudo swapoff -a`. To disable it permanently, you will need
  54. to edit the `/etc/fstab` file and comment out any lines that contain the
  55. word `swap`.
  56. --
  57. * **Configure `swappiness`**
  58. +
  59. --
  60. The second option is to ensure that the sysctl value `vm.swappiness` is set
  61. to `0`. This reduces the kernel's tendency to swap and should not lead to
  62. swapping under normal circumstances, while still allowing the whole system
  63. to swap in emergency conditions.
  64. NOTE: From kernel version 3.5-rc1 and above, a `swappiness` of `0` will
  65. cause the OOM killer to kill the process instead of allowing swapping.
  66. You will need to set `swappiness` to `1` to still allow swapping in
  67. emergencies.
  68. --
  69. * **`mlockall`**
  70. +
  71. --
  72. The third option on Linux/Unix systems only, is to use
  73. http://opengroup.org/onlinepubs/007908799/xsh/mlockall.html[mlockall] to
  74. try to lock the process address space into RAM, preventing any Elasticsearch
  75. memory from being swapped out. This can be done, by adding this line
  76. to the `config/elasticsearch.yml` file:
  77. [source,yaml]
  78. --------------
  79. bootstrap.mlockall: true
  80. --------------
  81. After starting Elasticsearch, you can see whether this setting was applied
  82. successfully by checking the value of `mlockall` in the output from this
  83. request:
  84. [source,sh]
  85. --------------
  86. curl http://localhost:9200/_nodes/process?pretty
  87. --------------
  88. If you see that `mlockall` is `false`, then it means that the the `mlockall`
  89. request has failed. The most probable reason is that the user running
  90. Elasticsearch doesn't have permission to lock memory. This can be granted
  91. by running `ulimit -l unlimited` as `root` before starting Elasticsearch.
  92. Another possible reason why `mlockall` can fail is that the temporary directory
  93. (usually `/tmp`) is mounted with the `noexec` option. This can be solved by
  94. specfying a new temp directory, by starting Elasticsearch with:
  95. [source,sh]
  96. --------------
  97. ./bin/elasticsearch -Djna.tmpdir=/path/to/new/dir
  98. --------------
  99. WARNING: `mlockall` might cause the JVM or shell session to exit if it tries
  100. to allocate more memory than is available!
  101. --
  102. [float]
  103. [[settings]]
  104. === Elasticsearch Settings
  105. *elasticsearch* configuration files can be found under `ES_HOME/config`
  106. folder. The folder comes with two files, the `elasticsearch.yml` for
  107. configuring Elasticsearch different
  108. <<modules,modules>>, and `logging.yml` for
  109. configuring the Elasticsearch logging.
  110. The configuration format is http://www.yaml.org/[YAML]. Here is an
  111. example of changing the address all network based modules will use to
  112. bind and publish to:
  113. [source,yaml]
  114. --------------------------------------------------
  115. network :
  116. host : 10.0.0.4
  117. --------------------------------------------------
  118. [float]
  119. [[paths]]
  120. ==== Paths
  121. In production use, you will almost certainly want to change paths for
  122. data and log files:
  123. [source,yaml]
  124. --------------------------------------------------
  125. path:
  126. logs: /var/log/elasticsearch
  127. data: /var/data/elasticsearch
  128. --------------------------------------------------
  129. [float]
  130. [[cluster-name]]
  131. ==== Cluster name
  132. Also, don't forget to give your production cluster a name, which is used
  133. to discover and auto-join other nodes:
  134. [source,yaml]
  135. --------------------------------------------------
  136. cluster:
  137. name: <NAME OF YOUR CLUSTER>
  138. --------------------------------------------------
  139. [float]
  140. [[node-name]]
  141. ==== Node name
  142. You may also want to change the default node name for each node to
  143. something like the display hostname. By default Elasticsearch will
  144. randomly pick a Marvel character name from a list of around 3000 names
  145. when your node starts up.
  146. [source,yaml]
  147. --------------------------------------------------
  148. node:
  149. name: <NAME OF YOUR NODE>
  150. --------------------------------------------------
  151. Internally, all settings are collapsed into "namespaced" settings. For
  152. example, the above gets collapsed into `node.name`. This means that
  153. its easy to support other configuration formats, for example,
  154. http://www.json.org[JSON]. If JSON is a preferred configuration format,
  155. simply rename the `elasticsearch.yml` file to `elasticsearch.json` and
  156. add:
  157. [float]
  158. [[styles]]
  159. ==== Configuration styles
  160. [source,yaml]
  161. --------------------------------------------------
  162. {
  163. "network" : {
  164. "host" : "10.0.0.4"
  165. }
  166. }
  167. --------------------------------------------------
  168. It also means that its easy to provide the settings externally either
  169. using the `ES_JAVA_OPTS` or as parameters to the `elasticsearch`
  170. command, for example:
  171. [source,sh]
  172. --------------------------------------------------
  173. $ elasticsearch -Des.network.host=10.0.0.4
  174. --------------------------------------------------
  175. Another option is to set `es.default.` prefix instead of `es.` prefix,
  176. which means the default setting will be used only if not explicitly set
  177. in the configuration file.
  178. Another option is to use the `${...}` notation within the configuration
  179. file which will resolve to an environment setting, for example:
  180. [source,js]
  181. --------------------------------------------------
  182. {
  183. "network" : {
  184. "host" : "${ES_NET_HOST}"
  185. }
  186. }
  187. --------------------------------------------------
  188. The location of the configuration file can be set externally using a
  189. system property:
  190. [source,sh]
  191. --------------------------------------------------
  192. $ elasticsearch -Des.config=/path/to/config/file
  193. --------------------------------------------------
  194. [float]
  195. [[configuration-index-settings]]
  196. === Index Settings
  197. Indices created within the cluster can provide their own settings. For
  198. example, the following creates an index with memory based storage
  199. instead of the default file system based one (the format can be either
  200. YAML or JSON):
  201. [source,sh]
  202. --------------------------------------------------
  203. $ curl -XPUT http://localhost:9200/kimchy/ -d \
  204. '
  205. index :
  206. store:
  207. type: memory
  208. '
  209. --------------------------------------------------
  210. Index level settings can be set on the node level as well, for example,
  211. within the `elasticsearch.yml` file, the following can be set:
  212. [source,yaml]
  213. --------------------------------------------------
  214. index :
  215. store:
  216. type: memory
  217. --------------------------------------------------
  218. This means that every index that gets created on the specific node
  219. started with the mentioned configuration will store the index in memory
  220. *unless the index explicitly sets it*. In other words, any index level
  221. settings override what is set in the node configuration. Of course, the
  222. above can also be set as a "collapsed" setting, for example:
  223. [source,sh]
  224. --------------------------------------------------
  225. $ elasticsearch -Des.index.store.type=memory
  226. --------------------------------------------------
  227. All of the index level configuration can be found within each
  228. <<index-modules,index module>>.
  229. [float]
  230. [[logging]]
  231. === Logging
  232. Elasticsearch uses an internal logging abstraction and comes, out of the
  233. box, with http://logging.apache.org/log4j/[log4j]. It tries to simplify
  234. log4j configuration by using http://www.yaml.org/[YAML] to configure it,
  235. and the logging configuration file is `config/logging.yml` file.