问题描述
- ES集群启动的节点数量为单节点、导致index的settings中设置了replica为1
- 这个replica shard就会成为unassigned shards,因为分片不能分配到已经存在分片副本的同一节点
解决方式
临时解决-索引修改
ES命令修改
# 定位问题
curl -X GET -s {ip}:9200/_cat/shards?h=index,shard,prirep,state,unassigned.reason| grep UNASSIGNED
# 更改副本数量
curl -X PUT http://{ip}:9200/{index}/_settings --header 'Content-Type: application/json' -d '
{
"index": {
"number_of_replicas": 0
}
}'
# 查看集群状态
curl -u elastic:Bocloud@v587 -X GET http://192.168.1.36:9200/_cat/health
1729404314 06:05:14 elasticsearch green 1 1 4 4 0 0 0 0 - 100.0%
详细请参考
http://124.222.123.110:8080/2023051700003.html
Kiban设置索引
前置条件
- 当前环境已经安装对应版本的Kibana服务
- 找到管理-Elasticsearch-索引管理-选择需要修改的索引-点击名称-编辑设置
- 把
"index.number_of_replicas": "1"
改成"index.number_of_replicas": "0"
Kibana查看索引状态
永久解决-索引模板
模板简述
【Elasticsearch7.x】
template大致分成setting和mappings两部分:
索引可使用预定义的模板进行创建,这个模板称作Index templates。模板设置包括settings和mappings,通过模式匹配的方式使得多个索引重用一个模板。
-
settings主要作用于index的一些相关配置信息,如分片数、副本数,tranlog同步条件、refresh等
-
mappings主要是一些说明信息,大致又分为_all、_source、prpperties这三部分:
_all
:主要指的是AllField字段,我们可以将一个或多个都包含进来,在进行检索时无需指定字段的情况下检索多个字段。设置“all" : {“enabled” : true}_source
:主要指的是SourceField字段,Source可以理解为ES除了将数据保存在索引文件中,另外还有一份源数据。_source字段在我们进行检索时相当重要,如果在{“enabled” : false}情况下默认检索只会返回ID, 你需要通过Fields字段去到索引中去取数据,效率不是很高。但是enabled设置为true时,索引会比较大,这时可以通过Compress进行压缩和inclueds、excludes来在字段级别上进行一些限制,自定义哪些字段允许存储。- properties:这是最重要的步骤,主要针对索引结构和字段级别上的一些设置。
-
咱们通常在elasticsearch中 post mapping信息,每重新创建索引便到设置mapping,分片,副本信息。非常繁琐。强烈建议大家通过设置template方式设置索引信息。设置索引名,通过正则匹配的方式匹配到相应的模板。
:::tip PS
直接修改mapping的优先级>索引template。索引匹配了多个template,当属性等配置出现不一致的,以order的最大值为准,order默认值为0
:::
创建索引模板
curl -u elastic:123456 -X PUT http://192.168.1.36:9200/_template/my_systemlogs -H 'Content-Type: application/json' -d '
{
"index_patterns": [
"systemlogs*"
],
"settings": {
"index": {
"number_of_replicas": 0,
"refresh_interval": "30s"
}
},
"mappings": {
"properties": {
"@timestamp": {
"type": "date"
},
"fileDataTimeMillis": {
"type": "date"
},
"ftpServerName": {
"type": "keyword"
}
}
}
}'
查看索引模板
curl -u elastic:123456 -X GET http://192.168.1.36:9200/_template/my_systemlogs?pretty"
模板验证
删除索引
curl -u elastic:123456 -X DELETE "http://localhost:9200/systemlogs-2024.10.20"
重启Filebeat
- 采用进程方式启动的-未使用systemd进行管理
- 重启方式根据自身服务启动方式判断
# 停止服务
ps -ef |grep filebeat| grep -v grep | awk '{print $2}' |xargs kill -9
# 启动服务
su "kibana" -c "nohup /cmp/filebeat/filebeat -e -c /cmp/filebeat/filebeat.yml &"
查看索引状态
curl -u elastic:123456 -X GET http://192.168.1.36:9200/_cat/indices?v
查看集群状态
ES命令查看
curl -u elastic:123456 -X GET http://192.168.1.36:9200/_cat/health?v
curl -u elastic:123456 -X GET http://192.168.1.36:9200/_cat/master?v
curl -u elastic:123456 -X GET http://192.168.1.36:9200/_cat/nodes?v
Kibana查看索引状态
参考地址
http://124.222.123.110:8080/2023051700003.html
https://elasticsearch.cn/article/335
https://blog.youkuaiyun.com/Mrerlou/article/details/120186684