Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setup/sysconfig #7

Open
wants to merge 2 commits into
base: cn
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 17 additions & 23 deletions docs/reference/setup/sysconfig.asciidoc
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
[[system-config]]
== Important System Configuration
== 重要系统配置

Ideally, Elasticsearch should run alone on a server and use all of the
resources available to it. In order to do so, you need to configure your
operating system to allow the user running Elasticsearch to access more
resources than allowed by default.
理想情况下,Elasticsearch 应该在服务器上独立运行并使用所有的可用资源。
为了做到这一点,你需要配置你的操作系统,使得运行 Elasticsearch 的用户获得超过默认分配的更多资源。

The following settings *must* be considered before going to production:
在投入生产环境之前,*必须* 考虑以下设置:

* <<setup-configuration-memory,Disable swapping>>
* <<file-descriptors,Increase file descriptors>>
* <<vm-max-map-count,Ensure sufficient virtual memory>>
* <<max-number-of-threads,Ensure sufficient threads>>
* <<networkaddress-cache-ttl,JVM DNS cache settings>>
* <<setup-configuration-memory,禁用 swapping>>
* <<file-descriptors,增加文件描述符>>
* <<vm-max-map-count,确保足够的虚拟内存>>
* <<max-number-of-threads,确保足够的线程>>
* <<networkaddress-cache-ttl,JVM DNS 缓存设置>>

[[dev-vs-prod]]
[float]
=== Development mode vs production mode

By default, Elasticsearch assumes that you are working in development mode.
If any of the above settings are not configured correctly, a warning will be
written to the log file, but you will be able to start and run your
Elasticsearch node.

As soon as you configure a network setting like `network.host`, Elasticsearch
assumes that you are moving to production and will upgrade the above warnings
to exceptions. These exceptions will prevent your Elasticsearch node from
starting. This is an important safety measure to ensure that you will not
lose data because of a malconfigured server.
=== 开发模式 vs 生产模式

Elasticsearch 默认假设你工作在开发模式。如果以上任一设置配置错误,日志就会记录一条警告,
但是你还是可以启动并运行 Elasticsearch 节点。

一旦你配置了类似 `network.host` 的网络设置,Elasticsearch 会假设你正迁移到生产环境,并将上文提及的
警告升级为异常。这些异常会阻止 Elasticsearch 节点启动。
这是确保你不会因配置错误而丢失数据的一种重要安全措施。

include::sysconfig/configuring.asciidoc[]

Expand Down
76 changes: 29 additions & 47 deletions docs/reference/setup/sysconfig/configuring.asciidoc
Original file line number Diff line number Diff line change
@@ -1,63 +1,54 @@
[[setting-system-settings]]
=== Configuring system settings
=== 配置系统设置

Where to configure systems settings depends on which package you have used to
install Elasticsearch, and which operating system you are using.
在何处配置系统设置取决于你之前安装 Elasticsearch 的包类型,以及你正在使用的操作系统类型。

When using the `.zip` or `.tar.gz` packages, system settings can be configured:
当使用 `.zip` `.tar.gz` 包时,系统设置配置如下:

* temporarily with <<ulimit,`ulimit`>>, or
* permanently in <<limits.conf,`/etc/security/limits.conf`>>.
* 使用 <<ulimit,`ulimit`>> 临时生效, 或者
* <<limits.conf,`/etc/security/limits.conf`>> 永久生效。

When using the RPM or Debian packages, most system settings are set in the
<<sysconfig,system configuration file>>. However, systems which use systemd
require that system limits are specified in a
<<systemd,systemd configuration file>>.
当使用 RPM 或 Debian 包时,大多数系统设置都在 <<sysconfig,system 配置文件>> 。
但是使用 systemd 的系统要求在 <<systemd,systemd 配置文件>> 中指定系统限制。

[[ulimit]]
==== `ulimit`

On Linux systems, `ulimit` can be used to change resource limits on a
temporary basis. Limits usually need to be set as `root` before switching to
the user that will run Elasticsearch. For example, to set the number of
open file handles (`ulimit -n`) to 65,536, you can do the following:
在 Linux 系统上,`ulimit` 可用于临时改变资源。在切换为运行 Elasticsearch 的用户前,通常需要 `root` 权限。
例如,设置打开文件句柄( `ulimit -n` )数为 65,536,你可以这样做:

[source,sh]
--------------------------------
sudo su <1>
ulimit -n 65536 <2>
su elasticsearch <3>
--------------------------------
<1> Become `root`.
<2> Change the max number of open files.
<3> Become the `elasticsearch` user in order to start Elasticsearch.
<1> 切换 `root`.
<2> 改变最大打开文件数。
<3> 切换 `elasticsearch` 用户用于启动 Elasticsearch

The new limit is only applied during the current session.
新的 limit 仅适用于当前会话。

You can consult all currently applied limits with `ulimit -a`.
您可以使用 `ulimit -a` 查询所有当前应用的 limits。

[[limits.conf]]
==== `/etc/security/limits.conf`

On Linux systems, persistent limits can be set for a particular user by
editing the `/etc/security/limits.conf` file. To set the maximum number of
open files for the `elasticsearch` user to 65,536, add the following line to
the `limits.conf` file:
在 Linux 系统上,可以通过编辑 `/etc/security/limits.conf` 文件来为指定用户设置固定 limits。
为了将 `elasticsearch` 用户最大打开文件数设为 65,536,可在 `limits.conf` 文件中添加以下行:


[source,sh]
--------------------------------
elasticsearch - nofile 65536
--------------------------------

This change will only take effect the next time the `elasticsearch` user opens
a new session.
此更改仅在 `elasticsearch` 用户开启新 session 时生效。

[NOTE]
.Ubuntu and `limits.conf`
.Ubuntu `limits.conf`
===============================
Ubuntu ignores the `limits.conf` file for processes started by `init.d`. To
enable the `limits.conf` file, edit `/etc/pam.d/su` and uncomment the
following line:
Ubuntu 忽略由 `init.d` 启动进程的 `limits.conf` 文件。 为了启用 `limits.conf` 文件,请编辑 `/etc/pam.d/su` 并取消以下行注释:

[source,sh]
--------------------------------
Expand All @@ -66,42 +57,33 @@ following line:
===============================

[[sysconfig]]
==== Sysconfig file
==== Sysconfig 文件

When using the RPM or Debian packages, system settings and environment
variables can be specified in the system configuration file, which is located
in:
使用 RPM 或 Debian 包时,系统设置和环境变量可由位于以下路径的系统配置文件指定:

[horizontal]
RPM:: `/etc/sysconfig/elasticsearch`
Debian:: `/etc/default/elasticsearch`

However, for systems which uses `systemd`, system limits need to be specified
via <<systemd,systemd>>.
但是,对于使用 `systemd` 的系统,需要通过 <<systemd,systemd>> 指定系统 limits。

[[systemd]]
==== Systemd configuration
==== Systemd 配置

When using the RPM or Debian packages on systems that use
https://en.wikipedia.org/wiki/Systemd[systemd], system limits must be
specified via systemd.
当 RPM 或 Debian 包使用 https://en.wikipedia.org/wiki/Systemd[systemd] 时,系统 limits 必须由 systemd 指定。

The systemd service file (`/usr/lib/systemd/system/elasticsearch.service`)
contains the limits that are applied by default.
systemd 服务文件( `/usr/lib/systemd/system/elasticsearch.service` )包含默认应用的 limits。

To override them, add a file called
`/etc/systemd/system/elasticsearch.service.d/override.conf` (alternatively,
you may run `sudo systemctl edit elasticsearch` which opens the file
automatically inside your default editor). Set any changes in this file,
such as:
要覆盖它们,请添加一个名为 `/etc/systemd/system/elasticsearch.service.d/override.conf` 的文件(或者,
你可以在你的默认编辑器中运行 `sudo systemctl edit elasticsearch` 来打开文件)。在文件中设置任何更改,例如:

[source,sh]
---------------------------------
[Service]
LimitMEMLOCK=infinity
---------------------------------

Once finished, run the following command to reload units:
一旦完成,运行如下命令重载:

[source,sh]
---------------------------------
Expand Down
22 changes: 6 additions & 16 deletions docs/reference/setup/sysconfig/dns-cache.asciidoc
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
[[networkaddress-cache-ttl]]
=== DNS cache settings
=== DNS 缓存设置

Elasticsearch runs with a security manager in place. With a security manager in
place, the JVM defaults to caching positive hostname resolutions
indefinitely. If your Elasticsearch nodes rely on DNS in an environment where
DNS resolutions vary with time (e.g., for node-to-node discovery) then you might
want to modify the default JVM behavior. This can be modified by adding
http://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html[`networkaddress.cache.ttl=<timeout>`]
to your
http://docs.oracle.com/javase/8/docs/technotes/guides/security/PolicyFiles.html[Java
security policy]. Any hosts that fail to resolve will be logged. Note also that
with the Java security manager in place, the JVM defaults to caching negative
hostname resolutions for ten seconds. This can be modified by adding
http://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html[`networkaddress.cache.negative.ttl=<timeout>`]
to your
http://docs.oracle.com/javase/8/docs/technotes/guides/security/PolicyFiles.html[Java
security policy].
Elasticsearch 与安全管理器一起运行。JVM 默认与安全管理器永久缓存正向主机名解析。
如果你的 Elasticsearch 节点依赖的 DNS 解析随时变化(例如,node-to-node 发现)。
那么你可能会想修改默认 JVM 行为。这可以通过向 http://docs.oracle.com/javase/8/docs/technotes/guides/security/PolicyFiles.html[Java 安全策略] 添加 http://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html[`networkaddress.cache.ttl=<timeout>`] 修改。
任何未能解析的主机都将被记录。还请注意使用 Java 安全管理器时 JVM 默认缓存负向主机名解析十秒钟。这可以通过向
http://docs.oracle.com/javase/8/docs/technotes/guides/security/PolicyFiles.html[Java 安全策略] 添加 http://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html[`networkaddress.cache.negative.ttl=<timeout>`] 修改。
27 changes: 9 additions & 18 deletions docs/reference/setup/sysconfig/file-descriptors.asciidoc
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
[[file-descriptors]]
=== File Descriptors
=== 文件描述符

