(四)elasticsearch 5x 索引管理
来源:互联网 发布:剔除异常数据的方法 编辑:程序博客网 时间:2024/05/21 11:03
首先是索引运行中的常用命令:
1.cluster-allocation-explain API
这个API主要是为了方便解决下面两个问题:
对于不能指派(unassigned)的分片: 解释这些分片不能被指派(到某个节点)的原因.
对于已指派的分片: 解决这些分片指派到特定节点的理由.
curl -XPOST ip:9200/_cluster/allocation/explain?prettycurl -XGET ip:9200/_cluster/allocation/explain?pretty -d '{"index":"my_index","shard":0,"primary":true}'//查看指定的node
参考文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-allocation-explain.html
默认情况,集群会等待一分钟来查看节点是否会重新加入,如果这个节点在此期间重新加入,重新加入的节点会保持其现有的分片数据,不会触发新的分片分配。
通过修改参数delayed_timeout
,默认等待时间可以全局设置也可以在索引级别进行修改PUT /_all/_settings { "settings": { "index.unassigned.node_left.delayed_timeout": "5m" }}
参考文档:https://www.elastic.co/guide/cn/elasticsearch/guide/current/_delaying_shard_allocation.html
3.cluster.routing.allocation.enable
正常情况下,Elasticsearch 希望你的数据被完全的复制和均衡的分布。如果你手动关闭了一个节点,集群会立刻发现节点的丢失并开始再平衡。如果节点的维护是短期工作的话,这一点就很烦人了,因为大型分片的再平衡需要花费相当的时间(想想尝试复制 1TB 的数据——即便在高速网络上也是不一般的事情了)。
此命令可以停止分片的自动分配
PUT /_cluster/settings{ "transient" : { "cluster.routing.allocation.enable" : "none" }}此命令可以开启分片的自动分配
PUT /_cluster/settings{ "transient" : { "cluster.routing.allocation.enable" : "all" }}
参考文档:https://www.elastic.co/guide/cn/elasticsearch/guide/current/_rolling_restarts.html
索引运行过程中有时出一些问题,以下是遇到过的问题及解决办法.
问题1:索引red,有主节点未分配
allocation_status : no_valid_shard_copy
原因是直接在服务器上删除了某个节点的数据及备份,导致该节点为空,且没有任何备份.此时只需要强制将空的主分片分配给某个节点就可以了,命令:
POST /_cluster/reroute?pretty -d '{ "commands":[{ "allocate_empty_primary":{"index":"my_index","shard":0,"node":"node_name","accept_data_loss":true} }]}'
相似命令,用于分配给拥有旧数据的节点,有丢失数据的风险:
POST /_cluster/reroute?pretty -d '{ "commands":[{ "allocate_stale_primary":{"index":"my_index","shard":0,"node":"node_name","accept_data_loss":true} }]}'
使用前请参考官网文档:https://www.elastic.co/guide/en/elasticsearch/reference/5.6/cluster-reroute.html
问题2:索引red,有主节点未分配
failed to obtain in-memory shard lock,ShardLockObtainFailedException,obtaining shard lock timed out after 5000ms
原因是碎片分配器在5次尝试失败后不再尝试,只需要调整最大重试次数,或者使用重试命令即可.
//重试curl -XPOST ip:9200/_cluster/reroute?retry_failed//设置最大重试次数curl -XPUT ip:9200/my_index/_settings?pretty -d '{ "index.allocation.max_retries" : 10}'问题参考:https://github.com/elastic/elasticsearch/issues/23199
- (四)elasticsearch 5x 索引管理
- [Elasticsearch] 索引管理 (四) - 动态映射
- (三)elasticsearch 5x 索引优化
- [Elasticsearch] 索引管理 (一)
- [Elasticsearch] 索引管理 (二)
- [Elasticsearch] 索引管理
- elasticsearch 索引 Warmer 管理
- Elasticsearch索引管理
- elasticsearch索引管理
- (四)ElasticSearch索引创建
- (一)elasticsearch 5x 索引创建,修改及模板使用
- ElasticSearch(十)-索引管理
- Elasticsearch索引管理-reindex重建索引
- ElasticSearch Java Api(四) -删除索引
- ElasticSearch Java Api(四) -删除索引
- ElasticSearch Java Api(四) -删除索引
- ElasticSearch Java Api(四) -删除索引
- [Elasticsearch] 索引管理 (五) - 默认映射,重索引,索引别名
- [蓝书/Ch5] Astronauts UVALive
- 笔试_oracle(4)
- 从零开始前端学习[31]:css3中新增加的一些背景属性
- 关于机械硬盘的一点常识
- composer创建laravel新项目流程
- (四)elasticsearch 5x 索引管理
- 数据结构入门---栈(上)
- 在ubuntu终端退出jupyter notebook
- C语言实验——圆柱体计算
- Java--day04 循环语句、方法
- css中的子元素设置绝对定位问题
- 安卓编程之获取系统当前时间
- 从零开发B/S机架应用程序(一)
- 单例模式 随笔