elasticsearch日常排错

系列文章目录

第一章 es集群搭建
第二章 es集群基本操作命令
第三章 es基于search-guard插件实现加密认证
第四章 es常用插件
第五章 es数据迁移之elasticdump
第六章 es数据迁移之logstash



前言

整理部分生产环境中遇到的es集群问题及解决方案。

提示:以下是本篇文章正文内容,下面案例可供参考

一、es集群启动相关报错

1、错误提示:
	/export/server/elasticsearch-6.8.13/plugins/plugins.zip/plugin-descriptor.properties: Not a directory
	
背景: 
	在启动es集群时,发现集群启动失败,经过查看es日志发现上述plugin-descriptor.properties不是一个目录的错误
	
解决方法:
	移除/export/server/elasticsearch-6.8.13/plugins/下的plugins.zip这个重启即可。切记在es的plugins目录下不能存在类似.zip或.tar.gz、.tar等文件。


2、错误提示:
	root用户启动es集群失败

背景:
	在启动es集群时,未切换为创建的elasticsearch普通用户,采用root超管用户启动,结果失败。查看日志是不能以root身份启动集群

解决方法:
	切换为自己部署es集群时创建的普通用户启动即可

二、索引只允许读操作,不允许其他操作

1、错误提示:
	Caused by: org.springframework.data.elasticsearch.ElasticsearchException: Bulk indexing has failures. Use ElasticsearchException.getFailedDocuments() for detailed messages [{44499=ElasticsearchException[Elasticsearch exception [type=cluster_block_exception, reason=blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];]]}]

背景:
	在es磁盘达到告警后,对es集群三台服务器的磁盘进行了扩容,在扩容完成后,重新启动es集群,对某个索引执行相关的操作命令时报上述错误。

解决方法:
	执行以下查看命令
		curl -XGET http://ip:9200/_settings
	
	找到以下部分
		blocks:{
	      read_only_allow_delete:true       
		}
		true:代表只读
		false:代表正常所有 权限
	
	执行下方的解决此问题的命令: 及关闭只读由true改为false
		curl -XPUT -H "Content-Type: application/json" http://127.0.0.1:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": false}'

三、es报错UNASSIGNED,且集群状态为yellow

1、错误提示:
	"cannot allocate because a previous copy of the primary shard existed but can no longer be found on the nodes"

背景:
	在查看es集群健康状态时,集群的状态为yellow,且出现了不能分配的副本数量
	curl http://ip:9200/_cat/health
	返回的结果中unassigned_shards这一项不为0.

解决方法:
	查看es集群节点数是否正常
		curl http://ip:9200/_cat/nodes?V
	
	检查全部索引的主分片的副本数是不是大于了节点数(即副本数量分配是否合理) #在集群中,要确保主分片的副本数+1要少于或等于集群节点数。如果大于则会导致集群状态不正常。
		curl http://ip:9200/_cat/allocation?v
	
	查看出现unassigned的原因 #这时候就考虑是分片未合理规划的原因
		curl http://ip:9200/_cluster/allocation/explain

	查看索引的分片规划
		curl http://ip:9200/_cat/shards?h=index,shard,prirep,state,unassigned.reason
		unidom_prewarn_data                               1 r STARTED    
		unidom_prewarn_data                               1 r STARTED    
		unidom_prewarn_data                               1 p STARTED    
		unidom_prewarn_data                               1 r UNASSIGNED INDEX_CREATED
		unidom_prewarn_data                               2 r STARTED    
		unidom_prewarn_data                               2 p STARTED    
		unidom_prewarn_data                               2 r STARTED    
		unidom_prewarn_data                               2 r UNASSIGNED INDEX_CREATED
		unidom_prewarn_data                               0 r STARTED    
		unidom_prewarn_data                               0 p STARTED    
		unidom_prewarn_data                               0 r STARTED    
		unidom_prewarn_data                               0 r UNASSIGNED INDEX_CREATED
	分析:
		以上的0,1,2代表节点的编号,很清楚的能看到每个节点,一个p(主分片),3个r(副本分片),然后有一个副本分片不能分配
	备注: 
		1、当副本数大于数据节点数时,那么每个分片只能最多有(节点数量-1)个副本,无法分配的副本数则为主分片数*(副本数-(节点数-1)).假设节点数为3,主分片数为1,副本数为3,那么无法分配的副本数则为:1*(3-(3-1))=1。那么此时只需要重新设置索引副本分片数即可
		2、总shard数是节点的整数倍
		
	重新分配unassigned分片
	curl -XPUT 'http://ip:9200/unidom_suggest_data(有unassigned的分片)/_settings' -H 'Content-Type: application/json'  -d '{ "number_of_replicas": 2(修改分片数)}' #这个数通过上述备注计算即可 上述计算出有一个无法分配,那么在此前分片的基础上再减去那一个分片即可。即为2

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值