Elasticsearch 7.x生產配置


1、官方文檔

這些重要配置說明,請參考官方文檔:
https://www.elastic.co/guide/en/elasticsearch/reference/7.x/important-settings.html

 

 

 

2、參數說明

2.1 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 下。如果這些重要文件夾保留在默認位置,則Elasticsearch升級到新版本時,很有可能被刪除。

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

補充說明:在生產環境下,應用程序的數據和日志一般需要配置到獨立的磁盤分區下。比如/data目錄作為獨立的數據分區,/var/log作為應用程序日志分區。這樣做的好處是,防止因應用程序數據或日志增長,撐爆OS分區。

2.2 cluster.name

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.
某個節點只有和集群下的其他節點共享它的 cluster.name 才能加入一個集群。默認是elasticsearch,但是應該修改為更恰當的,用於描述集群目的的名稱。

cluster.name: myes

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.
一定要確保不要在不同的環境中使用相同的集群名稱。否則,節點可能會加入錯誤的集群中。

2.3 node.name

Elasticsearch uses node.name as a human readable identifier for a particular instance of Elasticsearch so it is included in the response of many APIs. It defaults to the hostname that the machine has when Elasticsearch starts but can be configured explicitly in elasticsearch.yml as follows:
默認情況下,Elasticsearch 將使用隨機生成的uuid的前7個字符作為節點id,請注意,節點ID是持久化的,並且在節點重新啟動時不會更改,因此默認節點名稱也不會更改。

也可以使用服務器的 HOSTNAME 作為節點的名稱。

node.name: ${HOSTNAME}

2.4 network.host

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] 。這足以在服務器上運行單個開發節點。

In order 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:
為了與其他服務器上的節點進行通信並形成集群,你的節點將需要綁定到非環回地址。雖然這里有很多網絡相關的配置,但通常只需要配置一下 network.host

network.host: 192.168.60.101

As soon as 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.
一旦自定義設置了 network.host ,Elasticsearch 會假定你正在從開發模式轉移到生產模式,並將許多系統啟動檢查從警告升級到異常。

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.
默認情況下,Elasticsearch假定您正在開發模式下工作。 如果未正確配置上述任何設置,則會向日志文件寫入警告,但您將能夠啟動並運行Elasticsearch節點。
一旦配置了network.host之類的網絡設置,Elasticsearch就會假定您正在轉向生產並將上述警告升級為異常。 這些異常將阻止您的Elasticsearch節點啟動。 這是一項重要的安全措施,可確保您不會因服務器配置錯誤而丟失數據。

2.5 Discovery settings

There are two important discovery and cluster formation settings that should be configured before going to production so that nodes in the cluster can discover each other and elect a master node.
在開始生產之前,應該配置兩個重要的discovery 和cluster 設置,以便群集中的節點可以相互發現並選擇主節點。

discovery.seed_hosts

Out of the box, without any network configuration, Elasticsearch will bind to the available loopback addresses and will scan local 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 you want to form a cluster with nodes on other hosts, you must use the discovery.seed_hosts setting to provide a list of other nodes in the cluster that are master-eligible and likely to be live and contactable in order to seed the discovery process. This setting should normally contain the addresses of all the master-eligible nodes in the cluster. This setting contains either an array of hosts or a comma-delimited string. Each value should be in the form of host:port or host (where port defaults to the setting transport.profiles.default.port falling back to transport.port if not set). Note that IPv6 hosts must be bracketed. The default for this setting is 127.0.0.1, [::1].
如果要在其他主機上形成包含節點的群集,則必須使用discovery.seed_hosts設置提供群集中其他節點的列表,這些節點符合主要條件且可能是實時且可聯系的,以便為發現過程設定種子。 此設置通常應包含群集中所有符合主節點的節點的地址。 此設置包含主機數組或逗號分隔的字符串。 每個值應采用host:port或host的形式(其中port默認為設置transport.profiles.default.port,如果未設置則返回transport.port)。 請注意,必須將IPv6主機置於括號內。 此設置的默認值為127.0.0.1,[:: 1]。

discovery.seed_hosts:
   - node1
   - node2
   - node3

The port will default to transport.profiles.default.port and fallback to transport.port if not specified.
如果未指定,端口將默認為transport.profiles.default.port並回退到transport.port。

If a hostname resolves to multiple IP addresses then the node will attempt to discover other nodes at all resolved addresses.
如果主機名解析為多個IP地址,則該節點將嘗試發現所有已解析地址的其他節點。

cluster.initial_master_nodes

When you start a brand new Elasticsearch cluster for the very first time, there is a cluster bootstrapping step, which determines the set of master-eligible nodes whose votes are counted in the very first election. In development mode, with no discovery settings configured, this step is automatically performed by the nodes themselves. As this auto-bootstrapping is inherently unsafe, when you start a brand new cluster in production mode, you must explicitly list the names or IP addresses of the master-eligible nodes whose votes should be counted in the very first election. This list is set using the cluster.initial_master_nodes setting.
當您第一次啟動全新的Elasticsearch集群時,會出現一個集群引導步驟,該步驟確定在第一次選舉中計票的主要合格節點集。 在開發模式下,如果未配置發現設置,則此步驟由節點本身自動執行。 由於此自動引導本質上是不安全的,因此當您在生產模式下啟動全新集群時,必須明確列出符合條件的節點的名稱或IP地址,這些節點的投票應在第一次選舉中計算。 使用cluster.initial_master_nodes設置設置此列表。

cluster.initial_master_nodes:
   - node1 
   - node2 
   - node3 

Initial master nodes can be identified by their node.name, which defaults to the hostname. Make sure that the value in cluster.initial_master_nodes matches the node.name exactly. If you use a fully-qualified domain name such as master-node-a.example.com for your node names then you must use the fully-qualified name in this list; conversely if node.name is a bare hostname without any trailing qualifiers then you must also omit the trailing qualifiers in cluster.initial_master_nodes.
初始主節點可以通過其node.name來標識,該節點默認為主機名。 確保cluster.initial_master_nodes中的值與node.name完全匹配。 如果您使用完全限定的域名(例如master-node-a.example.com)作為節點名稱,則必須在此列表中使用完全限定名稱; 相反,如果node.name是一個沒有任何尾隨限定符的裸主機名,那么您還必須省略cluster.initial_master_nodes中的尾隨限定符。

Initial master nodes can also be identified by their IP address.
初始主節點也可以通過其IP地址識別。

2.6 堆大小配置  在文件jvm.options中

By default, Elasticsearch tells the JVM to use a heap with a minimum and maximum size of 1 GB. When moving to production, it is important to configure heap size to ensure that Elasticsearch has enough heap available.
默認情況下,Elasticsearch告訴JVM使用最小和最大大小為1 GB的堆。 遷移到生產環境時,配置堆大小以確保Elasticsearch有足夠的可用堆是很重要的。

Elasticsearch will assign the entire heap specified in jvm.options via the Xms (minimum heap size) and Xmx (maximum heap size) settings.
Elasticsearch將通過Xms(最小堆大小)和Xmx(最大堆大小)設置分配jvm.options中指定的整個堆。

The value for these setting depends on the amount of RAM available on your server. Good rules of thumb are:
這些設置的值取決於服務器上可用的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)的截止值以上; 確切的截止值變化但接近32 GB。

Here are examples of how to set the heap size via the jvm.options file:
以下是如何通過jvm.options文件設置堆大小的示例:

比如公司有一個elasticsearch集群,每個節點是8G內存,那么可以設置如下。

[root@elastic1 elasticsearch-7.0.1]# vi config/jvm.options 
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms4g
-Xmx4g

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM