Elasticsearch Reference [5.2] » Setup Elasticsearch

Setup Elasticsearch edit

配置Elasticsearch


This section includes information on how to setup Elasticsearch and get it running, including:

本章节包含如何配置Elasticsearch的内容以及如何运行,具体为:

  • Downloading
  • Installing
  • Starting
  • Configuring

Supported platforms edit

支持的平台


The matrix of officially supported operating systems and JVMs is available here:  Support Matrix. Elasticsearch is tested on the listed platforms, but it is possible that it will work on other platforms too.

官方支持的操作系统以及JVMs可以查看 这里。Elasticsearch在列举的平台上都测试过了,但是在其他平台上也可能能工作。


Java (JVM) Version edit

Java虚拟机版本


Elasticsearch is built using Java, and requires at least  Java 8 in order to run. Only Oracle’s Java and the OpenJDK are supported. The same JVM version should be used on all Elasticsearch nodes and clients.

使用Java,需要至少Java8.只有Oracle Java和OpenJDK支持。Elasticsearch节点和客户端必须使用相同的JVM版本。


We recommend installing Java version  1.8.0_73 or later. Elasticsearch will refuse to start if a known-bad version of Java is used.

推荐使用1.8.0_73版本或者更新的版本。如果某个版本已经证实无法使用的话,Elasticsearch将拒绝启动。


The version of Java that Elasticsearch will use can be configured by setting the  JAVA_HOMEenvironment variable.

Java版本可以通过设置JAVA_HOME来设置需要的java版本

Note

Elasticsearch ships with default configuration for running Elasticsearch on 64-bit server JVMs. If you are using a 32-bit client JVM, you must remove  -server from  jvm.optionsand if you are using any 32-bit JVM you should reconfigure the thread stack size from  -Xss1m to  -Xss320k.

Elasticsearch默认使用64位JVMs。如果你使用32位客户端JVM,你必须从jvm.options中移除-server,如果你使用任何32位JVM,你应该重新配置线程栈尺寸,从-Xss1m变为-Xss320k



Installing Elasticsearchedit

Elasticsearch is provided in the following package formats:

zip/tar.gz

The zip and tar.gz packages are suitable for installation on any system and are the easiest choice for getting started with Elasticsearch.

Install Elasticsearch with .zip or .tar.gz or Install Elasticsearch on Windows

deb

The deb package is suitable for Debian, Ubuntu, and other Debian-based systems. Debian packages may be downloaded from the Elasticsearch website or from our Debian repository.

Install Elasticsearch with Debian Package

rpm

The rpm package is suitable for installation on Red Hat, Centos, SLES, OpenSuSE and other RPM-based systems. RPMs may be downloaded from the Elasticsearch website or from our RPM repository.

Install Elasticsearch with RPM

docker

An image is available for running Elasticsearch as a Docker container. It ships with X-Pack pre-installed and may be downloaded from the Elastic Docker Registry.

Install Elasticsearch with Docker

Configuration Management Toolsedit

We also provide the following configuration management tools to help with large deployments:

Puppet

puppet-elasticsearch

Chef

cookbook-elasticsearch

Ansible

ansible-elasticsearch





Install Elasticsearch with .zip or .tar.gzedit

Elasticsearch is provided as a .zip and as a .tar.gz package. These packages can be used to install Elasticsearch on any system and are the easiest package format to use when trying out Elasticsearch.

The latest stable version of Elasticsearch can be found on the Download Elasticsearch page. Other versions can be found on the Past Releases page.

Note

Elasticsearch requires Java 8 or later. Use the official Oracle distribution or an open-source distribution such as OpenJDK.

Download and install the .zip packageedit

The .zip archive for Elasticsearch v5.2.1 can be downloaded and installed as follows:

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.2.1.zip
sha1sum elasticsearch-5.2.1.zip unzip elasticsearch-5.2.1.zip cd elasticsearch-5.2.1/ 

Compare the SHA produced by sha1sum or shasum with the published SHA.

This directory is known as $ES_HOME.

Download and install the .tar.gz packageedit

The .tar.gz archive for Elasticsearch v5.2.1 can be downloaded and installed as follows:

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.2.1.tar.gz
sha1sum elasticsearch-5.2.1.tar.gz  tar -xzf elasticsearch-5.2.1.tar.gz cd elasticsearch-5.2.1/

Compare the SHA produced by sha1sum or shasum with the published SHA.

This directory is known as $ES_HOME.

Running Elasticsearch from the command lineedit

Elasticsearch can be started from the command line as follows:

./bin/elasticsearch

By default, Elasticsearch runs in the foreground, prints its logs to the standard output (stdout), and can be stopped by pressing Ctrl-C.

Checking that Elasticsearch is runningedit

You can test that your Elasticsearch node is running by sending an HTTP request to port 9200 on localhost:

GET /
COPY AS CURL VIEW IN CONSOLE  

which should give you a response something like this:

{"name":"Cp8oag6","cluster_name":"elasticsearch","cluster_uuid":"AT69_T_DTp-1qgIJlatQqA","version":{"number":"5.2.1","build_hash":"f27399d","build_date":"2016-03-30T09:51:41.449Z","build_snapshot":false,"lucene_version":"6.4.1"},"tagline":"You Know, for Search"} 

Log printing to stdout can be disabled using the -q or --quiet option on the command line.

Running as a daemonedit

To run Elasticsearch as a daemon, specify -d on the command line, and record the process ID in a file using the -p option:

./bin/elasticsearch -d -p pid

Log messages can be found in the $ES_HOME/logs/ directory.

To shut down Elasticsearch, kill the process ID recorded in the pid file:

kill `cat pid`
Note

The startup scripts provided in the RPM and Debian packages take care of starting and stopping the Elasticsearch process for you.

Configuring Elasticsearch on the command lineedit

Elasticsearch loads its configuration from the $ES_HOME/config/elasticsearch.yml file by default. The format of this config file is explained in Configuring Elasticsearch.

Any settings that can be specified in the config file can also be specified on the command line, using the -E syntax as follows:

./bin/elasticsearch -d -Ecluster.name=my_cluster -Enode.name=node_1
Tip

Typically, any cluster-wide settings (like cluster.name) should be added to the elasticsearch.yml config file, while any node-specific settings such as node.namecould be specified on the command line.

Directory layout of .zip and .tar.gz archivesedit

The .zip and .tar.gz packages are entirely self-contained. All files and directories are, by default, contained within $ES_HOME — the directory created when unpacking the archive.

This is very convenient because you don’t have to create any directories to start using Elasticsearch, and uninstalling Elasticsearch is as easy as removing the $ES_HOME directory. However, it is advisable to change the default locations of the config directory, the data directory, and the logs directory so that you do not delete important data later on.

Type  Description  Default Location  Setting

home

Elasticsearch home directory or $ES_HOME

Directory created by unpacking the archive

bin

Binary scripts including elasticsearch to start a node and elasticsearch-plugin to install plugins

$ES_HOME/bin

conf

Configuration files including elasticsearch.yml

$ES_HOME/config

path.conf

data

The location of the data files of each index / shard allocated on the node. Can hold multiple locations.

$ES_HOME/data

path.data

logs

Log files location.

$ES_HOME/logs

path.logs

plugins

Plugin files location. Each plugin will be contained in a subdirectory.

$ES_HOME/plugins

repo

Shared file system repository locations. Can hold multiple locations. A file system repository can be placed in to any subdirectory of any directory specified here.

Not configured

path.repo

script

Location of script files.

$ES_HOME/scripts

path.scripts

Next stepsedit

You now have a test Elasticsearch environment set up. Before you start serious development or go into production with Elasticsearch, you will need to do some additional setup:

  • Learn how to configure Elasticsearch.
  • Configure important Elasticsearch settings.
  • Configure important system settings.




Install Elasticsearch with Dockeredit

Elasticsearch is also available as a Docker image. The image is built with X-Pack.

Security noteedit

Note

X-Pack is preinstalled in this image. Please take a few minutes to familiarize yourself with X-Pack Security and how to change default passwords. The default password for the elastic user is changeme.

Note

X-Pack includes a trial license for 30 days. After that, you can obtain one of the available subscriptions or disable Security. The Basic license is free and includes the Monitoring extension.

Obtaining Elasticsearch for Docker is as simple as issuing a docker pull command against the Elastic Docker registry.

The Docker image can be retrieved with the following command:

docker pull docker.elastic.co/elasticsearch/elasticsearch:5.2.1

Running Elasticsearch from the command lineedit

Development modeedit

Elasticsearch can be quickly started for development or testing use with the following command:

docker run -p 9200:9200-e "http.host=0.0.0.0"-e "transport.host=127.0.0.1" docker.elastic.co/elasticsearch/elasticsearch:5.2.1 

Production modeedit

Important

The vm_max_map_count kernel setting needs to be set to at least 262144 for production use. Depending on your platform:

  • Linux

    The vm_map_max_count setting should be set permanently in /etc/sysctl.conf:

    $ grep vm.max_map_count /etc/sysctl.conf
    vm.max_map_count=262144
    

    To apply the setting on a live system type: sysctl -w vm.max_map_count=262144

  • OSX with Docker for Mac

    The vm_max_map_count setting must be set within the xhyve virtual machine:

    $ screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
    

    Log in with root and no password. Then configure the sysctl setting as you would for Linux:

    sysctl -w vm.max_map_count=262144
    
  • OSX with Docker Toolbox

    The vm_max_map_count setting must be set via docker-machine:

    docker-machine ssh
    sudo sysctl -w vm.max_map_count=262144
    

The following example brings up a cluster comprising two Elasticsearch nodes. To bring up the cluster, use the docker-compose.yml and just type:

docker-compose up
Note

docker-compose is not pre-installed with Docker on Linux. Instructions for installing it can be found on the docker-compose webpage.

The node elasticsearch1 listens on localhost:9200 while elasticsearch2 talks to elasticsearch1 over a Docker network.

This example also uses Docker named volumes, called esdata1 and esdata2 which will be created if not already present.

docker-compose.yml:

version: '2'services: elasticsearch1: image: docker.elastic.co/elasticsearch/elasticsearch:5.2.1
    container_name: elasticsearch1
    environment:
- cluster.name=docker-cluster - bootstrap.memory_lock=true -"ES_JAVA_OPTS=-Xms512m -Xmx512m"ulimits: memlock: soft: -1 hard: -1 nofile: soft: 65536 hard: 65536 mem_limit: 1g cap_add: - IPC_LOCK volumes: - esdata1:/usr/share/elasticsearch/data ports: - 9200:9200 networks: - esnet elasticsearch2: image: docker.elastic.co/elasticsearch/elasticsearch:5.2.1 environment: - cluster.name=docker-cluster - bootstrap.memory_lock=true -"ES_JAVA_OPTS=-Xms512m -Xmx512m"-"discovery.zen.ping.unicast.hosts=elasticsearch1"ulimits: memlock: soft: -1 hard: -1 nofile: soft: 65536 hard: 65536 mem_limit: 1g cap_add: - IPC_LOCK volumes: - esdata2:/usr/share/elasticsearch/data networks: - esnet volumes: esdata1: driver: local esdata2: driver: local networks: esnet: driver: bridge 

To stop the cluster, type docker-compose down. Data volumes will persist, so it’s possible to start the cluster again with the same data using docker-compose up. To destroy the cluster and the data volumes just type docker-compose down -v.

Inspect status of cluster:edit

curl -u elastic http://127.0.0.1:9200/_cat/health
Enter host password for user 'elastic':147222592915:38:49 docker-cluster green 22420000-100.0% 
COPY AS CURL VIEW IN CONSOLE  

Log messages go to the console and are handled by the configured Docker logging driver. By default you can access logs with docker logs.

Configuring Elasticsearch with Dockeredit

Elasticsearch loads its configuration from files under /usr/share/elasticsearch/config/. These configuration files are documented in Configuring Elasticsearch and Setting JVM options.

The image offers several methods for configuring Elasticsearch settings with the conventional approach being to provide customized files, i.e. elasticsearch.yml, but it’s also possible to use environment variables to set options:

A. Present the parameters via Docker environment variablesedit

For example, to define the cluster name with docker run you can pass -e "cluster.name=mynewclustername". Double quotes are required.

Note

There is a difference between defining default settings and normal settings. The former are prefixed with default. and cannot override normal settings, if defined.

B. Bind-mounted configurationedit

Create your custom config file and mount this over the image’s corresponding file. For example, bind-mounting a custom_elasticsearch.yml with docker run can be accomplished with the parameter:

-v full_path_to/custom_elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
Important

custom_elasticsearch.yml should be readable by uid:gid 1000:1000

C. Customized imageedit

In some environments, it may make more sense to prepare a custom image containing your configuration. A Dockerfile to achieve this may be as simple as:

FROM docker.elastic.co/elasticsearch/elasticsearch:5.2.1
ADD elasticsearch.yml /usr/share/elasticsearch/config/
USER root
chown elasticsearch:elasticsearch config/elasticsearch.yml
USER elasticsearch

You could then build and try the image with something like:

docker build --tag=elasticsearch-custom .
docker run -ti -v /usr/share/elasticsearch/data elasticsearch-custom

D. Override the image’s default CMDedit

Options can be passed as command-line options to the Elasticsearch process by overriding the default command for the image. For example:

docker run <various parameters> bin/elasticsearch -Ecluster.name=mynewclustername

Notes for production use and defaultsedit

We have collected a number of best practices for production use.

Note

Any Docker parameters mentioned below assume the use of docker run.

  1. It is important to correctly set capabilities and ulimits via the Docker CLI. As seen earlier in the example docker-compose.yml, the following options are required:

    --cap-add=IPC_LOCK --ulimit memlock=-1:-1 --ulimit nofile=65536:65536
    
  2. Ensure bootstrap.memory_lock is set to true as explained in "Disable swapping".

    This can be achieved through any of the configuration methods, e.g. by setting the appropriate environments variable with -e "bootstrap.memory_lock=true".

  3. The image exposes TCP ports 9200 and 9300. For clusters it is recommended to randomize the published ports with --publish-all, unless you are pinning one container per host.
  4. Use the ES_JAVA_OPTS environment variable to set heap size, e.g. to use 16GB use -e ES_JAVA_OPTS="-Xms16g -Xmx16g" with docker run. It is also recommended to set a memory limit for the container.
  5. Pin your deployments to a specific version of the Elasticsearch Docker image, e.g. docker.elastic.co/elasticsearch/elasticsearch:5.2.1.
  6. Always use a volume bound on /usr/share/elasticsearch/data, as shown in the production example, for the following reasons:

    1. The data of your elasticsearch node won’t be lost if the container is killed
    2. Elasticsearch is I/O sensitive and the Docker storage driver is not ideal for fast I/O
    3. It allows the use of advanced Docker volume plugins
  7. If you are using the devicemapper storage driver (default on at least RedHat (rpm) based distributions) make sure you are not using the default loop-lvm mode. Configure docker-engine to use direct-lvm instead.
  8. Consider centralizing your logs by using a different logging driver. Also note that the default json-file logging driver is not ideally suited for production use.

Next stepsedit

You now have a test Elasticsearch environment set up. Before you start serious development or go into production with Elasticsearch, you will need to do some additional setup:

  • Learn how to configure Elasticsearch.
  • Configure important Elasticsearch settings.
  • Configure important system settings.




Configuring Elasticsearch edit

配置Elasticsearch


Elasticsearch ships with good defaults and requires very little configuration. Most settings can be changed on a running cluster using the  Cluster Update Settings API.

Elasticsearch有非常好的默认配置,只需要很少的配置就可以运行。大部分配置可以运行时改变,具体查看 Cluster Update Setting API。


The configuration files should contain settings which are node-specific (such as  node.name and paths), or settings which a node requires in order to be able to join a cluster, such as  cluster.nameand  network.host.

配置文件应该包含配置有:节点特定的配置(node.name和paths),或者是一个节点能够加入集群所需要的配置,例如cluster.name和network.host。


Config file location edit

配置文件位置


Elasticsearch has two configuration files:
  • elasticsearch.yml for configuring Elasticsearch, and
  • log4j2.properties for configuring Elasticsearch logging.

Elasticsearch有两个配置文件:
  • elasticsearch.yml,用于配置elasticsearch
  • log4j2.properties, 用于配置Elasticsearch日志打印


These files are located in the config directory, whose location defaults to  $ES_HOME/config/. The Debian and RPM packages set the config directory location to  /etc/elasticsearch/.


默认存放在$ES_HOME/config/。Debian和RPM包存放在/etc/elasticsearch/


The location of the config directory can be changed with the  path.conf setting, as follows:

config目录位置也可以通过path.conf进行设置,如下所示:

./bin/elasticsearch -Epath.conf=/path/to/my/config/

Config file format edit

配置文件格式:


The configuration format is  YAML. Here is an example of changing the path of the data and logs directories:

配置格式是 YAML。这里有一个例子:改变data和log的路径:


path:
data: /var/lib/elasticsearch logs: /var/log/elasticsearch

Settings can also be flattened as follows:

也可以像下面一样配置:

path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch

Environment variable subsitution edit

环境变量配置:


Environment variables referenced with the  ${...} notation within the configuration file will be replaced with the value of the environment variable, for instance:

配置文件中的环境变量可以由外部的环境变量表示,例如:

node.name:    ${HOSTNAME}
network.host: ${ES_NETWORK_HOST}

Prompting for settings edit

提示设置


For settings that you do not wish to store in the configuration 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}will allow you to see the value as you type it in. For example:

如果你不想存储配置文件中的某些配置,你可以使用${prompt.text}或者${prompt.secret},并在前台启动Elasticsearch。${prompt.secret}已禁用回声,这样输入的值就不会显示在终端。${prompt.text}将允许你查看你输入的值。例如:

node:
name: ${prompt.text}

When starting Elasticsearch, you will be prompted to enter the actual value like so:

当启动Elasticsearch时,你将获得一些提示信息,如下所示:

Enter value for[node.name]:
Note

