configuration.asciidoc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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,sh]
  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. Most operating systems try to use as much memory as possible for file system
  56. caches and eagerly swap 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.
  67. On Linux systems, you can disable swap temporarily
  68. by running: `sudo swapoff -a`. To disable it permanently, you will need
  69. to edit the `/etc/fstab` file and comment out any lines that contain the
  70. word `swap`.
  71. On Windows, the equivalent can be achieved by disabling the paging file entirely
  72. via `System Properties → Advanced → Performance → Advanced → Virtual memory`.
  73. --
  74. * **Configure `swappiness`**
  75. +
  76. --
  77. The second option is to ensure that the sysctl value `vm.swappiness` is set
  78. to `0`. This reduces the kernel's tendency to swap and should not lead to
  79. swapping under normal circumstances, while still allowing the whole system
  80. to swap in emergency conditions.
  81. NOTE: From kernel version 3.5-rc1 and above, a `swappiness` of `0` will
  82. cause the OOM killer to kill the process instead of allowing swapping.
  83. You will need to set `swappiness` to `1` to still allow swapping in
  84. emergencies.
  85. --
  86. * **`mlockall`**
  87. +
  88. --
  89. The third option is to use
  90. http://opengroup.org/onlinepubs/007908799/xsh/mlockall.html[mlockall] on Linux/Unix systems, or https://msdn.microsoft.com/en-us/library/windows/desktop/aa366895%28v=vs.85%29.aspx[VirtualLock] on Windows, to
  91. try to lock the process address space into RAM, preventing any Elasticsearch
  92. memory from being swapped out. This can be done, by adding this line
  93. to the `config/elasticsearch.yml` file:
  94. [source,yaml]
  95. --------------
  96. bootstrap.mlockall: true
  97. --------------
  98. After starting Elasticsearch, you can see whether this setting was applied
  99. successfully by checking the value of `mlockall` in the output from this
  100. request:
  101. [source,sh]
  102. --------------
  103. curl http://localhost:9200/_nodes/process?pretty
  104. --------------
  105. If you see that `mlockall` is `false`, then it means that the the `mlockall`
  106. request has failed. The most probable reason, on Linux/Unix systems, is that
  107. the user running Elasticsearch doesn't have permission to lock memory. This can
  108. be granted by running `ulimit -l unlimited` as `root` before starting Elasticsearch.
  109. Another possible reason why `mlockall` can fail is that the temporary directory
  110. (usually `/tmp`) is mounted with the `noexec` option. This can be solved by
  111. specifying a new temp directory, by starting Elasticsearch with:
  112. [source,sh]
  113. --------------
  114. ./bin/elasticsearch -Djna.tmpdir=/path/to/new/dir
  115. --------------
  116. WARNING: `mlockall` might cause the JVM or shell session to exit if it tries
  117. to allocate more memory than is available!
  118. --
  119. [float]
  120. [[settings]]
  121. === Elasticsearch Settings
  122. *elasticsearch* configuration files can be found under `ES_HOME/config`
  123. folder. The folder comes with two files, the `elasticsearch.yml` for
  124. configuring Elasticsearch different
  125. <<modules,modules>>, and `logging.yml` for
  126. configuring the Elasticsearch logging.
  127. The configuration format is http://www.yaml.org/[YAML]. Here is an
  128. example of changing the address all network based modules will use to
  129. bind and publish to:
  130. [source,yaml]
  131. --------------------------------------------------
  132. network :
  133. host : 10.0.0.4
  134. --------------------------------------------------
  135. [float]
  136. [[paths]]
  137. ==== Paths
  138. In production use, you will almost certainly want to change paths for
  139. data and log files:
  140. [source,yaml]
  141. --------------------------------------------------
  142. path:
  143. logs: /var/log/elasticsearch
  144. data: /var/data/elasticsearch
  145. --------------------------------------------------
  146. [float]
  147. [[cluster-name]]
  148. ==== Cluster name
  149. Also, don't forget to give your production cluster a name, which is used
  150. to discover and auto-join other nodes:
  151. [source,yaml]
  152. --------------------------------------------------
  153. cluster:
  154. name: <NAME OF YOUR CLUSTER>
  155. --------------------------------------------------
  156. Make sure that you don't reuse the same cluster names in different
  157. environments, otherwise you might end up with nodes joining the wrong cluster.
  158. For instance you could use `logging-dev`, `logging-stage`, and `logging-prod`
  159. for the development, staging, and production clusters.
  160. [float]
  161. [[node-name]]
  162. ==== Node name
  163. You may also want to change the default node name for each node to
  164. something like the display hostname. By default Elasticsearch will
  165. randomly pick a Marvel character name from a list of around 3000 names
  166. when your node starts up.
  167. [source,yaml]
  168. --------------------------------------------------
  169. node:
  170. name: <NAME OF YOUR NODE>
  171. --------------------------------------------------
  172. The hostname of the machine is provided in the environment
  173. variable `HOSTNAME`. If on your machine you only run a
  174. single elasticsearch node for that cluster, you can set
  175. the node name to the hostname using the `${...}` notation:
  176. [source,yaml]
  177. --------------------------------------------------
  178. node:
  179. name: ${HOSTNAME}
  180. --------------------------------------------------
  181. Internally, all settings are collapsed into "namespaced" settings. For
  182. example, the above gets collapsed into `node.name`. This means that
  183. its easy to support other configuration formats, for example,
  184. http://www.json.org[JSON]. If JSON is a preferred configuration format,
  185. simply rename the `elasticsearch.yml` file to `elasticsearch.json` and
  186. add:
  187. [float]
  188. [[styles]]
  189. ==== Configuration styles
  190. [source,yaml]
  191. --------------------------------------------------
  192. {
  193. "network" : {
  194. "host" : "10.0.0.4"
  195. }
  196. }
  197. --------------------------------------------------
  198. It also means that its easy to provide the settings externally either
  199. using the `ES_JAVA_OPTS` or as parameters to the `elasticsearch`
  200. command, for example:
  201. [source,sh]
  202. --------------------------------------------------
  203. $ elasticsearch -Des.network.host=10.0.0.4
  204. --------------------------------------------------
  205. Another option is to set `es.default.` prefix instead of `es.` prefix,
  206. which means the default setting will be used only if not explicitly set
  207. in the configuration file.
  208. Another option is to use the `${...}` notation within the configuration
  209. file which will resolve to an environment setting, for example:
  210. [source,js]
  211. --------------------------------------------------
  212. {
  213. "network" : {
  214. "host" : "${ES_NET_HOST}"
  215. }
  216. }
  217. --------------------------------------------------
  218. Additionally, for settings that you do not wish to store in the configuration
  219. file, you can use the value `${prompt.text}` or `${prompt.secret}` and start
  220. Elasticsearch in the foreground. `${prompt.secret}` has echoing disabled so
  221. that the value entered will not be shown in your terminal; `${prompt.text}`
  222. will allow you to see the value as you type it in. For example:
  223. [source,yaml]
  224. --------------------------------------------------
  225. node:
  226. name: ${prompt.text}
  227. --------------------------------------------------
  228. On execution of the `elasticsearch` command, you will be prompted to enter
  229. the actual value like so:
  230. [source,sh]
  231. --------------------------------------------------
  232. Enter value for [node.name]:
  233. --------------------------------------------------
  234. NOTE: Elasticsearch will not start if `${prompt.text}` or `${prompt.secret}`
  235. is used in the settings and the process is run as a service or in the background.
  236. The location of the configuration file can be set externally using a
  237. system property:
  238. [source,sh]
  239. --------------------------------------------------
  240. $ elasticsearch -Des.config=/path/to/config/file
  241. --------------------------------------------------
  242. [float]
  243. [[configuration-index-settings]]
  244. === Index Settings
  245. Indices created within the cluster can provide their own settings. For
  246. example, the following creates an index with memory based storage
  247. instead of the default file system based one (the format can be either
  248. YAML or JSON):
  249. [source,sh]
  250. --------------------------------------------------
  251. $ curl -XPUT http://localhost:9200/kimchy/ -d \
  252. '
  253. index:
  254. refresh_interval: 5s
  255. '
  256. --------------------------------------------------
  257. Index level settings can be set on the node level as well, for example,
  258. within the `elasticsearch.yml` file, the following can be set:
  259. [source,yaml]
  260. --------------------------------------------------
  261. index :
  262. refresh_interval: 5s
  263. --------------------------------------------------
  264. This means that every index that gets created on the specific node
  265. started with the mentioned configuration will store the index in memory
  266. *unless the index explicitly sets it*. In other words, any index level
  267. settings override what is set in the node configuration. Of course, the
  268. above can also be set as a "collapsed" setting, for example:
  269. [source,sh]
  270. --------------------------------------------------
  271. $ elasticsearch -Des.index.refresh_interval=5s
  272. --------------------------------------------------
  273. All of the index level configuration can be found within each
  274. <<index-modules,index module>>.
  275. [float]
  276. [[logging]]
  277. === Logging
  278. Elasticsearch uses an internal logging abstraction and comes, out of the
  279. box, with http://logging.apache.org/log4j/1.2/[log4j]. It tries to simplify
  280. log4j configuration by using http://www.yaml.org/[YAML] to configure it,
  281. and the logging configuration file is `config/logging.yml`. The
  282. http://en.wikipedia.org/wiki/JSON[JSON] and
  283. http://en.wikipedia.org/wiki/.properties[properties] formats are also
  284. supported. Multiple configuration files can be loaded, in which case they will
  285. get merged, as long as they start with the `logging.` prefix and end with one
  286. of the supported suffixes (either `.yml`, `.yaml`, `.json` or `.properties`).
  287. The logger section contains the java packages and their corresponding log
  288. level, where it is possible to omit the `org.elasticsearch` prefix. The
  289. appender section contains the destinations for the logs. Extensive information
  290. on how to customize logging and all the supported appenders can be found on
  291. the http://logging.apache.org/log4j/1.2/manual.html[log4j documentation].
  292. Additional Appenders and other logging classes provided by
  293. http://logging.apache.org/log4j/extras/[log4j-extras] are also available,
  294. out of the box.
  295. [float]
  296. [[deprecation-logging]]
  297. ==== Deprecation logging
  298. In addition to regular logging, Elasticsearch allows you to enable logging
  299. of deprecated actions. For example this allows you to determine early, if
  300. you need to migrate certain functionality in the future. By default,
  301. deprecation logging is disabled. You can enable it in the `config/logging.yml`
  302. file by setting the deprecation log level to `DEBUG`.
  303. [source,yaml]
  304. --------------------------------------------------
  305. deprecation: DEBUG, deprecation_log_file
  306. --------------------------------------------------
  307. This will create a daily rolling deprecation log file in your log directory.
  308. Check this file regularly, especially when you intend to upgrade to a new
  309. major version.