报错详情
es的9200端口无法访问,查看es pod日志报错信息如下:
"message": "Authentication of [elastic] was terminated by realm [reserved] - failed to authenticate user [elastic]"
解决
查看日志有一行输出:"stacktrace": ["org.elasticsearch.action.UnavailableShardsException: at least one primary shard for the index [.security-7] is unavailable",
证明是es的.security-7
索引损坏。这个索引包括了用户登录的一些信息。
es版本是7.17.3,启用了xpack,用了keystore,所以不能直接重置密码。
创建新用户,授予管理员权限,再用这个用户删掉.security-7
索引,再重启es。
elasticsearch-users useradd restore_user -p xxxxx -r superuser
curl -X DELETE "127.0.0.1:9200/.security-*" -u restore_user
删除索引后,重启es,可以正常访问。但是接入kibana时,报错再次出现。
再次进入容器创建restore_user用户,查看.security-7
索引异常原因。
报错中显示了.security-7
索引有默认的tier:data_content
,es集群中没有这个角色,所以无法分配。
解决方法
新增data_content
角色节点。或者手动指定.security-7
索引为data_hot
或者data_warm
角色。
这里采用了第二种方法:
curl 127.0.0.1:9200/.security-7/_settings -X PUT -u restore_user -H 'Content-Type: application/json' -d '{"index.routing.allocation.include._tier_preference": "data_hot"}'
集群恢复正常。