#生產環境配置
```
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#集群名稱,默認是elasticsearch
cluster.name: es_prod
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#節點名稱
node.name: docker_node1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#可以指定es的數據存儲目錄,默認存儲在es_home/data目錄下
path.data: /var/data/elasticsearch
#
# Path to log files:
#可以指定es的日志存儲目錄,默認存儲在es_home/logs目錄下
path.logs: /var/log/elasticsearch
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#鎖定物理內存地址,防止elasticsearch內存被交換出去,也就是避免es使用swap交換分區
bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#為es設置ip綁定,默認是127.0.0.1,也就是默認只能通過127.0.0.1 或者localhost才能訪問
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#為es設置自定義端口,默認是9200
#在同一個服務器中啟動多個es節點的話,默認監聽的端口號會自動加1:例如:9200,9201,9202...
http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#設置其他節點連接此節點的地址,如果不設置的話,則自動獲取
network.publish_host: 172.16.16.179
#通過這個ip列表進行節點發現,組建集群
discovery.zen.ping.unicast.hosts: ["172.16.16.179:9300","172.16.16.179:9301","172.16.16.178:9302"]
#discovery.zen.ping_timeout: 60s
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#這個參數決定了在選主過程中需要有多少個節點通信,通過配置這個參數來防止集群腦裂現象 (集群總節點數量/2)+1
discovery.zen.minimum_master_nodes: 2
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#gateway.recover_after_nodes: 3
#預期的節點加入集群,就進行數據恢復處理
gateway.expected_nodes: 3
#如未達到預期的節點加入集群,需要等待的時間
gateway.recover_after_time: 1m
#一個集群中的N個節點啟動后,才允許進行數據恢復處理,默認是1
gateway.recover_after_nodes: 2
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
node.master: true
node.data: true
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
xpack.ml.enabled: false
xpack.security.enabled: false
xpack.monitoring.enabled: false
xpack.graph.enabled: false
xpack.watcher.enabled: false
node.max_local_storage_nodes: 256
transport.tcp.port: 9300
transport.tcp.compress: true
action.auto_create_index: .security,.monitoring*,.watches,.triggered_watches,.watcher-history*,.ml*
```
將日志和數據,文件夾權限為es的user
添加:
path.logs: /var/log/elasticsearch
path.data: /var/data/elasticsearch
拷貝配置文件config下文件elasticsearch.yml到其他目錄/usr/local/esconfig/
啟動命令:
ES_PATH_CONF=/usr/local/esconfig/ ./bin/elasticsearch -d
#### 將es的bin加入環境變量PATH中
```
export ES_HOME=/usr/local/elasticsearch-6.2.2
export PATH=$ES_HOME/bin
```
執行source profile生效后啟動
ES_PATH_CONF=/usr/local/esconfig/ elasticsearch -d
#### 集群重啟優化
shard重新復制,移動,刪除,再次移動的過程,會大量的耗費網絡和磁盤資源。對于數據量龐大的集群來說,可能導致每次集群重啟時,都有TB級別的數據無端移動,可能導致集群啟動會耗費很長時間。
比如我本來有10個node,集群重啟時,有5個node
1.復制其他5個node的shard到本地
2.此時上線其他5個node
3.復制到新上線的5個node,原來的5個node刪除自己的shard
生產優化的配置:
gateway.expected_nodes: 3
gateway.recover_after_time: 1m
gateway.recover_after_nodes: 2
等待至少2個節點在線,然后等待最多1分鐘,或者3個節點都在線,開始shard recovery恢復的過程

#### es關閉
jps
ps -ef|grep Elasticsearch
kill -SIGTERM 15516
- 目錄
- 前言
- ElasticSearch基礎
- 基礎概念
- 生產環境配置
- ElasticSearch插件
- ElasticSearch-head插件
- 中文分詞
- ElasticSearch安全插件x-pack
- ElasticSearch查詢
- ElasticSearch語法
- 創建索引
- 新增文檔
- 修改文檔
- 查詢文檔
- 簡單查詢
- 基礎查詢
- 聚合查詢
- 刪除文檔
- ElasticSearch高級查詢
- filter語法
- 關聯查詢
- SpringBoot集成ES的操作
- java操作ES
- Spring-data-elasticsearch操作ES
- SpringBoot性能優化
- ElasticSearch的優化
- ElasticSearch系統優化
- ElasticSearch數據的備份與恢復
- ElasticSearch性能調優
- ElasticSearch集群監控
- ElasticSearch問題匯總
- ElasticSearch問題
- ElasticSearch學習網站