Elasticsearch will not start if  ${prompt.text} or  ${prompt.secret} is used in the settings and the process is run as a service or in the background.

如果使用${prompt.text}或者${prompt.secret},则Elasticsearch不会在后台启动


Setting default settings edit

设置默认配置


New default settings may be specified on the command line using the  default. prefix. This will specify a value that will be used by default unless another value is specified in the config file.


可以使用default.前缀对新默认配置进行设置。在没有在配置文件指定其他值之前,都会使用配置的值。

For instance, if Elasticsearch is started as follows:

./bin/elasticsearch -Edefault.node.name=My_Node

the value for  node.name will be  My_Node, unless it is overwritten on the command line with  es.node.name or in the config file with  node.name.


node.name会时My_node,除非在命令行中使用es.node.name配置或者在配置文件中使用node.name配置。


Logging configuration edit

日志打印配置


Elasticsearch uses  Log4j 2 for logging. Log4j 2 can be configured using the log4j2.properties file. Elasticsearch exposes a single property  ${sys:es.logs} that can be referenced in the configuration file to determine the location of the log files; this will resolve to a prefix for the Elasticsearch log file at runtime.

Elasticsearch使用 Log4j2记录日志信息。Log4j2可以在log4j2.properties文件中进行配置。Elasticsearch设置了唯一的属性配置${sys:es.logs}用来决定日志文件的位置。这个作为Elasticsearch运行时日志的前缀。


For example, if your log directory ( path.logs) is  /var/log/elasticsearch and your cluster is named  production then  ${sys:es.logs} will resolve to  /var/log/elasticsearch/production.

例如,如果日志目录(path.logs)是/var/log/elasticsearch,同时集群命名为production,那么${sys:es.logs}将被解析为/var/log/elasticsearch/production


appender.rolling.type =RollingFile appender.rolling.name = rolling appender.rolling.fileName = ${sys:es.logs}.log  appender.rolling.layout.type =PatternLayout appender.rolling.layout.pattern =[%d{ISO8601}][%-5p][%-25c]%.10000m%n appender.rolling.filePattern = ${sys:es.logs}-%d{yyyy-MM-dd}.log  appender.rolling.policies.type =Policies appender.rolling.policies.time.type =TimeBasedTriggeringPolicy appender.rolling.policies.time.interval =1 appender.rolling.policies.time.modulate =true 

Configure the RollingFile appender

Log to /var/log/elasticsearch/production.log

Roll logs to /var/log/elasticsearch/production-yyyy-MM-dd.log

Using a time-based roll policy

Roll logs on a daily basis

Align rolls on the day boundary (as opposed to rolling every twenty-four hours)

If you append .gz or .zip to appender.rolling.filePattern, then the logs will be compressed as they are rolled.


如果在appender.rolling.filePattern中使用.gz或者.zip扩展,则日志将使用扩展名压缩。


Deprecation logging edit

丢弃日志


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 enabled at the WARN level, the level at which all deprecation log messages will be emitted.

除了常规日志打印之外,Elasticsearch还允许你开启日志丢弃功能。例如,允许你早期确定,以便以后迁移某些功能。默认情况下,丢弃日志一般设置为WARN级别,即只有高于这个级别的日志会打印,低于这个级别的日志都会丢弃。

logger . deprecation . level  =  warn

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.

The default logging configuration has set the roll policy for the deprecation logs to roll and compress after 1 GB, and to preserve a maximum of five log files (four rolled logs, and the active log).


You can disable it in the  config/log4j2.properties file by setting the deprecation log level to  error.

这会在日志目录中创建日常的滚动丢弃日志文件。按照常规检查这些日志即可,特别是当你打算升级时。

默认日志打印配置设置了滚动策略,一般是1GB就会发生日志滚动,而且只会保存5个日志文件。

你可以在config/log4j2.properties中设置日志级别为error。
Multiple configuration files can be loaded (in which case they will get merged) as long as they are named  log4j2.properties and have the Elasticsearch config directory as an ancestor; this is useful for plugins that expose additional loggers. The logger section contains the java packages and their corresponding log level. 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 Log4j documentation.


可以加载多个配置文件(某些情况下会合并),只要它们命名为log4j2.properties,同时都使用相同的Elasticsearch配置目录。支持额外的loggers对于其它插件来说是非常有用的。logger部分包含了java包以及它们相关的log级别。appender部分包含了日志生成位置。其它如何使用自定义的日志以及其它支持的appenders都可以在 log4j 文档中找到。




Important Elasticsearch configuration edit

重要的Elasticsearch配置


While Elasticsearch requires very little configuration, there are a number of settings which need to be configured manually and should definitely be configured before going into production.

Elasticsearch只需要非常少的配置,只有少数配置在生产环境中需要人工配置,

  • path.data and path.logs
  • cluster.name
  • node.name
  • bootstrap.memory_lock
  • network.host
  • discovery.zen.ping.unicast.hosts
  • discovery.zen.minimum_master_nodes

path.data and  path.logs edit

path.data和path.logs


If you are using the  .zip or  .tar.gz archives, the  data and  logs directories are sub-folders of  $ES_HOME. If these important folders are left in their default locations, there is a high risk of them being deleted while upgrading Elasticsearch to a new version.

如果你使用的是.zip或者.tar.gz格式,data和logs目录会在$ES_HOME的子目录。如果这些中药的目录使用默认配置,则对于升级Elasticesearch来说是个很大的风险。


In production use, you will almost certainly want to change the locations of the data and log folder:

在生产环境中,你一般需要改变这些数据和日志目录:

path:
  logs: /var/log/elasticsearch
  data: /var/data/elasticsearch

The RPM and Debian distributions already use custom paths for  data and  logs.

RPM和Debian部署已经对data和logs使用了用户的路径


The  path.data settings can be set to multiple paths, in which case all paths will be used to store data (although the files belonging to a single shard will all be stored on the same data path):

path.data配置可以配置为多个目录,所有的配置目录都会用来存储数据(然而属于同一个分片的文件只能存储在相同目录)。

path:
  data:
    - /mnt/elasticsearch_1
    - /mnt/elasticsearch_2
    - /mnt/elasticsearch_3

cluster.name edit

集群名字


A node can only join a cluster when it shares its  cluster.name with all the other nodes in the cluster. The default name is  elasticsearch, but you should change it to an appropriate name which describes the purpose of the cluster.

节点只能加入集群名字相同的集群。默认名字是elasticsearch,但是当创建其它用途集群时一般需要设置一个合适的名字。

cluster.name: logging-prod

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.

确保在不同的环境中不要使用相同的名字,否则节点会加入一个错误的集群。


node.name edit

节点名字


By default, Elasticsearch will take the 7 first character of the randomly generated uuid used as the node id. Note that the node id is persisted and does not change when a node restarts and therefore the default node name will also not change.

默认情况下,Elasticsearch会把随机产生的uuid的前7个字母作为node id。注意:node id是持久存在的,不可更改的,当一个节点重启时,节点名字不应该改变。


It is worth configuring a more meaningful name which will also have the advantage of persisting after restarting the node:

值得配置一个有意义的名字,利于重启节点,方便记忆。

node.name: prod-data-2

The  node.name can also be set to the server’s HOSTNAME as follows:

node.name也可以设置为HOSTNAME:

node.name: ${HOSTNAME}

bootstrap.memory_lock edit

It is vitally important to the health of your node that none of the JVM is ever swapped out to disk. One way of achieving that is set the  bootstrap.memory_lock setting to  true.

没有JVM会交换到磁盘上,因此这个对节点健康很重要。一个办法就是设置bootstrap.memory_lock为true。


For this setting to have effect, other system settings need to be configured first. See  Enable  bootstrap.memory_lock for more details about how to set up memory locking correctly.

想要这个配置生效,需要先设置其它系统配置。查看启动 bootstrap.memory_lock的更多细节。

network.hostedit


By default, Elasticsearch binds to loopback addresses only — e.g.  127.0.0.1 and  [::1]. This is sufficient to run a single development node on a server.

默认情况下,Elasticsearch会帮顶回环地址-例如127.0.0.1以及[::1]。在某个server上运行单个部署的节点很有效。

Tip

In fact, more than one node can be started from the same  $ES_HOME location on a single node. This can be useful for testing Elasticsearch’s ability to form clusters, but it is not a configuration recommended for production.

实际上,有可能不止一个节点拥有相同的$ES_HOME。这个对于测试集群能力比较有效,但是生产环境中不建议这么玩。


In order to communicate and to form a cluster with nodes on other servers, your node will need to bind to a non-loopback address. While there are many  network settings, usually all you need to configure is  network.host:

为了能和其它servers上节点正常通信,并形成集群,节点需要绑定到一个非回环地址。有很多 网络方面的配置,通常你需要配置的是network.host:

network.host: 192.168.1.10

The  network.host setting also understands some special values such as  _local__site__global_ and modifiers like  :ip4 and  :ip6, details of which can be found in  the section called “Special values for  network.host edit”.

network.host配置也可以解析一些特殊配置,例如_local_,_site_,_global_以及修饰符:ip4和:ip6,更多的细节信息可以查看章节“ Special values for network.host”

