2013-08-28 19:24:34 -04:00
[[setup-configuration]]
== Configuration
[float]
=== Environment Variables
2014-01-06 15:58:46 -05:00
Within the scripts, Elasticsearch comes with built in `JAVA_OPTS` passed
2013-08-28 19:24:34 -04:00
to the JVM started. The most important setting for that is the `-Xmx` to
control the maximum allowed memory for the process, and `-Xms` to
control the minimum allocated memory for the process (_in general, the
more memory allocated to the process, the better_).
Most times it is better to leave the default `JAVA_OPTS` as they are,
and use the `ES_JAVA_OPTS` environment variable in order to set / change
JVM settings or arguments.
The `ES_HEAP_SIZE` environment variable allows to set the heap memory
that will be allocated to elasticsearch java process. It will allocate
the same value to both min and max values, though those can be set
explicitly (not recommended) by setting `ES_MIN_MEM` (defaults to
2014-07-10 17:34:35 -04:00
`256m`), and `ES_MAX_MEM` (defaults to `1g`).
2013-08-28 19:24:34 -04:00
It is recommended to set the min and max memory to the same value, and
enable <<setup-configuration-memory,`mlockall`>>.
[float]
2013-09-25 12:17:40 -04:00
[[system]]
2013-08-28 19:24:34 -04:00
=== System Configuration
[float]
2013-09-25 12:17:40 -04:00
[[file-descriptors]]
2013-08-28 19:24:34 -04:00
==== File Descriptors
Make sure to increase the number of open files descriptors on the
machine (or for the user running elasticsearch). Setting it to 32k or
even 64k is recommended.
2016-02-21 22:48:14 -05:00
You can retrieve the `max_file_descriptors` for each node
2013-10-17 05:54:36 -04:00
using the <<cluster-nodes-info>> API, with:
[source,js]
--------------------------------------------------
2016-01-14 14:21:36 -05:00
curl localhost:9200/_nodes/stats/process?pretty
2013-10-17 05:54:36 -04:00
--------------------------------------------------
2014-06-12 07:56:06 -04:00
[float]
[[vm-max-map-count]]
==== Virtual memory
2014-06-26 16:46:21 -04:00
Elasticsearch uses a <<default_fs,`hybrid mmapfs / niofs`>> directory by default to store its indices. The default
2014-06-12 07:56:06 -04:00
operating system limits on mmap counts is likely to be too low, which may
result in out of memory exceptions. On Linux, you can increase the limits by
running the following command as `root`:
2015-07-14 12:14:09 -04:00
[source,sh]
2014-06-12 07:56:06 -04:00
-------------------------------------
sysctl -w vm.max_map_count=262144
-------------------------------------
To set this value permanently, update the `vm.max_map_count` setting in
`/etc/sysctl.conf`.
2013-10-17 05:54:36 -04:00
2014-11-21 15:41:06 -05:00
NOTE: If you installed Elasticsearch using a package (.deb, .rpm) this setting will be changed automatically. To verify, run `sysctl vm.max_map_count`.
2013-09-30 17:32:00 -04:00
[float]
[[setup-configuration-memory]]
2013-08-28 19:24:34 -04:00
==== Memory Settings
2015-06-05 08:41:08 -04:00
Most operating systems try to use as much memory as possible for file system
caches and eagerly swap out unused application memory, possibly resulting
2014-05-14 10:01:25 -04:00
in the elasticsearch process being swapped. Swapping is very bad for
performance and for node stability, so it should be avoided at all costs.
There are three options:
* **Disable swap**
+
--
The simplest option is to completely disable swap. Usually Elasticsearch
is the only service running on a box, and its memory usage is controlled
by the `ES_HEAP_SIZE` environment variable. There should be no need
2015-06-05 08:41:08 -04:00
to have swap enabled.
On Linux systems, you can disable swap temporarily
2014-05-14 10:01:25 -04:00
by running: `sudo swapoff -a`. To disable it permanently, you will need
to edit the `/etc/fstab` file and comment out any lines that contain the
word `swap`.
2015-06-05 08:41:08 -04:00
On Windows, the equivalent can be achieved by disabling the paging file entirely
via `System Properties → Advanced → Performance → Advanced → Virtual memory`.
2014-05-14 10:01:25 -04:00
--
* **Configure `swappiness`**
+
--
The second option is to ensure that the sysctl value `vm.swappiness` is set
2014-05-02 04:44:26 -04:00
to `0`. This reduces the kernel's tendency to swap and should not lead to
swapping under normal circumstances, while still allowing the whole system
to swap in emergency conditions.
2014-05-14 10:01:25 -04:00
NOTE: From kernel version 3.5-rc1 and above, a `swappiness` of `0` will
cause the OOM killer to kill the process instead of allowing swapping.
You will need to set `swappiness` to `1` to still allow swapping in
emergencies.
--
2014-05-02 04:44:26 -04:00
2014-05-14 10:01:25 -04:00
* **`mlockall`**
+
--
2015-06-05 08:41:08 -04:00
The third option is to use
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
2014-05-14 10:01:25 -04:00
try to lock the process address space into RAM, preventing any Elasticsearch
memory from being swapped out. This can be done, by adding this line
to the `config/elasticsearch.yml` file:
2014-05-02 04:44:26 -04:00
2014-05-14 10:01:25 -04:00
[source,yaml]
--------------
bootstrap.mlockall: true
--------------
After starting Elasticsearch, you can see whether this setting was applied
successfully by checking the value of `mlockall` in the output from this
request:
[source,sh]
--------------
curl http://localhost:9200/_nodes/process?pretty
--------------
2016-02-09 05:07:32 -05:00
If you see that `mlockall` is `false`, then it means that the `mlockall`
2015-06-05 08:41:08 -04:00
request has failed. The most probable reason, on Linux/Unix systems, is that
2015-06-19 12:33:44 -04:00
the user running Elasticsearch doesn't have permission to lock memory. This can
2015-06-05 08:41:08 -04:00
be granted by running `ulimit -l unlimited` as `root` before starting Elasticsearch.
2014-05-14 10:01:25 -04:00
Another possible reason why `mlockall` can fail is that the temporary directory
(usually `/tmp`) is mounted with the `noexec` option. This can be solved by
2015-05-05 04:03:15 -04:00
specifying a new temp directory, by starting Elasticsearch with:
2014-05-14 10:01:25 -04:00
[source,sh]
--------------
./bin/elasticsearch -Djna.tmpdir=/path/to/new/dir
--------------
WARNING: `mlockall` might cause the JVM or shell session to exit if it tries
to allocate more memory than is available!
--
2013-08-28 19:24:34 -04:00
[float]
2013-09-25 12:17:40 -04:00
[[settings]]
2013-08-28 19:24:34 -04:00
=== Elasticsearch Settings
*elasticsearch* configuration files can be found under `ES_HOME/config`
folder. The folder comes with two files, the `elasticsearch.yml` for
2014-01-06 15:58:46 -05:00
configuring Elasticsearch different
2013-08-28 19:24:34 -04:00
<<modules,modules>>, and `logging.yml` for
2014-01-06 15:58:46 -05:00
configuring the Elasticsearch logging.
2013-08-28 19:24:34 -04:00
The configuration format is http://www.yaml.org/[YAML]. Here is an
example of changing the address all network based modules will use to
bind and publish to:
2013-10-17 05:54:36 -04:00
[source,yaml]
2013-08-28 19:24:34 -04:00
--------------------------------------------------
network :
host : 10.0.0.4
--------------------------------------------------
[float]
2013-09-25 12:17:40 -04:00
[[paths]]
2013-08-28 19:24:34 -04:00
==== Paths
In production use, you will almost certainly want to change paths for
data and log files:
2013-10-17 05:54:36 -04:00
[source,yaml]
2013-08-28 19:24:34 -04:00
--------------------------------------------------
path:
logs: /var/log/elasticsearch
data: /var/data/elasticsearch
--------------------------------------------------
[float]
2013-09-25 12:17:40 -04:00
[[cluster-name]]
2013-08-28 19:24:34 -04:00
==== Cluster name
Also, don't forget to give your production cluster a name, which is used
to discover and auto-join other nodes:
2013-10-17 05:54:36 -04:00
[source,yaml]
2013-08-28 19:24:34 -04:00
--------------------------------------------------
cluster:
name: <NAME OF YOUR CLUSTER>
--------------------------------------------------
2015-06-19 12:33:44 -04:00
Make sure that you don't reuse the same cluster names in different
environments, otherwise you might end up with nodes joining the wrong cluster.
For instance you could use `logging-dev`, `logging-stage`, and `logging-prod`
for the development, staging, and production clusters.
2013-08-28 19:24:34 -04:00
[float]
2013-09-25 12:17:40 -04:00
[[node-name]]
2013-08-28 19:24:34 -04:00
==== Node name
You may also want to change the default node name for each node to
2014-01-06 15:58:46 -05:00
something like the display hostname. By default Elasticsearch will
2013-08-28 19:24:34 -04:00
randomly pick a Marvel character name from a list of around 3000 names
when your node starts up.
2013-10-17 05:54:36 -04:00
[source,yaml]
2013-08-28 19:24:34 -04:00
--------------------------------------------------
node:
name: <NAME OF YOUR NODE>
--------------------------------------------------
2015-04-17 04:24:50 -04:00
The hostname of the machine is provided in the environment
variable `HOSTNAME`. If on your machine you only run a
single elasticsearch node for that cluster, you can set
the node name to the hostname using the `${...}` notation:
2015-02-06 15:23:59 -05:00
[source,yaml]
--------------------------------------------------
node:
name: ${HOSTNAME}
--------------------------------------------------
2013-08-28 19:24:34 -04:00
Internally, all settings are collapsed into "namespaced" settings. For
2013-12-22 13:32:09 -05:00
example, the above gets collapsed into `node.name`. This means that
2013-08-28 19:24:34 -04:00
its easy to support other configuration formats, for example,
http://www.json.org[JSON]. If JSON is a preferred configuration format,
simply rename the `elasticsearch.yml` file to `elasticsearch.json` and
add:
[float]
2013-09-25 12:17:40 -04:00
[[styles]]
2013-08-28 19:24:34 -04:00
==== Configuration styles
2013-10-17 05:54:36 -04:00
[source,yaml]
2013-08-28 19:24:34 -04:00
--------------------------------------------------
{
"network" : {
"host" : "10.0.0.4"
}
}
--------------------------------------------------
It also means that its easy to provide the settings externally either
using the `ES_JAVA_OPTS` or as parameters to the `elasticsearch`
command, for example:
2013-10-17 05:54:36 -04:00
[source,sh]
2013-08-28 19:24:34 -04:00
--------------------------------------------------
2013-12-15 14:29:11 -05:00
$ elasticsearch -Des.network.host=10.0.0.4
2013-08-28 19:24:34 -04:00
--------------------------------------------------
Another option is to set `es.default.` prefix instead of `es.` prefix,
which means the default setting will be used only if not explicitly set
in the configuration file.
Another option is to use the `${...}` notation within the configuration
file which will resolve to an environment setting, for example:
[source,js]
--------------------------------------------------
{
"network" : {
"host" : "${ES_NET_HOST}"
}
}
--------------------------------------------------
2015-04-30 13:14:05 -04:00
Additionally, for settings that you do not wish to store in the configuration
2015-06-06 10:41:07 -04:00
file, you can use the value `${prompt.text}` or `${prompt.secret}` and start
Elasticsearch in the foreground. `${prompt.secret}` has echoing disabled so
that the value entered will not be shown in your terminal; `${prompt.text}`
2015-04-30 13:14:05 -04:00
will allow you to see the value as you type it in. For example:
[source,yaml]
--------------------------------------------------
node:
2015-06-06 10:41:07 -04:00
name: ${prompt.text}
2015-04-30 13:14:05 -04:00
--------------------------------------------------
On execution of the `elasticsearch` command, you will be prompted to enter
the actual value like so:
[source,sh]
--------------------------------------------------
Enter value for [node.name]:
--------------------------------------------------
2015-06-06 10:41:07 -04:00
NOTE: Elasticsearch will not start if `${prompt.text}` or `${prompt.secret}`
2015-04-30 13:14:05 -04:00
is used in the settings and the process is run as a service or in the background.
2013-08-28 19:24:34 -04:00
[float]
2013-09-30 17:32:00 -04:00
[[configuration-index-settings]]
2013-08-28 19:24:34 -04:00
=== Index Settings
Indices created within the cluster can provide their own settings. For
2016-03-02 04:50:18 -05:00
example, the following creates an index with a refresh interval of 5
seconds instead of the default refresh interval (the format can be either
2013-08-28 19:24:34 -04:00
YAML or JSON):
2013-10-17 05:54:36 -04:00
[source,sh]
2013-08-28 19:24:34 -04:00
--------------------------------------------------
$ curl -XPUT http://localhost:9200/kimchy/ -d \
'
2015-08-10 04:41:11 -04:00
index:
refresh_interval: 5s
2013-08-28 19:24:34 -04:00
'
--------------------------------------------------
Index level settings can be set on the node level as well, for example,
within the `elasticsearch.yml` file, the following can be set:
2013-10-17 05:54:36 -04:00
[source,yaml]
2013-08-28 19:24:34 -04:00
--------------------------------------------------
index :
2015-08-10 04:41:11 -04:00
refresh_interval: 5s
2013-08-28 19:24:34 -04:00
--------------------------------------------------
This means that every index that gets created on the specific node
2016-03-02 04:50:18 -05:00
started with the mentioned configuration will use a refresh interval of
5 seconds *unless the index explicitly sets it*. In other words, any
index level settings override what is set in the node configuration. Of
course, the above can also be set as a "collapsed" setting, for example:
2013-08-28 19:24:34 -04:00
2013-10-17 05:54:36 -04:00
[source,sh]
2013-08-28 19:24:34 -04:00
--------------------------------------------------
2015-08-10 04:41:11 -04:00
$ elasticsearch -Des.index.refresh_interval=5s
2013-08-28 19:24:34 -04:00
--------------------------------------------------
All of the index level configuration can be found within each
<<index-modules,index module>>.
[float]
2013-09-25 12:17:40 -04:00
[[logging]]
2013-08-28 19:24:34 -04:00
=== Logging
2014-01-06 15:58:46 -05:00
Elasticsearch uses an internal logging abstraction and comes, out of the
2014-11-12 11:39:10 -05:00
box, with http://logging.apache.org/log4j/1.2/[log4j]. It tries to simplify
2013-08-28 19:24:34 -04:00
log4j configuration by using http://www.yaml.org/[YAML] to configure it,
2014-11-12 11:39:10 -05:00
and the logging configuration file is `config/logging.yml`. The
http://en.wikipedia.org/wiki/JSON[JSON] and
http://en.wikipedia.org/wiki/.properties[properties] formats are also
2014-11-19 05:24:23 -05:00
supported. Multiple configuration files can be loaded, in which case they will
get merged, as long as they start with the `logging.` prefix and end with one
of the supported suffixes (either `.yml`, `.yaml`, `.json` or `.properties`).
The logger section contains the java packages and their corresponding log
level, where it is possible to omit the `org.elasticsearch` prefix. The
appender section contains the destinations for the logs. Extensive information
on how to customize logging and all the supported appenders can be found on
the http://logging.apache.org/log4j/1.2/manual.html[log4j documentation].
2014-11-12 11:39:10 -05:00
2015-06-19 12:33:44 -04:00
Additional Appenders and other logging classes provided by
http://logging.apache.org/log4j/extras/[log4j-extras] are also available,
2014-11-13 05:29:48 -05:00
out of the box.
2015-05-26 11:44:52 -04:00
2015-05-26 12:16:12 -04:00
[float]
[[deprecation-logging]]
2015-05-26 11:44:52 -04:00
==== Deprecation logging
In addition to regular logging, Elasticsearch allows you to enable logging
of deprecated actions. For example this allows you to determine early, if
you need to migrate certain functionality in the future. By default,
deprecation logging is disabled. You can enable it in the `config/logging.yml`
file by setting the deprecation log level to `DEBUG`.
[source,yaml]
--------------------------------------------------
deprecation: DEBUG, deprecation_log_file
--------------------------------------------------
This will create a daily rolling deprecation log file in your log directory.
Check this file regularly, especially when you intend to upgrade to a new
major version.