1. 程式人生 > >Elasticsearch簡單入門--elasticsearch重要的配置項

Elasticsearch簡單入門--elasticsearch重要的配置項

Important Elasticsearch configuration

雖然Elasticsearch只需要很少的配置,但是有許多設定項需要手動配置,並且應該明確地被設定在投入生產之前。

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

1. path.data 和 path.logs

如果你使用zip 和 tar.gz檔案檔案解壓縮安裝的,data和logs目錄是$ES_HOME的子目錄,如果這些重要的資料夾被保留在它們的預設位置,那麼在將Elasticsearch升級到新版本時刪除它們的風險很高(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)。

在生產中使用,您幾乎肯定希望更改資料和日誌資料夾的位置

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

這個path.data配置項可以被設定為多個路徑,在這種情況下,所有路徑都將用於儲存資料(儘管屬於單個shard的檔案都將儲存在相同的資料路徑上)

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

2. cluster.name

當一個節點與叢集中的所有其他節點共享它的cluster.name時,它才能加入到叢集中(A node can only join a cluster when it shares its cluster.name

 with all the other nodes in the cluster),意思就是一個節點跟其他節點有相同的cluster.name時,才能成為一個叢集, 節點配置中 叢集預設的名稱為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.)

3. node.name

預設,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

# node.name同樣可以被設定為伺服器的主機名稱
node.name: ${HOSTNAME}

4. bootstrap.memory_lock

沒有一個JVM被交換到磁碟上,這對於節點的健康非常重要 (It is vitally important to the health of your node that none of the JVM is ever swapped out to disk),

實現這一點的一種方法是設定載入程式。memory_lock設定為true。要使此設定生效,需要首先配置其他系統設定,

看到啟用引導。memory_lock獲取關於如何正確設定記憶體鎖定的詳細資訊 

參考:https://www.elastic.co/guide/en/elasticsearch/reference/5.6/setup-configuration-memory.html#mlockall

5. network.host

預設情況下,Elasticsearch只繫結到環回地址。127.0.0.1(::1)。這足以在伺服器上執行單個開發節點。(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.)

實際上,可以從單個節點上相同的$ES_HOME位置啟動多個節點。這對於測試Elasticsearch形成叢集的能力很有用,但是在生產環境中不推薦使用這種配置.

為了與其他伺服器上的節點通訊並形成叢集,您的節點將需要繫結到非環回地址,雖然有許多網路設定,通常您需要配置的是network.host:(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:)

network.host: 192.168.1.10

注意:一旦為網路提供了自定義設定。Elasticsearch假設您正在從開發模式轉移到生產模式,並將許多系統啟動檢查從警告升級到異常。(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 Development mode vs production modeedit for more information. 

檢視更多關係開發模式和生成模式的資訊 

https://www.elastic.co/guide/en/elasticsearch/reference/5.6/system-config.html#dev-vs-prod

6. discovery.zen.ping.unicast.hosts

開箱即用,無需任何網路配置,Elasticsearch將繫結到可用的環回地址,並掃描埠9300到9305,嘗試連線到同一伺服器上執行的其他節點。這提供了一種無需進行任何配置的自動叢集體驗(This provides an auto- clustering experience without having to do any configuration),在使用其他伺服器上的節點形成叢集時,必須提供叢集中可能是活動的和可接觸的其他節點的種子列表(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)

例如:

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

# 或者
discovery.zen.ping.unicast.hosts: ["192.168.1.10", "192.168.1.11", "192.168.1.12"]

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.

7.  discovery.zen.minimum_master_nodes

為了防止資料丟失,配置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.)

使用minumum_master_nodes避免腦裂的更多詳細解釋 參考:https://www.elastic.co/guide/en/elasticsearch/reference/5.6/modules-node.html#split-brain

避免腦裂,該設定項應該被設定為 a quorum of master-eligible nodes(候選主節點的法定人數)

(master_eligible_nodes/2)+1

換句話說,如果有三個候選主節點,那麼minumum master nodes應該被設定為 (3/2)+1 或者是2

discovery.zen.minumum_master_nodes: 2