Important

As soon you provide a custom setting for  network.host, Elasticsearch assumes that you are moving from development mode to production mode, and upgrades a number of system startup checks from warnings to exceptions. See  the section called “Development mode vs production mode edit” for more information.

只要你配置了自己的network.host,Elasticsearch就假定你从部署模式向生产模式迁移,并更新了一些系统启动时检查,包括警告信息和异常信息。查看章节” Development mode vs production mode"获取更多信息。

discovery.zen.ping.unicast.hostsedit


Out of the box, without any network configuration, Elasticsearch will bind to the available loopback addresses and will scan ports 9300 to 9305 to try to connect to other nodes running on the same server. This provides an auto- clustering experience without having to do any configuration.

开箱即用,没有任何网络配置,Elasticsearch将帮顶可用的回环地址,并扫描9300到9305端口,尝试连接运行在本机上的其它节点。这提供了自动创建集群的能力,不需要额外的配置。


When the moment comes to form a cluster with nodes on other servers, you have to provide a seed list of other nodes in the cluster that are likely to be live and contactable. This can be specified as follows:

当需要互联集群中位于其它机子上的节点时,就需要提供集群中其它节点的一个种子列表,最好是活跃以及能够连接的节点。

discovery.zen.ping.unicast.hosts:
   - 192.168.1.10:9300
   - 192.168.1.11 
   - seeds.mydomain.com 

The port will default to transport.profiles.default.port and fallback to transport.tcp.port if not specified.


A hostname that resolves to multiple IP addresses will try all resolved addresses.
端口默认设置为transport.profiles.default.port,如果没有特别指定的话,一般会回退到transport.tcp.port
如果hostname可以解析为多个ip地址,将会尝试连接所有ip地址。


discovery.zen.minimum_master_nodes edit

To prevent data loss, it is vital to configure the  discovery.zen.minimum_master_nodes setting so that each master-eligible node knows the  minimum number of master-eligible nodes that must be visible in order to form a cluster.

为了避免数据丢失,配置discovery.zen.minimum_master_nodes是至关重要的,以便每个符合主机条件的都节点知道才能形成集群的合格主机节点的最小数量。


Without this setting, a cluster that suffers a network failure is at risk of having the cluster split into two independent clusters — a split brain — which will lead to data loss. A more detailed explanation is provided in  the section called “Avoiding split brain with  minimum_master_nodes edit”.

如果没有设置,遭遇网络故障的集群会遇到分裂为两个集群的风险-脑裂-这可能导致数据丢失。更多细节需要查看章节 Avoiding split brain with minimu_master_nodes。


To avoid a split brain, this setting should be set to a  quorum of master- eligible nodes:

为了避免脑裂,这个设置应当设置符合主机条件的节点数为:

(master_eligible_nodes / 2) + 1

In other words, if there are three master-eligible nodes, then minimum master nodes should be set to  (3 / 2) + 1 or  2:

换句话说,如果有三个符合主机条件的节点,最少的主节点个数应当设置为(3/2) + 1 或者 2;

discovery.zen.minimum_master_nodes: 2




Bootstrap Checksedit


Collectively, we have a lot of experience with users suffering unexpected issues because they have not configured  important settings. In previous versions of Elasticsearch, misconfiguration of some of these settings were logged as warnings. Understandably, users sometimes miss these log messages. To ensure that these settings receive the attention that they deserve, Elasticsearch has bootstrap checks upon startup.

对于用户遇到意外事情来说,我们有很多这样的经验,因为它们没有配置 重要的配置。在以前的版本中,某些错误配置会作为警告信息打印出来。不幸的是,用户有时会忽略这些消息。为了保证这些配置都会获得足够的注意,Elasticsearch会在启动时检查基础配置。


These bootstrap checks inspect a variety of Elasticsearch and system settings and compare them to values that are safe for the operation of Elasticsearch. If Elasticsearch is in development mode, any bootstrap checks that fail appear as warnings in the Elasticsearch log. If Elasticsearch is in production mode, any bootstrap checks that fail will cause Elasticsearch to refuse to start.

这些基础配置检查会探测大量的Elasticsearch和系统配置,并将它们和适合运行的值相比较。如果Elasticsearch在开发模式,任何基础检查失败都会以警告信息打印。如果Elasticsearch在生产环境,任何基础检查失败都会导致Elasticsearch启动失败。


There are some bootstrap checks that are always enforced to prevent Elasticsearch from running with incompatible settings. These checks are documented individually.

某些基础检查会强制避免Elasticsearch运行在不兼容的环境。这些检查都是独立的。


Development vs. production mode edit’

开发模式VS生产模式


By default, Elasticsearch binds to  localhost for  HTTP and  transport (internal) communication. This is fine for downloading and playing with Elasticsearch, and everyday development but it’s useless for production systems. To form a cluster, Elasticsearch instances must be reachable via transport communication so they must bind transport to an external interface. Thus, we consider an Elasticsearch instance to be in development mode if it does not bind transport to an external interface (the default), and is otherwise in production mode if it does bind transport to an external interface. Note that HTTP can be configured independently of transport via  http.host and  transport.host; this can be useful for configuring a single instance to be reachable via HTTP for testing purposes without triggering production mode.

默认情况下,Elasticsearch会绑定到localhost,以供 HTTP和 transport通信。这对于下载和尝试Elasticsearch以及每天的开发来说比较好,但是对于生产系统来说不好。为了创建集群,Elasticsearch实例必须是可连接的,因此它们必须绑定到一个外部接口。这样,如果没有绑定到外部接口上,我们就认为是开发环境,否则就认为是生产环境。注意,HTTP可以通过http.host和transport.host独立配置。这个对于配置一个单独的实示例来说很有用。




Heap size check edit

堆尺寸检查


If a JVM is started with unequal initial and max heap size, it can be prone to pauses as the JVM heap is resized during system usage. To avoid these resize pauses, it’s best to start the JVM with the initial heap size equal to the maximum heap size. Additionally, if  bootstrap.memory_lock is enabled, the JVM will lock the initial size of the heap on startup. If the initial heap size is not equal to the maximum heap size, after a resize it will not be the case that all of the JVM heap is locked in memory. To pass the heap size check, you must configure the  heap size.

如果JVM以不同的初始值和最大堆大小启动,则JVM堆会在系统使用期间调整大小,因此可能出现暂停。为了避免这些因为调整出现的暂停,最好在启动时设置初始堆大小等于最大堆尺寸。另外,如果开启 bootrap.memory_lock,JVM将在启动时锁住初始堆大小。如果初始堆大小不等于最大堆大小,在调整大小之后,将不会使所有JVM堆都锁到内存中。为了跳过堆大小检查,你必须配置堆尺寸。




File descriptor check edit

文件描述符检查


File descriptors are a Unix construct for tracking open "files". In Unix though,  everything is a file. For example, "files" could be a physical file, a virtual file (e.g.,  /proc/loadavg), or network sockets. Elasticsearch requires lots of file descriptors (e.g., every shard is composed of multiple segments and other files, plus connections to other nodes, etc.). This bootstrap check is enforced on OS X and Linux. To pass the file descriptor check, you might have to configure  file descriptors.

文件描述符是Unix用于追踪打开文件的。在Unix环境中, 一切都是文件。例如,“文件”可以是一个物理文件,也可以是虚拟文件(例如,/proc/loadavg),或者网络sockets。Elasticsearch要求大量的文件描述符(例如,每个shard都是由多个部分和其它文件,还有其它节点的连接一起构成的。)。在OS X和Linux上强制进行基础检查。为了通过文件描述符检查,你需要配置 文件描述符。




Memory lock check edit

内存锁检查


When the JVM does a major garbage collection it touches every page of the heap. If any of those pages are swapped out to disk they will have to be swapped back in to memory. That causes lots of disk thrashing that Elasticsearch would much rather use to service requests. There are several ways to configure a system to disallow swapping. One way is by requesting the JVM to lock the heap in memory through  mlockall (Unix) or virtual lock (Windows). This is done via the Elasticsearch setting  bootstrap.memory_lock. However, there are cases where this setting can be passed to Elasticsearch but Elasticsearch is not able to lock the heap (e.g., if the  elasticsearch user does not have  memlock unlimited). The memory lock check verifies that  if the  bootstrap.memory_lock setting is enabled, that the JVM was successfully able to lock the heap. To pass the memory lock check, you might have to configure  mlockall.

当JVM做主要的垃圾回收时,它会接触到堆的每个页。如果这些页中的任何页交换到磁盘上,它们后面还会交换回内存。这将引起大量的磁盘抖动,Elasticsearch更愿意做服务请求。有很多方法配置系统来避免这种交换。一种方式是请求JVM通过mlockall(Unix)或者virtual lock(windows)锁住内存中的堆。这可以通过设置 bootstrap.memory_lock来做。然而, 还有一些情况:当这种设置可以传递给Elasticsearch,但是Elasticesearch无法锁住堆(例如,如果elasticesearch用户不能设置memlock unlimited)。内存锁检查确认了:如果bootstrap.memory_lock设置可以启动,JVM可以锁住堆。为了通过内存锁检查,你需要配置 mlockall。




