configuration.asciidoc 11 KB

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