本文簡要介紹ES5版本集群部署時的要點。 更多相關信息請參閱官網。
部分配置未在生產環境體現。 生產中2個集群20台centOS,總數據15TB,90億條。 實時寫入5000條/s, 最大7萬/s。
環境准備:
1. vi /etc/sysctl.conf 加入:
vm.max_map_count=262144
執行 sysctl -p 使配置生效
2. vi /etc/security/limits.d/20-nproc.conf #打開進程數
* soft nproc 65536
3. vi /etc/security/limits.conf #打開文件數
* soft nofile 65536
* hard nofile 65536
* - memlock unlimited
ES配置:
- 設置至少1台純Master, 2台混合Data/Master。 合計3台master的集群。 所有的bulk請求僅post到master中。
- 設置約50%的內存給ES, 如Xms=Xmx=24G
-
對master,由於bulk請求涉及頻繁gc, 設置為如下的G1GC。
-XX:+UseG1GC
- 將所有master 的ip地址更新到discovery file插件配置中。
node.attr.rack: crm-master-01
node.name: golden-master01
network.publish_host: 10.27.1.1cluster.name : goldeneye
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300
path:
data:
- /home/data1
- /home/data2bootstrap.memory_lock: true
discovery.zen.minimum_master_nodes: 2
action.destructive_requires_name: true
script.max_compilations_per_minute: 120
indices.query.bool.max_clause_count: 4096##===================MASTER NODE =========================
node.master: true
node.data: false
node.ingest: true
discovery.zen.ping_timeout: 10sxpack.monitoring.history.duration: 1d
xpack.graph.enabled: false
xpack.watcher.enabled: false
#xpack.security.enabled: false
xpack.security.dls_fls.enabled: false
xpack.security.transport.filter.enabled: false##===================DATA NODE =========================
node.master: false
node.data: true
node.ingest: falsehttp.enabled: false
xpack.security.enabled: true
xpack.monitoring.enabled: true
xpack.graph.enabled: false
xpack.watcher.enabled: false
集群settings
curl -XPUT localhost:9200/_cluster/settings -d '
{
"transient": {
"cluster": {
"routing": {
"rebalance": {
"enable": "none" #初始導入前,禁用shard移動
},
"allocation": {
"node_concurrent_incoming_recoveries": "6", #初始導入后,將replica設為1時, 加速replica復制速度。默認為2
"node_concurrent_outgoing_recoveries": "6"
}
}
},
"indices": {
"recovery": {
"max_bytes_per_sec": "500mb" #初始導入后,將replica設為1時, 加速replica復制速度,默認為40m
},
"store": {
"throttle": {
"type": "merge",
"max_bytes_per_sec": "500m" #數據導入時,及_forcemerge?max_num_segments=3時加速
}
}
}
}
}
'
創建庫Template
curl -XPUT localhost:9200/_template/crm_v5 -d '
{
"template": "crm*",
"aliases": {
"crm_v5.0": {}
},
"settings": {
"index": {
"number_of_shards": "1",
"number_of_replicas": "1", #初始化導入時設置 0,
"refresh_interval": "10s", #初始化導入時設置 -1
"translog.durability":"async", #大量寫入場景
"translog.flush_threshold_size":"1024m" #默認512m
"max_result_window": "5000000",
"max_rescore_window":"20000",
"unassigned.node_left.delayed_timeout": "10m",
"search.slowlog.threshold.query.warn":"30s",
"indexing.slowlog.threshold.index.warn": "10s"
}
},
"mappings": {
"customer": {
"_all": { "enabled": false }, #內存優化
"properties": {
字段使用盡量短的類型:能short就不要使用int,能half 就不要使用float。
如long,integer,short, byte
float, half_float
"end_time": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis" #兩種格式2016-0-01T00:00:00 +08:00
}
啟動全量導入作業
更新template的 number_of_replicas=0,refresh_interval=-1
全量導入完成
1. 確認已導入的庫大小, 對大於30GB的庫,重新設置shard個數number_of_shards,使每個shard約為30GB。 使用 _reindex 和_alias 接口配合完成。
2. 合並每個shard的segment數目 , 增強search速度。
curl -XPOST /crm*/_forcemerge?max_num_segments=3
3. 啟動副本備份。 number_of_replicas=1
curl -XPUT 'localhost:9200/crm*/_settings' -d ' { "index" : { "number_of_replicas" : 1 } }'
運維期間
A: 移動Index所屬節點
curl -XPUT localhost:9200/_cluster/reroute 遷移節點數據
{
"commands" : [ {
"move" :
{
"index" : "crm-0720", "shard" : 0,
"from_node" : "data02", "to_node" : "data03"
}
}]
}
如果關閉一個節點,則執行reroute前, 還必須禁用系統自動的shard分配
curl -XPUT localhost:9200/_cluster/settings -d '{ "transient" : { "cluster.routing.allocation.enable" : "none" } }' #默認為all
PUT /_cluster/settings
{
"persistent" : {
"cluster.routing.allocation.enable":"none",
"cluster.routing.rebalance.enable":"replicas",
"action.destructive_requires_name":true
}
}
當前文件夾內查找關鍵字,顯示所在文件,所在行,行內容:
grep -nHIrF KeyWord ./