[NOTE]
This is only relevant for Linux and macOS and can be safely ignored if running
Elasticsearch on Windows. On Windows that JVM uses an
https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx[API]
limited only by available resources.
这只适用于 Linux 和 MacOS ,如果在 Windows 上 运行 Elasticsearch 则可以安全地忽略。
在 Windows 上 JVM 使用一个仅受可用资源限制的 https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx[API] 。

Elasticsearch uses a lot of file descriptors or file handles. Running out of
file descriptors can be disastrous and will most probably lead to data loss.
Make sure to increase the limit on the number of open files descriptors for
the user running Elasticsearch to 65,536 or higher.
Elasticsearch 使用大量文件描述符或文件句柄。 用尽文件描述符是灾难性的,并且很可能导致数据丢失。
确保为 Elasticsearch 运行用户提高打开文件描述符数量为 65,536 或更高。

For the `.zip` and `.tar.gz` packages, set <<ulimit,`ulimit -n 65536`>> as
root before starting Elasticsearch, or set `nofile` to `65536` in
<<limits.conf,`/etc/security/limits.conf`>>.
对于 `.zip` 和 `.tar.gz` 包,在运行 Elasticsearch 前以 root 设置 <<ulimit,`ulimit -n 65536`>> ,或者设置<<limits.conf,`/etc/security/limits.conf`>> 里的 `nofile` 为 `65536` 。

On macOS, you must also pass the JVM option `-XX:-MaxFDLimit`
to Elasticsearch in order for it to make use of the higher file descriptor limit.
对于 macOS,你必须向 Elasticsearch JVM 传递 `-XX:-MaxFDLimit` 选项以便使用更多的文件描述符。

RPM and Debian packages already default the maximum number of file
descriptors to 65536 and do not require further configuration.
RPM 和 Debian 包默认最大文件描述符为 65536,因此不需要进一步配置。

You can check the `max_file_descriptors` configured for each node
using the <<cluster-nodes-stats>> API, with:
您可以使用 <<cluster-nodes-stats>> API 检查每个节点配置的 `max_file_descriptors` :

[source,js]
--------------------------------------------------
Expand Down
89 changes: 31 additions & 58 deletions docs/reference/setup/sysconfig/swap.asciidoc
Original file line number Diff line number Diff line change
@@ -1,108 +1,81 @@
[[setup-configuration-memory]]
=== Disable swapping
=== 禁用 swapping

Most operating systems try to use as much memory as possible for file system
caches and eagerly swap out unused application memory. This can result in parts
of the JVM heap or even its executable pages being swapped out to disk.
大多数操作系统尝试让文件系统缓存用尽可能多的内存,并急切地换出未使用的应用内存。
这可能会导致部分 JVM 堆或其可执行页面被交换到磁盘。

Swapping is very bad for performance, for node stability, and should be avoided
at all costs. It can cause garbage collections to last for **minutes** instead
of milliseconds and can cause nodes to respond slowly or even to disconnect
from the cluster. In a resilient distributed system, it's more effective to let
the operating system kill the node.
Swapping 对性能非常不利,为了节点稳定应该不惜一切代价避免 Swapping。 这可能导致持续 **分钟** 而不是毫秒的垃圾回收,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这可能导致持续 **数分钟** 而不是数毫秒的垃圾回收

并可能导致节点响应缓慢甚至集群连接断开。在弹性分布式系统中,这很容易让操作系统杀死节点。

There are three approaches to disabling swapping. The preferred option is to
completely disable swap. If this is not an option, whether or not to prefer
minimizing swappiness versus memory locking is dependent on your environment.
有三种方法禁用 swapping。 首选是完全禁用交换。如果这不是一种选择,选择最小化 swappiness 还是内存锁定取决于你的环境。

[[disable-swap-files]]
==== Disable all swap files
==== 禁用所有文件交换