Maximum number of threads check edit

最大线程数检查


Elasticsearch executes requests by breaking the request down into stages and handing those stages off to different thread pool executors. There are different  thread pool executors for a variety of tasks within Elasticsearch. Thus, Elasticsearch needs the ability to create a lot of threads. The maximum number of threads check ensures that the Elasticsearch process has the rights to create enough threads under normal use. This check is enforced only on Linux. If you are on Linux, to pass the maximum number of threads check, you must configure your system to allow the Elasticsearch process the ability to create at least 2048 threads. This can be done via  /etc/security/limits.conf using the  nprocsetting (note that you might have to increase the limits for the  root user too).

Elasticsearch处理请求时,会将请求分成不同的阶段,然后再将这些处理阶段分到线程池中的不同线程去执行。Elasticsearch中有 不同的线程池来完成大量的任务。这样,Elasticesearch就需要创建大量线程的能力。最大线程数检查保证了Elasticsearch进程正常情况下可以创建足够的线程。这个检查只在Linux上强制进行。如果是在Linux环境下,为了通过最大线程数检查,你必须配置系统以允许Elasticsearch可以创建至少2048个线程。这可以通过修改/etc/security/limits.conf中的nproc设置来实现(注意,你需要root用户才能修改这个配置)。




Maximum size virtual memory check edit

最大虚拟内存尺寸检查


Elasticsearch and Lucene use  mmap to great effect to map portions of an index into the Elasticsearch address space. This keeps certain index data off the JVM heap but in memory for blazing fast access. For this to be effective, the Elasticsearch should have unlimited address space. The maximum size virtual memory check enforces that the Elasticsearch process has unlimited address space and is enforced only on Linux. To pass the maximum size virtual memory check, you must configure your system to allow the Elasticsearch process the ability to have unlimited address space. This can be done via  /etc/security/limits.conf using the  as setting to  unlimited (note that you might have to increase the limits for the  root user too).

Elasticsearch和Lucene使用mmap以更有效的映射索引库位置和Elasticsearch地址空间。这可以保持相当的索引库数据不在JVM堆而是在内存中,以获得更快的访问。虚拟内存最大尺寸检查强制了Elasticsearch拥有无限的地址空间,而且只在Linux上要求这一项。为了通过虚拟内存最大尺寸检查,你必须配置系统以允许Elasticsearch进程拥有无限的地址空间。这可以通过修改/etc/security/limits.conf中as类设置为unlimited(注意你需要root用户权限)



Maximum map count check edit

最大映射数量检查


Continuing from the previous  point, to use  mmap effectively, Elasticsearch also requires the ability to create many memory-mapped areas. The maximum map count check checks that the kernel allows a process to have at least 262,144 memory-mapped areas and is enforced on Linux only. To pass the maximum map count check, you must configure  vm.max_map_count via  sysctl to be at least  262144.

继续上一个点,为了更有效的使用mmap,Elasticsearch也要求创建很多内存映射区域的能力。最大的映射数量检查检查了内核是否允许一个进程拥有至少262144个内存映射区域,并且只会在Linux上强制进行。为了通过最大映射数量检查,你必须通过sysctl配置vm.max_map_count至少为262144.




Client JVM check edit

客户端JVM检查


There are two different JVMs provided by OpenJDK-derived JVMs: the client JVM and the server JVM. These JVMs use different compilers for producing executable machine code from Java bytecode. The client JVM is tuned for startup time and memory footprint while the server JVM is tuned for maximizing performance. The difference in performance between the two VMs can be substantial. The client JVM check ensures that Elasticsearch is not running inside the client JVM. To pass the client JVM check, you must start Elasticsearch with the server VM. On modern systems and operating systems, the server VM is the default. Additionally, Elasticsearch is configured by default to force the server VM.

OpenJDK衍生出的JVMs提供两个JVMs:客户端JVM和服务端JVM。这些JVMs使用不同的编译器生产出可执行机器上Java的字节码。客户端JVM真对启动时间和内存占用进行调整,服务端JVM针对性能最大化进行优化。两个VMs之间的性能差异可能比较大。客户端JVM检查保证了Elasticsearch没有运行在客户端JVM内部。为了通过客户端JVM检查,你必须使用服务端VM启动Elasticsearch。现代操作系统中,服务端VM是默认选择。然而,Elasticsearch还是会默认强制选择服务端VM。




Use serial collector check edit

使用序列化收集检查


There are various garbage collectors for the OpenJDK-derived JVMs targeting different workloads. The serial collector in particular is best suited for single logical CPU machines or extremely small heaps, neither of which are suitable for running Elasticsearch. Using the serial collector with Elasticsearch can be devastating for performance. The serial collector check ensures that Elasticsearch is not configured to run with the serial collector. To pass the serial collector check, you must not start Elasticsearch with the serial collector (whether it’s from the defaults for the JVM that you’re using, or you’ve explicitly specified it with  -XX:+UseSerialGC). Note that the default JVM configuration that ship with Elasticsearch configures Elasticsearch to use the CMS collector.


OpenJDK衍生的JVMs有多种的垃圾回收器用于实现不同的工作负载。序列化收集器特别适用于单个逻辑CPU机器或者极端小的堆。序列化收集器检查保证了Elasticsearch没有配置在运行时采用序列化。为了通过序列化收集器检查,你必须不能使用序列化收集器启动Elasticsearch(无论你使用的JVM默认是否使用这种收集器,或者你已经显示指定了 -XX:+UseSerialGC)。注意,Elasticsearch配置的默认JVM配置是是用CMS收集器。




System call filter check edit

系统调用过滤器检查


Elasticsearch installs system call filters of various flavors depending on the operating system (e.g., seccomp on Linux). These system call filters are installed to prevent the ability to execute system calls related to forking as a defense mechanism against arbitrary code execution attacks on Elasticsearch The system call filter check ensures that if system call filters are enabled, then they were successfully installed. To pass the system call filter check you must either fix any configuration errors on your system that prevented system call filters from installing (check your logs), or  at your own risk disable system call filters by setting  bootstrap.system_call_filter to  false.

Elasticsearch安装系统调用大量依赖于操作系统的过滤器(例如Linux上seccomp)。这些系统调用过滤器防止以下情况:执行与forking相关的系统调用作为攻击Elasticsearch的手段。这项系统调用检查保证了:如果系统调用开启了,那么它们就成功安装了。为了通过系统调用过滤器检查,你必须或者是修改某些系统的配置错误,避免安装系统调用过滤器(查看日志可以看出),或者冒风险关闭系统调用过滤器,通过设置bootstrap.system_call_filter为false。




OnError and OnOutOfMemoryError checks edit

OnError以及OnOutOfMemoryError检查


The JVM options  OnError and  OnOutOfMemoryError enable executing arbitrary commands if the JVM encounters a fatal error ( OnError) or an  OutOfMemoryError( OnOutOfMemoryError). However, by default, Elasticsearch system call filters (seccomp) are enabled and these filters prevent forking. Thus, using  OnError or  OnOutOfMemoryError and system call filters are incompatible. The  OnError and OnOutOfMemoryError checks prevent Elasticsearch from starting if either of these JVM options are used and system call filters are enabled. This check is always enforced. To pass this check do not enable  OnError nor  OnOutOfMemoryError; instead, upgrade to Java 8u92 and use the JVM flag  ExitOnOutOfMemoryError. While this does not have the full capabilities of  OnError nor  OnOutOfMemoryError, arbitrary forking will not be supported with seccomp enabled.

JVM选项OnError和OnOutOfMemoryError允许执行任何命令,如果JVM遭遇致命错误(OnError)或者是OutOfMemoryError。然而,默认情况下,Elasticsearch系统调用过滤器(seccomp)是开启的,这些过滤器阻挡了forking。这样,使用OnError或者OnOutOfMemoryError以及系统调用过滤器是不兼容的。OnError和OnOutOfMemoryError检查避免Elasticsearch在使用这些JVM选项或者系统调用过滤器开启时启动。这项检查也是强制的。为了通过这项检查,不要开启OnError或者OnOutOfMemoryError;而是更新到Java 8u92,并使用JVM 标志ExitOnOutOfMemoryError。虽然这不支持完整的OnError或者OnOutOfMemoryError能力,但是也不支持seccomp开启任意的forking。




G1GC checkedit


Early versions of the HotSpot JVM that shipped with JDK 8 are known to have issues that can lead to index corruption when the G1GC collector is enabled. The versions impacted are those earlier than the version of HotSpot that shipped with JDK 8u40. The G1GC check detects these early versions of the HotSpot JVM.

已知JDK 8 附带的HotSpot JVM早期版本在使用G1GC收集器时会导致索引崩溃。带有HotSpot的JDK 8u40之前的版本都受到此影响。G1GC检查探测JVM HotSpot早期版本。




Important System Configuration edit

重要的系统配置


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应当单独的运行在server上,当可能时使用所有资源。为了做到这一点,你需要配置你的操作系统以允许运行Elasticsearch的用户可以访问比默认允许更多的资源。

