configuration.asciidoc 9.8 KB

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