ES 配置
ES 提供了很多預設的引數設定,使我們不用新增任何引數就可以成功的啟動ES。作為一個認真的學習者。我們還是來一起看看 如何更好的自定義 ES配置。詳細的配置內容,可以參考 https://www。elastic。co/guide/en/elasticsearch/reference/current/settings。html。
ES 的屬性,分為 靜態屬性 和 動態屬性。所有的靜態屬性,都必須重啟後才能生效。對於動態屬性可以透過呼叫
POST _nodes/reload_secure_settings
{
“secure_settings_password”: “s3cr3t”
}
”s3cr3t“,是ES-keystore生成的秘鑰。呼叫時需要替換為自己設定的秘鑰。
支援熱載入的屬性有: Azure repository plugin,EC2 discovery plugin,GCS repository plugin,S3 repository plugin, Monitoring settings,Watcher settings。如果想了解更多,可以在 https://www。elastic。co/guide/en/elasticsearch/reference/current/secure-settings。html查詢。
在ES的安裝目錄,很明顯的有一個 config目錄。進入之後,可以看到
elasticsearch。keystore: Elasticsearch提供了金鑰庫和elasticsearch-keystore用於管理金鑰庫設定的工具。
接下來,我們重點來看下和配置相關的三個檔案
elasticsearch。yml:
jvm。options:
log4j2。properties:
和許可權相關的。這裡我們先不深入瞭解。
role_mapping。yml
roles。yml
users
users_roles
elasticsearch。keystore
elasticsearch 介紹
有些設定是非常敏感的,僅依靠檔案系統許可權來保護它們的值是不夠的。對於這個用例,Elasticsearch提供了一個金鑰儲存庫和Elasticsearch-keystore工具來管理金鑰儲存庫中的設定。設計僅從金鑰庫中讀取某些設定。但是,金鑰庫沒有驗證來阻止不支援的設定。將不支援的設定新增到金鑰庫中會導致Elasticsearch無法啟動。
對金鑰庫的所有修改僅在重新啟動Elasticsearch之後生效。
這些設定與 elasticsearch。yml 配置檔案中的常規設定一樣,需要在叢集的每個節點上指定。當前,所有安全設定都是特定於節點的設定,在每個節點上必須具有相同的值。
elasticserche-keystore 使用
來看一下 elasticsearch-keystore 命令
bin/elasticsearch-keystore
* [add
* [add-file (
* [create] [-p]: 建立一個新的Es keyStore
* [list] : 展示keystore的項
* [passwd] : 修改 keystore的密碼
* [remove
* [upgrade] : 升級金鑰庫的內部格式。
* [has-passwd] - 驗證是否有keystore並且有密碼保護
簡單使用:
# 建立一個keystore
> 。/elasticsearch-keystore create -p
## //輸入密碼
Enter new password for the elasticsearch keystore (empty for no password):
## // 確認密碼
Enter same password again:
## // 已經有keystore檔案了,是否要覆蓋
An elasticsearch keystore already exists。 Overwrite? [y/N]y
Created elasticsearch keystore in /Users/bjhl/fxb_applicaton/fxb_program/elasticsearch-7。10。1/config/elasticsearch。keystore
# 檢視秘鑰庫
> 。/elasticsearch-keystore list
## // 輸入密碼
Enter password for the elasticsearch keystore :
keystore。seed # 秘鑰庫
# 新增設定到秘鑰庫中
> 。/elasticsearch-keystore add settings。name
## // 輸入密碼
Enter password for the elasticsearch keystore :
## 輸入新增的設定的value
Enter value for settings。name:
# 新增檔案到秘鑰庫
> 。/elasticsearch-keystore add-file file。name xxx。xx
Enter password for the elasticsearch keystore :
# 刪除配置
> 。/elasticsearch-keystore remove settings。name
Enter password for the elasticsearch keystore :
# 更新keystore
> 。/elasticsearch-keystore upgrade
Enter password for the elasticsearch keystore :
elasticsearch。yml
# - 叢集相關配置 -
# 叢集的名稱
cluster。name:my-application
# 更多關於叢集的配置,參考:https://www。elastic。co/guide/en/elasticsearch/reference/current/modules-cluster。html
# 跨叢集配置:參考:https://www。elastic。co/guide/en/elasticsearch/reference/current/ccr-settings。html
# 節點的名稱
node。name:fxb-cluster-node-1
# 可以為叢集新增一些自定義的屬性配置
node。attr。zhName:方小白
# 更多節點相關的配置,參考
# - 路徑相關配置 -
# 指定儲存資料的位置,多個路徑的話,使用`,`分割 (separate multiple locations by comma)
path。data:/path/to/data
# 日誌檔案儲存地址
path。logs:/path/to/logs
# - 記憶體相關 -
# Lock the memory on startup:
bootstrap。memory_lock:true
# 確保將堆大小設定為系統上可用記憶體的一半左右,並確保程序的所有者可以使用此限制。系統交換記憶體時,Elasticsearch的效能較差。
# —————————————————— Network ——————————————————-
# Set the bind address to a specific IP (IPv4 or IPv6):
network。host:192。168。0。1
# 啟動埠
http。port:9200
# 更多可以參考: https://www。elastic。co/guide/en/elasticsearch/reference/current/modules-network。html
# ————————————————- Discovery ——————————————————
# 提供群集中符合主機資格的節點的地址列表。
# The default list of hosts is [“127。0。0。1”, “[::1]”]
discovery。seed_hosts:[“host1”,“host2”]
# 設定初始的符合主機資格的節點集,【靜態屬性】
cluster。initial_master_nodes:[“node-1”,“node-2”]
# 更多關於發現相關的配置,參考:https://www。elastic。co/guide/en/elasticsearch/reference/current/ccr-settings。html
# —————————————————— Gateway ——————————————————-
# Block initial recovery after a full cluster restart until N nodes are started:
gateway。recover_after_nodes:3
#
# 更多內容,參考https://www。elastic。co/guide/en/elasticsearch/reference/current/modules-gateway。html
#
# —————————————————— Various ——————————————————-
# Require explicit names when deleting indices:
action。destructive_requires_name:true
JVM 引數 => jvm。options
jvm。options包含使用特殊語法的以行分隔的JVM引數列表:
# 表示註釋
以-開頭的行被視為獨立於JVM版本而應用的JVM選項
以<數字>:-開頭的行被視為JVM選項,只有當JVM的版本與該數字匹配時才適用,比如:8:-Xmx2g
以 <數字>-:開頭 的行被視為JVM選項,僅在JVM版本大於或等於該數字時才適用。比如:8-:-Xmx2g
以<數字>-<數字>:開頭的行被視為僅在JVM版本落在兩個數字範圍內時才適用的JVM選項。比如:8-9:-Xmx2g
Elasticsearch預設配置JVM使用最小和最大大小為1 GB的堆。
## JVM configuration
## IMPORTANT: JVM heap size
## 參考 https://www。elastic。co/guide/en/elasticsearch/reference/current/important-settings。html#heap-size-settings
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
-Xms1g
-Xmx1g
## Expert settings: 高階設定
## 不理解下面的屬性,不建議修改
## GC configuration
8-13:-XX:+UseConcMarkSweepGC
8-13:-XX:CMSInitiatingOccupancyFraction=75
8-13:-XX:+UseCMSInitiatingOccupancyOnly
## G1GC Configuration
# NOTE: G1 GC is only supported on JDK version 10 or later
# to use G1GC, uncomment the next two lines and update the version on the
# following three lines to your version of the JDK
# 10-13:-XX:-UseConcMarkSweepGC
# 10-13:-XX:-UseCMSInitiatingOccupancyOnly
14-:-XX:+UseG1GC
14-:-XX:G1ReservePercent=25
14-:-XX:InitiatingHeapOccupancyPercent=30
## JVM temporary directory
-Djava。io。tmpdir=${ES_TMPDIR}
## heap dumps
# generate a heap dump when an allocation from the Java heap fails
# heap dumps are created in the working directory of the JVM
-XX:+HeapDumpOnOutOfMemoryError
# specify an alternative path for heap dumps; ensure the directory exists and
# has sufficient space
-XX:HeapDumpPath=data
# specify an alternative path for JVM fatal error logs
-XX:ErrorFile=logs/hs_err_pid%p。log
## JDK 8 GC logging
8:-XX:+PrintGCDetails
8:-XX:+PrintGCDateStamps
8:-XX:+PrintTenuringDistribution
8:-XX:+PrintGCApplicationStoppedTime
8:-Xloggc:logs/gc。log
8:-XX:+UseGCLogFileRotation
8:-XX:NumberOfGCLogFiles=32
8:-XX:GCLogFileSize=64m
# JDK 9+ GC logging
9-:-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc。log:utctime,pid,tags:filecount=32,filesize=64m
日誌引數
可以看到 ElasticSearch 使用log4j2日誌,關於此日誌的配置,這裡就不多贅述了。
系統配置
除了對 ES 的配置之外,如果想要更好的提升ES效能,還需對 ES所依賴的宿主機進行一些屬性配置。比如:比如禁止swap等。更多內容,參考:https://www。elastic。co/guide/en/elasticsearch/reference/current/system-config。html。
最後
希望和你一起遇見更好的自己
qrcode