分片shardsES是个分布式的搜索引擎, 所以索引通常都会分解成不同部分, 而这些分布在不同节点的数据就是分片.
ES自动管理和组织分片, 并在必要的时候对分片数据进行再平衡分配
副本replicas为了提升访问压力过大是单机无法处理所有请求的问题,Elasticsearch集群引入了副本策略replica。副本策略对index中的每个分片创建冗余的副本,
处理查询时可以把这些副本当做主分片来对待(primary shard),此外副本策略提供了高可用和数据安全的保障,当分片所在的机器宕机,
Elasticsearch可以使用其副本进行恢复,从而避免数据丢失。
调整分片和副本原则A:索引不存在时,可以自定义副本和分片数
B:索引存在,则只能修改副本
调整分片和副本常用命令
curl -H "Content-Type: application/json" -XPUT 'http://10.10.10.53:9200/test5/' -d'{"settings":{"number_of_shards":3,"number_of_replicas":0}}'
curl -H "Content-Type: application/json" -XPUT 'http://10.10.10.46:9200/blog' -d'{"settings": {"number_of_shards":3,"number_of_replicas":2}}';
curl -H "Content-Type: application/json" -XPUT 'http://10.10.10.53:9200/test4/_settings' -d'{"index":{"number_of_replicas":3}}'
查看集群node 信息curl -XGET http://10.10.10.46:9200/_cat/nodes?pretty
查看集群索引curl -XGET http://10.10.10.46:9200/_cat/indices?pretty
定期自动清理索引这里使用LINUX中的Crontab进行定时任务来删除xx天的索引。我们在定义logstash向elasticsearch中输出索引的格式为XXX-2019.08.10,因此,我们可以先定义一个脚本:
touch es_clear.sh
vim es_clear.sh
#! /bin/bash
DATA=`date -d "-xx days" "+%Y.%m.&d"`
curl -H "Content-Type:application/json" -XDELETE 'http://192.24.4.143:9200/*-'${DATA}''
chmod +x es_clear.sh
首先在界面敲入:crontab -e后回车,可以打开crontab的编辑界面
0 1 * * * /home/elkpro/scripts/es_clear.sh