Usually Elasticsearch is the only service running on a box, and its memory usage
is controlled by the JVM options. There should be no need to have swap enabled.
通常 Elasticsearch 是机器上运行的唯一服务,它的内存使用情况由 JVM 选项控制。应该不需要启用交换。

On Linux systems, you can disable swap temporarily by running:
Linux 系统,你可以运行以下命令临时禁用交换:

[source,sh]
--------------
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`.
如果需要永久禁用,你需要编辑 `/etc/fstab` 文件并注释任何包含 `swap` 的行。

On Windows, the equivalent can be achieved by disabling the paging file entirely
via `System Properties → Advanced → Performance → Advanced → Virtual memory`.
在 Windows,可通过 `System Properties → Advanced → Performance → Advanced → Virtual memory` 禁用页文件来实现相同功能。

[[swappiness]]
==== Configure `swappiness`
==== 配置 `swappiness`

Another option available on Linux systems is to ensure that the sysctl value
`vm.swappiness` is set to `1`. 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.
Linux 系统上另一个可选项是确保 sysctl `vm.swappiness` 值设为 `1` 。这减少了内核的交换趋势,并在正常情况下不会导致交换,
但是仍然允许整个系统在紧急情况下进行 swapping。

[[bootstrap-memory_lock]]
==== Enable `bootstrap.memory_lock`
==== 启用 `bootstrap.memory_lock`

Another 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 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:
另一个选择是在 Linux/Unix 系统使用 http://opengroup.org/onlinepubs/007908799/xsh/mlockall.html[mlockall]
或在 Windows 使用 https://msdn.microsoft.com/en-us/library/windows/desktop/aa366895%28v=vs.85%29.aspx[VirtualLock]
尝试将进程地址空间锁定到 RAM 中,防止任何 Elasticsearch 内存被换出。 这可以通过在 `config/elasticsearch.yml` 文件添加以下行完成:

[source,yaml]
--------------
bootstrap.memory_lock: true
--------------

WARNING: `mlockall` might cause the JVM or shell session to exit if it tries to
allocate more memory than is available!
WARNING: `mlockall` 如果试图分配比可用内存更多的内存可能会导致 JVM 或 shell 会话退出。

After starting Elasticsearch, you can see whether this setting was applied
successfully by checking the value of `mlockall` in the output from this
request:
启动 Elasticsearch 后,你可通过检查以下请求输出中的 `mlockall` 值验证这个设置是否应用成功:

[source,js]
--------------
GET _nodes?filter_path=**.mlockall
--------------
// CONSOLE

If you see that `mlockall` is `false`, then it means that the `mlockall`
request has failed. You will also see a line with more information in the logs
with the words `Unable to lock JVM Memory`.
如果你发现 `mlockall` 是 `false` ,那这意味着 `mlockall` 请求失败。你同样可在日志看到 `Unable to lock JVM Memory` 的更多信息。

The most probable reason, on Linux/Unix systems, is that the user running
Elasticsearch doesn't have permission to lock memory. This can be granted as
follows:
Linux/Unix 系统最可能的原因是运行 Elasticsearch 的用户没有锁定内存的权限。可用以下方式授权:

`.zip` and `.tar.gz`::
`.zip` `.tar.gz`::

Set <<ulimit,`ulimit -l unlimited`>> as root before starting Elasticsearch,
or set `memlock` to `unlimited` in
<<limits.conf,`/etc/security/limits.conf`>>.
以 root启动 Elasticsearch 并设置 <<ulimit,`ulimit -l unlimited`>> ,或在 <<limits.conf,`/etc/security/limits.conf`>> 文件设置 `memlock` 为 `unlimited` 。

RPM and Debian::
RPM Debian::

Set `MAX_LOCKED_MEMORY` to `unlimited` in the
<<sysconfig,system configuration file>> (or see below for systems using
`systemd`).
在 <<sysconfig,系统配置文件>> (使用 `systemd` 的系统参考下文)设置 `MAX_LOCKED_MEMORY` 为 `unlimited` 。

Systems using `systemd`::
使用 `systemd` 系统::

Set `LimitMEMLOCK` to `infinity` in the <<systemd,systemd configuration>>.
在 <<systemd,systemd 配置>> 设置 `LimitMEMLOCK` `infinity`

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
specifying a new temp directory using the `ES_JAVA_OPTS` environment variable:
另一个 `mlockall` 失败的原因可能是临时目录(一般是 `/tmp` )使用 `noexec` 选项加载。
这可通过给 `ES_JAVA_OPTS` 环境变量指定一个新的目录解决。

[source,sh]
--------------
export ES_JAVA_OPTS="$ES_JAVA_OPTS -Djava.io.tmpdir=/path/to/temp/dir"
./bin/elasticsearch
--------------

or setting this JVM flag in the jvm.options configuration file.
或在 jvm.options 配置文件内设置这个 JVM 标志。
Loading