The following settings must be addressed before going to production:

  • Set JVM heap size
  • Disable swapping
  • Increase file descriptors
  • Ensure sufficient virtual memory
  • Ensure sufficient threads

Development mode vs production mode edit

开发模式VS生产模式


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.

默认情况下,Elasticsearch假定你工作开发模式。如果上面任何配置没有配置正确,会有警告信息打印到日志文件,但是Elasticsearch也会启动。


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.

只要你配置了网络配置,例如network.host,Elasticsearch假定你已经迁移到生产环境了,而且将会将上述警告信息变为异常打印出来。这些一场将阻止Elasticsearch启动。这是重要的安全措施,保证了你不会因为错误配置的server而丢失信息。




Configuring system settings edit

配置系统配置


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, or
  • permanently in /etc/security/limits.conf.

When using the RPM or Debian packages, most system settings are set in the system configuration file. However, systems which use systemd require that system limits are specified in a  systemd configuration file.

当使用RPM或者Debian包时,大多数系统设置在 system configuration file中配置。然而,使用系统的系统要求系统限制在 systemd configuration file中配置。

ulimitedit


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可以用来改变资源限制。这些限制一般需要使用root权限设置。例如,设置打开文件句柄的数量为65536,你可以按照下面步骤来:

sudo su   ulimit -n 65536 su elasticsearch 

Become root.

Change the max number of open files.

Become the elasticsearch user in order to start Elasticsearch.


The new limit is only applied during the current session.

You can consult all currently applied limits with  ulimit -a.

新的限制只能在新会话中应用。你可以使用ulimit -a查看当前应用。

/etc/security/limits.confedit


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.conf中追加以下设置:

elasticsearch  -  nofile  65536

This change will only take effect the next time the  elasticsearch user opens a new session.

这个配置只会影响elasticsearch用户下次打开新会话。

Note

Ubuntu and 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的limits.conf杯init.d启动的进程忽略了。为了启动limits.conf,需要编辑/etc/pam.d/su,将注释掉的这行打开。

# session    required   pam_limits.so

Sysconfig fileedit


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安装包时,系统设置和环境变量可以在系统配置文件中指定,如下:

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 configurationedit

When using the RPM or Debian packages on systems that use systemd, system limits must be specified via systemd.

The systemd service file (/usr/lib/systemd/system/elasticsearch.service) contains the limits that are applied by default.

To override these, add a file called/etc/systemd/system/elasticsearch.service.d/elasticsearch.conf and specify any changes in that file, such as:

[Service]LimitMEMLOCK=infinity

Setting JVM optionsedit


The preferred method of setting Java Virtual Machine options (including system properties and JVM flags) is via the  jvm.options configuration file. The default location of this file is  config/jvm.options (when installing from the tar or zip distributions) and  /etc/elasticsearch/jvm.options (when installing from the Debian or RPM packages). This file contains a line-delimited list of JVM arguments, which must begin with  -. You can add custom JVM flags to this file and check this configuration into your version control system.

设置Java虚拟机选项的推荐方式(包括系统属性和JVM标志信息)是通过jvm.options配置文件。这个文件的默认位置是config/jvm.options(当使用tar或者zip包安装时)以及/etc/elasticsearch/jvm.options(当使用Debian或者RPM包时)。这个文件包含以行为分割的JVM参数,必须以 -. 为开始,你可以增加自定义的JVM标志信息,并检查这个配置


An alternative mechanism for setting Java Virtual Machine options is via the  ES_JAVA_OPTS environment variable. For instance:

设置Java虚拟机选项的可选方式时通过ES_JAVA_OPTS环境变量。例如:

export ES_JAVA_OPTS="$ES_JAVA_OPTS -Djava.io.tmpdir=/path/to/temp/dir"./bin/elasticsearch

When using the RPM or Debian packages,  ES_JAVA_OPTS can be specified in the system configuration file.




Set JVM heap size via jvm.options edit

通过jvm.options设置JVM堆尺寸

By default, Elasticsearch tells the JVM to use a heap with a minimum and maximum size of 2 GB. When moving to production, it is important to configure heap size to ensure that Elasticsearch has enough heap available.


Elasticsearch will assign the entire heap specified in jvm.options via the Xms (minimum heap size) and Xmx (maximum heap size) settings.

默认情况下,Elasticsearch告诉JVM使用堆的最大和最小尺寸都是2GB。当移动到生产环境时,重要的配置堆尺寸以保证Elasticsearch具有足够的堆。
jvm.options中Xms(最小堆尺寸)和Xmx(最大堆尺寸)指定堆有多大,Elasticsearch就分配多少空间。


The value for these setting depends on the amount of RAM available on your server. Good rules of thumb are:

这些设置的值依赖于server上RAM数量。

  • Set the minimum heap size (Xms) and maximum heap size (Xmx) to be equal to each other.通过Xms设置最小堆尺寸,通过Xmx设置最大堆尺寸,并设置这两个相等。
  • The more heap available to Elasticsearch, the more memory it can use for caching. But note that too much heap can subject you to long garbage collection pauses.Elasticsearch使用的堆越多,可以用于缓存的内存越多。但是注意,太多的堆可能引起较长时间的垃圾收集等待。
  • Set Xmx to no more than 50% of your physical RAM, to ensure that there is enough physical RAM left for kernel file system caches.设置Xmx不要超过物理RAM的50%,以保证有足够的物理RAM空间用于内核文件系统缓存。
  • Don’t set Xmx to above the cutoff that the JVM uses for compressed object pointers (compressed oops); the exact cutoff varies but is near 32 GB. You can verify that you are under the limit by looking for a line in the logs like the following:  不要设置Xmx高于JVM用于压缩对象指针(压缩的oops)的截断值。准确的阶段值接近32gb。你可以确认一下,日志中这一行是否在限制之下。

    heap size [1.9gb], compressed ordinary object pointers [true]
  • Even better, try to stay below the threshold for zero-based compressed oops; the exact cutoff varies but 26 GB is safe on most systems, but can be as large as 30 GB on some systems. You can verify that you are under the limit by starting Elasticsearch with the JVM options  -XX:+UnlockDiagnosticVMOptions -XX:+PrintCompressedOopsMode and looking for a line like the following:   更好的是,尝试保持低于zero-based压缩oops的限制值,准确的截断值比较大,但是26GB在大多数系统上比较安全,但是在某些系统上可以高达30GB。你可以确认一下,启动Elasticsearch时,通过JVM选项: -XX:+UnlockDiagnosticVMOptions -XX:+PrintCompressedOopsMode

    heap address: 0x000000011be00000, size: 27648 MB, zero based Compressed Oops
    

    showing that zero-based compressed oops are enabled instead of

    heap address: 0x0000000118400000, size: 28672 MB, Compressed Oops with base: 0x00000001183ff000
    

Here are examples of how to set the heap size via the jvm.options file:

下面时如何设置堆尺寸的例子:

-Xms2g-Xmx2g 

Set the minimum heap size to 2g.

Set the maximum heap size to 2g.


It is also possible to set the heap size via an environment variable. This can be done by commenting out the  Xms and  Xmx settings in the jvm.options file and setting these values via  ES_JAVA_OPTS:

也可以通过环境变量来设置堆尺寸。这可以通过jvm.options文件中的注释掉的配置来设置:

ES_JAVA_OPTS="-Xms2g -Xmx2g"./bin/elasticsearch  ES_JAVA_OPTS="-Xms4000m -Xmx4000m"./bin/elasticsearch 

Set the minimum and maximum heap size to 2 GB.

Set the minimum and maximum heap size to 4000 MB.

Note

Configuring the heap for the  Windows service is different than the above. The values initially populated for the Windows service can be configured as above but are different after the service has been installed. Consult the  Windows service documentation for additional details.




Disable swapping edit

禁用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 being swapped out to disk.

大多数操作系统会尽可能多的使用内存作为文件系统缓存,并交换暂时不用的应用内存。这可能导致部分JVM 堆数据交换到磁盘上。


Swapping is very bad for performance and 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.

交换对于性能、节点稳定性来说比较糟糕,应该避免。他会引起垃圾收集持续数分钟而不是数微秒,可能导致节点返回信息很慢,甚至和集群失去连接。


There are three approaches to disabling swapping:

有三个方法禁用交换:


Enable  bootstrap.memory_lock edit

启动bootstrap.memory_lock


The first option is to use  mlockall on Linux/Unix systems, or  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系统中的 mlockall,或者是Windows上的 VirtualLock,尝试锁住进程地址,避免任何Elasticsearch 内存被交换。这个可以通过在config/elasticsearch.yml中增加这行配置来实现:

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!

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的值:

GET _nodes?filter_path=**.mlockall
COPY AS CURL VIEW IN 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请求是失败的。你将看到一行或者更多的日志信息,用以表明不能锁住JVM内存。


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
Set  ulimit -l unlimited as root before starting Elasticsearch, or set  memlock to  unlimited in  /etc/security/limits.conf.   设置ulimit -l unlimited,使用root权限执行。在启动Elasticsearch之前执行。
RPM and Debian
Set  MAX_LOCKED_MEMORY to  unlimited in the  system configuration file (or see below for systems using  systemd).
Systems using systemd
Set  LimitMEMLOCK to  infinity in the  systemd configuration.

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:

另一个可能的原因可能临时目录(通常是/tmp)没有使用noexec选项挂载。这可以通过制定新的临时目录来解决,通过ES_JAVA_OPTS环境变量:

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.


Disable all swap files edit

禁用所有swap文件:


The second option is to completely disable swap. 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.

第二个选项是完全禁用swap。通常Elasticsearch是独占一台server,内存使用完全由JVM选项控制。这应该不需要swap功能。


On Linux systems, you can disable swap temporarily 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.

Linux系统上,你可以在运行时暂时禁用swap功能:sudo swapoff -a。想要永久禁用,需要修改/etc/fstab文件,注释掉所有包含swap的行。

On Windows, the equivalent can be achieved by disabling the paging file entirely via System Properties → Advanced → Performance → Advanced → Virtual memory.


Configure  swappiness edit

配置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.swampiness设置为1.这降低了内核使用swap的趋势,在正常环境下不会选择使用swamp,然而在紧急条件下,仍然会允许整个系统进行swap。




File Descriptors edit

文件描述符

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  APIlimited only by available resources.

这只和Linux以及macOS相关,当在Windows上运行时可以忽略。在Windows上,JVM使用


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的用户可打开的文件描述符设置为65536或者更高。


For the  .zip and  .tar.gz packages, set  ulimit -n 65536 as root before starting Elasticsearch, or set  nofile to  65536 in  /etc/security/limits.conf.

对于.zip或者.tar.gz包来说,在启动Elasticsearch之前使用root权限设置 ulimit -n 65536,或者设置/etc/security/limits.conf中的nofile为65536


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  Nodes Stats API, with:

你可以同哟API检查max_file_descriptors配置来看一下:

GET _nodes/stats/process?filter_path=**.max_file_descriptors
COPY AS CURL VIEW IN CONSOLE  




Virtual memory edit

虚拟内存


Elasticsearch uses a  hybrid mmapfs / niofs directory by default to store its indices. The default operating system limits on mmap counts is likely to be too low, which may result in out of memory exceptions.

Elasticsearch默认采用hybrid mmapfs / niofs目录来存储他的索引。操作系统在mmap数量的默认值可能太低了,可能会导致内存异常:


On Linux, you can increase the limits by running the following command as  root:

Linux上,你可以提高这个限制,需要使用root权限执行以下命令:

sysctl -w vm.max_map_count=262144

To set this value permanently, update the  vm.max_map_count setting in /etc/sysctl.conf. To verify after rebooting, run  sysctl vm.max_map_count.

想要永久设置这个值,需要更新/etc/sysctl.conf中的vm.max_map_count设置。为了确认系统重启之后生效,需要运行sysctl vm.max_map_count



The RPM and Debian packages will configure this setting automatically. No further configuration is required.

RPM和Debian包将会自动配置,不要额外的配置。



Number of threads edit

线程数


Elasticsearch uses a number of thread pools for different types of operations. It is important that it is able to create new threads whenever needed. Make sure that the number of threads that the Elasticsearch user can create is at least 2048.

Elasticsearch使用大量的线程池在不同操作时用。重要的是它能够创建大量的线程,无论需要与否。确保Elasticsearch用户可以创建至少2048个线程。


This can be done by setting  ulimit -u 2048 as root before starting Elasticsearch, or by setting  nproc to  2048 in  /etc/security/limits.conf.

可以通过设置 ulimit -u 2048来确保,需要在启动Elasticsearch之前使用root权限执行,或者设置 /etc/security/limits.conf文件中的nproc为2048




Upgrading Elasticsearchedit

Important

Before upgrading Elasticsearch:

  • Consult the breaking changes docs.
  • Use the Elasticsearch Migration Plugin to detect potential issues before upgrading.
  • Test upgrades in a dev environment before upgrading your production cluster.
  • Always back up your data before upgrading. You cannot roll back to an earlier version unless you have a backup of your data.
  • If you are using custom plugins, check that a compatible version is available.

在升级Elasticsearch之前:
  • 查看breaking changes文档
  • 在升级前使用Elasticsearch迁移插件来检查潜在的条目
  • 在开发环境测试升级
  • 在升级前备份数据。你不可以回滚到之前的版本,除非你有数据备份
  • 如果你使用自定义的插件,检查是否兼容升级版本


Elasticsearch can usually be upgraded using a rolling upgrade process, resulting in no interruption of service. This section details how to perform both rolling upgrades and upgrades with full cluster restarts.

Elasticsearch可以使用滚动升级过程进行升级,

To determine whether a rolling upgrade is supported for your release, please consult this table:

Upgrade From  Upgrade To  Supported Upgrade Type

1.x

5.x

Reindex to upgrade

2.x

2.y

Rolling upgrade (where y > x)

2.x

5.x

Full cluster restart

5.0.0 pre GA

5.x

Full cluster restart

5.x

5.y

Rolling upgrade (where y > x)

Important

Indices created in Elasticsearch 1.x or before

Elasticsearch is able to read indices created in the previous major version only. For instance, Elasticsearch 5.x can use indices created in Elasticsearch 2.x, but not those created in Elasticsearch 1.x or before.

This condition also applies to indices backed up with snapshot and restore. If an index was originally created in 1.x, it cannot be restored into a 5.x cluster even if the snapshot was made by a 2.x cluster.

Elasticsearch 5.x nodes will fail to start in the presence of too old indices.


See  Reindex to upgrade for more information about how to upgrade old indices.




Rolling upgrades edit

滚动升级


A rolling upgrade allows the Elasticsearch cluster to be upgraded one node at a time, with no downtime for end users. Running multiple versions of Elasticsearch in the same cluster for any length of time beyond that required for an upgrade is not supported, as shards will not be replicated from the more recent version to the older version.

滚动升级允许集群每次只升级一个节点,不需要宕机。同一个集群中超出升级最长时间的运行多个版本目前不支持,因为shards不能从新版本到旧版本之间跨越式的备份。


Consult this  table to verify that rolling upgrades are supported for your version of Elasticsearch.

查看这张表来确认滚动升级支持你的版本。


To perform a rolling upgrade:

滚动升级前需要执行:

  1. Disable shard allocation   禁用shard分配

    When you shut down a node, the allocation process will wait for one minute before starting to replicate the shards that were on that node to other nodes in the cluster, causing a lot of wasted I/O. This can be avoided by disabling allocation before shutting down a node:  当你停掉一个节点时,应用程序在开始备份其它节点上shards前会等待一分钟,会引起大量浪费的I/O。这个可以通过在停掉一个节点之前禁用分配来避免:

    PUT _cluster/settings
    {"transient":{"cluster.routing.allocation.enable":"none"}} 
    COPY AS CURL VIEW IN CONSOLE  
  2. Stop non-essential indexing and perform a synced flush (Optional) 禁用非必需索引化以及执行同步刷新(可选)

    You may happily continue indexing during the upgrade. However, shard recovery will be much faster if you temporarily stop non-essential indexing and issue a  synced-flush request: 你可以快乐的继续在升级期间进行索引。然而,shard恢复将会更快,如果临时停掉非必需的索引化以及执行同步刷新请求:

    POST _flush/synced
    
    COPY AS CURL VIEW IN CONSOLE  
    A synced flush request is a “best effort” operation. It will fail if there are any pending indexing operations, but it is safe to reissue the request multiple times if necessary.  同步刷新请求是一个最有效的操作,如果有任何等待的索引化操作,它将会失败,但是如果必须的话,多次请求是安全的。

  3.  Stop and upgrade a single node 停止并升级单个节点

    Shut down one of the nodes in the cluster before starting the upgrade. 在升级之前,停掉单个节点

    Tip
    When using the zip or tarball packages, the  configdatalogs and  plugins directories are placed within the Elasticsearch home directory by default. 当使用zip或者 tarball格式的包时,config、data、logs、plugins目录都在Elasticsearch主目录中

    It is a good idea to place these directories in a different location so that there is no chance of deleting them when upgrading Elasticsearch. These custom paths can be  configured with the  path.confpath.logs, and  path.datasettings, and using  ES_JVM_OPTIONS to specify the location of the  jvm.options file.将这些目录迁移到不同目录下是个好主意,这样任何改变都不会删除它们。这些自定义的路径可以通过path.conf,path.logs还有path.data来设置,同时使用ES_JVM_OPTIONS指定jvm.options文件路径。

    The  Debian and  RPM packages place these directories in the appropriate place for each operating 

    To upgrade using a Debian or RPM package:

    • Use rpm or dpkg to install the new package. All files should be placed in their proper locations, and config files should not be overwritten.

    To upgrade using a zip or compressed tarball:升级zip或者tar压缩包的格式:

    • Extract the zip or tarball to a new directory, to be sure that you don’t overwrite the config or data directories.解压zip或者tar包到新目录,确定你没有覆盖configs或者data目录
    • Either copy the files in the config directory from your old installation to your new installation, or set the environment variable ES_JVM_OPTIONS to the location of the jvm.options file and use the -E path.conf= option on the command line to point to an external config directory.不要拷贝旧版本的config目录的文件到新版本中,或者设置环境变量ES_JVM_OPTIONS为jvm.options文件,也不要使用-E path.conf=选项 指定一个外部配置目录。
    • Either copy the files in the data directory from your old installation to your new installation, or configure the location of the data directory in the config/elasticsearch.yml file, with the path.data setting.  既不要拷贝老版本数据目录到新版本数据目录,或者配置config/elasticesearch.yml的数据目录或者使用path.data配置。
  4. Upgrade any plugins  升级任何插件

    Elasticsearch plugins must be upgraded when upgrading a node. Use the elasticsearch-plugin script to install the correct version of any plugins that you need.必须在升级节点之前升级Elasticsearch插件。使用elasticsearch-plugin脚本安装正确的版本。

  5. Start the upgraded node 启动升级节点

    Start the now upgraded node and confirm that it joins the cluster by checking the log file or by checking the output of this request:   启动升级节点并通过检查日志文件或者请求输出确认已经加入了集群:

    GET _cat/nodes
    
    COPY AS CURL VIEW IN CONSOLE  
  6. Reenable shard allocation  重新开启shard分配

    Once the node has joined the cluster, reenable shard allocation to start using the node:一旦节点加入集群,重新启动shard分配:

    PUT _cluster/settings
    {"transient":{"cluster.routing.allocation.enable":"all"}} 
    COPY AS CURL VIEW IN CONSOLE  
  7. Wait for the node to recover  等待节点数据恢复

    You should wait for the cluster to finish shard allocation before upgrading the next node. You can check on progress with the  _cat/health request:  你可以等待集群完成数据shard分配之后再进行下一个节点升级。你可以通过_cat/health检查这个过程。

    GET _cat/health
    
    COPY AS CURL VIEW IN CONSOLE  

    Wait for the status column to move from yellow to green. Status greenmeans that all primary and replica shards have been allocated.等待status列从yellow变为green。status green意味着所有主要primary和备份shards意境分配了。

    Important
    During a rolling upgrade, primary shards assigned to a node with the higher version will never have their replicas assigned to a node with the lower version, because the newer version may have a different data format which is not understood by the older version.在滚动升级中,主shards永远不会将它们的备份分配到一个较低版本的节点上,因为较新版本又可能数据格式和旧版本不同。

    If it is not possible to assign the replica shards to another node with the higher version — e.g. if there is only one node with the higher version in the cluster — then the replica shards will remain unassigned and the cluster health will remain status  yellow.如果不能将备份shards分配到另一个带有更高版本的节点上-例如,如果集群里只有一个更高版本的节点,那么备份shards将保持未分配状态,那么集群会保持yellow状态。

    In this case, check that there are no initializing or relocating shards (the init and relo columns) before proceding.这种情况下,在继续下面之前,需要检查是否有未初始化或者重定向的shards(init或者relo列)

    As soon as another node is upgraded, the replicas should be assigned and the cluster health will reach status  green.一旦其它节点升级了,备份应当分配,集群健康将达到green状态。

    Shards that have not been  sync-flushed may take some time to recover. The recovery status of individual shards can be monitored with the _cat/recovery request:  没有 sync-flushed的shards需要一段时间恢复数据。个体数据恢复状态会在 _cat/recovery请求中提到。

    GET _cat/recovery
    
    COPY AS CURL VIEW IN CONSOLE  
    If you stopped indexing, then it is safe to resume indexing as soon as recovery has completed.  如果停止索引化,那么制药恢复完成那么重新进行索引化就是安全的。

  8. Repeat

    When the cluster is stable and the node has recovered, repeat the above steps for all remaining nodes. 当集群稳定了并且节点已经恢复了,重复上面的步骤升级其它节点。




Full cluster restart upgradeedit

Elasticsearch requires a full cluster restart when upgrading across major versions. Rolling upgrades are not supported across major versions. Consult this table to verify that a full cluster restart is required.

The process to perform an upgrade with a full cluster restart is as follows:

  1. Disable shard allocation

    When you shut down a node, the allocation process will immediately try to replicate the shards that were on that node to other nodes in the cluster, causing a lot of wasted I/O. This can be avoided by disabling allocation before shutting down a node:

    PUT _cluster/settings
    {"persistent":{"cluster.routing.allocation.enable":"none"}} 
    COPY AS CURL VIEW IN CONSOLE  
  2. Perform a synced flush

    Shard recovery will be much faster if you stop indexing and issue a synced-flush request:

    POST _flush/synced
    
    COPY AS CURL VIEW IN CONSOLE  

    A synced flush request is a “best effort” operation. It will fail if there are any pending indexing operations, but it is safe to reissue the request multiple times if necessary.

  3. Shutdown and upgrade all nodes

    Stop all Elasticsearch services on all nodes in the cluster. Each node can be upgraded following the same procedure described in [upgrade-node].

  4. Upgrade any plugins

    Elasticsearch plugins must be upgraded when upgrading a node. Use theelasticsearch-plugin script to install the correct version of any plugins that you need.

  5. Start the cluster

    If you have dedicated master nodes — nodes with node.master set totrue(the default) and node.data set to false —  then it is a good idea to start them first. Wait for them to form a cluster and to elect a master before proceeding with the data nodes. You can check progress by looking at the logs.

    As soon as the minimum number of master-eligible nodes have discovered each other, they will form a cluster and elect a master. From that point on, the _cat/health and _cat/nodes APIs can be used to monitor nodes joining the cluster:

    GET _cat/health
    
    GET _cat/nodes
    
    COPY AS CURL VIEW IN CONSOLE  

    Use these APIs to check that all nodes have successfully joined the cluster.

  6. Wait for yellow

    As soon as each node has joined the cluster, it will start to recover any primary shards that are stored locally. Initially, the _cat/health request will report a status of red, meaning that not all primary shards have been allocated.

    Once each node has recovered its local shards, the status will becomeyellow, meaning all primary shards have been recovered, but not all replica shards are allocated. This is to be expected because allocation is still disabled.

  7. Reenable allocation

    Delaying the allocation of replicas until all nodes have joined the cluster allows the master to allocate replicas to nodes which already have local shard copies. At this point, with all the nodes in the cluster, it is safe to reenable shard allocation:

    PUT _cluster/settings
    {"persistent":{"cluster.routing.allocation.enable":"all"}} 
    COPY AS CURL VIEW IN CONSOLE  

    The cluster will now start allocating replica shards to all data nodes. At this point it is safe to resume indexing and searching, but your cluster will recover more quickly if you can delay indexing and searching until all shards have recovered.

    You can monitor progress with the _cat/health and _cat/recovery APIs:

    GET _cat/health
    
    GET _cat/recovery
    
    COPY AS CURL VIEW IN CONSOLE  
    Once the  status column in the  _cat/health output has reached  green, all primary and replica shards have been successfully allocated.




Stopping Elasticsearchedit

An orderly shutdown of Elasticsearch ensures that Elasticsearch has a chance to cleanup and close outstanding resources. For example, a node that is shutdown in an orderly fashion will remove itself from the cluster, sync translogs to disk, and perform other related cleanup activities. You can help ensure an orderly shutdown by properly stopping Elasticsearch.

If you’re running Elasticsearch as a service, you can stop Elasticsearch via the service management functionality provided by your installation.

If you’re running Elasticsearch directly, you can stop Elasticsearch by sending control-C if you’re running Elasticsearch in the console, or by sending SIGTERM to the Elasticsearch process on a POSIX system. You can obtain the PID to send the signal to via various tools (e.g., ps or jps):

$ jps | grep Elasticsearch14542Elasticsearch 

From the Elasticsearch startup logs:

[2016-07-0712:26:18,908][INFO ][node ][I8hydUG] version[5.0.0-alpha4], pid[15399], build[3f5b994/2016-06-27T16:23:46.861Z], OS[Mac OS X/10.11.5/x86_64], JVM[OracleCorporation/JavaHotSpot(TM)64-BitServer VM/1.8.0_92/25.92-b14] 

Or by specifying a location to write a PID file to on startup (-p <path>):

$ ./bin/elasticsearch -p /tmp/elasticsearch-pid -d
$ cat /tmp/elasticsearch-pid && echo
15516
$ kill -SIGTERM 15516

Stopping on Fatal Errorsedit

During the life of the Elasticsearch virtual machine, certain fatal errors could arise that put the virtual machine in a questionable state. Such fatal errors include out of memory errors, internal errors in virtual machine, and serious I/O errors.

When Elasticsearch detects that the virtual machine has encountered such a fatal error Elasticsearch will attempt to log the error and then will halt the virtual machine. When Elasticsearch initiates such a shutdown, it does not go through an orderly shutdown as described above. The Elasticsearch process will also return with a special status code indicating the nature of the error.

JVM internal error

128

Out of memory error

127

Stack overflow error

126

Unknown virtual machine error

125

Serious I/O error

124

Unknown fatal error

1


你可能感兴趣的:(Elasticsearch Reference [5.2] » Setup Elasticsearch)