1. 程式人生 > >elasticsearch6.5安裝配置

elasticsearch6.5安裝配置

 

1 下載並安裝.tar.gz

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.4.tar.gz
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.4.tar.gz.sha512
shasum -a 512 -c elasticsearch-6.5.4.tar.gz.sha512 
tar -xzf elasticsearch-6.5.4.tar.gz
cd elasticsearch-6.5.4/ 

2 從命令列執行Elasticsearch

./bin/elasticsearch

預設情況下,Elasticsearch在前臺執行,將其日誌列印到標準輸出(stdout),然後按下即可停止Ctrl-C

3 檢查Elasticsearch是否正在執行

您可以測試你的Elasticsearch節點通過傳送一個HTTP請求的埠上執行9200localhost

GET /

哪個應該給你一個像這樣的回覆:

{
  "name" : "Cp8oag6",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "AT69_T_DTp-1qgIJlatQqA",
  "version" : {
    "number" : "6.5.4",
    "build_flavor" : "default",
    "build_type" : "zip",
    "build_hash" : "f27399d",
    "build_date" : "2016-03-30T09:51:41.449Z",
    "build_snapshot" : false,
    "lucene_version" : "7.5.0",
    "minimum_wire_compatibility_version" : "1.2.3",
    "minimum_index_compatibility_version" : "1.2.3"
  },
  "tagline" : "You Know, for Search"
}

4 作為守護程式執行

要將Elasticsearch作為守護程式執行,請-d在命令列中指定,並使用以下-p選項將程序ID記錄在檔案中

./bin/elasticsearch -d -p pid

以在$ES_HOME/logs/目錄中找到日誌訊息。

要關閉Elasticsearch,請終止pid檔案中記錄的程序ID :

kill `cat pid`


5 配置Elasticsearch

Elasticsearch具有良好的預設值,只需要很少的配置。可以使用Cluster Update Settings API 在正在執行的群集上更改大多數設定 。

配置檔案應包含特定於節點的設定(例如node.namepaths),或節點為了能夠加入群集而需要的設定,例如cluster.namenetwork.host

Elasticsearch有三個配置檔案:

  • elasticsearch.yml 用於配置Elasticsearch
  • jvm.options          用於配置Elasticsearch JVM設定
  • log4j2.properties 用於配置Elasticsearch日誌記錄

這些檔案位於config目錄中。

 

6 日誌配置

log4j2.properties檔案配置

appender.rolling.type = RollingFile 
appender.rolling.name = rolling
appender.rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}.log 
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] [%node_name]%marker %.-10000m%n
appender.rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-%d{yyyy-MM-dd}-%i.log.gz 
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy 
appender.rolling.policies.time.interval = 1 
appender.rolling.policies.time.modulate = true 
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy 
appender.rolling.policies.size.size = 256MB 
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.fileIndex = nomax
appender.rolling.strategy.action.type = Delete 
appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path}
appender.rolling.strategy.action.condition.type = IfFileName 
appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-* 
appender.rolling.strategy.action.condition.nested_condition.type = IfAccumulatedFileSize 
appender.rolling.strategy.action.condition.nested_condition.exceeds = 2GB 

配置RollingFileappender

登入 /var/log/elasticsearch/production.log

滾動日誌到/var/log/elasticsearch/production-yyyy-MM-dd-i.log; 日誌將在每個捲上壓縮i並將遞增

使用基於時間的滾動策略

每天滾動日誌

在日界上對齊卷(而不是每隔二十四小時滾動)

使用基於大小的滾動策略

256 MB後滾動日誌

滾動日誌時使用刪除操作

僅刪除與檔案模式匹配的日誌

該模式僅刪除主日誌

僅在我們累積了太多壓縮日誌時才刪除

壓縮日誌的大小條件為2 GB

appender.rolling.strategy.type = DefaultRolloverStrategy 
appender.rolling.strategy.action.type = Delete 
appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path} 
appender.rolling.strategy.action.condition.type = IfFileName 
appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-* 
appender.rolling.strategy.action.condition.nested_condition.type = IfLastModified 
appender.rolling.strategy.action.condition.nested_condition.age = 7D 

配置 DefaultRolloverStrategy

配置Delete處理翻轉的操作

Elasticsearch日誌的基本路徑

處理翻轉時應用的條件

從與glob匹配的基本路徑中刪除檔案 ${sys:es.logs.cluster_name}-*; 這是日誌檔案滾動到的glob; 這隻需要刪除已滾動的Elasticsearch日誌,但不能刪除已棄用和慢速日誌

應用於與glob匹配的檔案的巢狀條件

保留日誌七天

 

配置日誌記錄級別

logger.<unique_identifier>.name = <name of logging hierarchy>
logger.<unique_identifier>.level = <level>

7 path.datapath.logs

path:
  logs: /var/log/elasticsearch
  data: /var/data/elasticsearch
設定為多條路徑:
path:
  data:
    - /mnt/elasticsearch_1
    - /mnt/elasticsearch_2
    - /mnt/elasticsearch_3

8 cluster.name

cluster.name: es-prod

9 node.name

node.name: ${HOSTNAME}

10 network.host

network.host: 192.168.1.10

11 發現設定

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

如果未指定 ,埠將預設為transport.profiles.default.port和回退 transport.tcp.port

解析為多個IP地址的主機名將嘗試所有已解析的地址。

如果有三個符合主節點的節點,則應將最小主節點設定為(3 / 2) + 12

discovery.zen.minimum_master_nodes: 2

12 設定堆大小

以下是如何通過jvm.options檔案設定堆大小的示例:

-Xms2g 
-Xmx2g 

將最小堆大小設定為2g。

將最大堆大小設定為2g。