查看集群状态信息
curl http://10.110.106.173:9200/_cluster/health?pretty
当集群状态为yellow,unassigned_shards的数值几百上千时,此时为了加快索引shards重新分配的速度,可以设置一下参数值,默认为2
curl -XPUT 10.117.106.11:9200/_cluster/settings -d '
{
"transient":{"cluster.routing.allocation.node_concurrent_recoveries": 8}
}'
重建索引,reindex
curl -XPOST 10.110.106.87:9200/_reindex -d '
{
"conflicts": "proceed",
"source": {
"remote": {"host": "http://10.116.106.139:9200"},
"index": "uss_operation_waybill~201806","size":"10000"},
"dest": {
"index": "uss_operation_waybill~201806",
"version_type": "external"}
}'
添加别名
curl -XPOST 'http://localhost:9200/_aliases' -d '
{ "actions": [ {"add": {"index": "test1", "alias": "alias1"}} ] }'
删除别名,可提高查询速度
curl -XPOST http://10.116.106.139:9200/_aliases -d '
{"actions":[
{ "remove":{"index":"uss_operation_waybill~201804","alias":"uss_operation_waybill" }},
{ "remove":{"index":"uss_operation_waybill~201805","alias":"uss_operation_waybill" }},
{ "remove":{"index":"uss_operation_waybill~201806","alias":"uss_operation_waybill" }}
]}'
增加字段
openapi_profile~2020:索引名,openapi_profile:type名,cust_name_text:新增的字段名,type:新增字段的类型
curl -XPUT 'http://10.110.106.208:9200/openapi_profile~2020/_mapping/openapi_profile?pretty' -H 'Content-Type: application/json' -d '
{
"properties": {
"cust_name_text": {
"type": "text",
"analyzer": "ngram_analyzer"
}
}
}'
查看分片重新均衡
curl 192.168.56.10:9200/_cat/shards | fgrep RELO
查看集群磁盘IO情况
iostat -x 2 10
mount 查看磁盘
强制merge,可提高查询速度
curl -XPOST 10.116.106.139:9200/uss_operation_waybill~201904/_forcemerge?max_num_segments=1
/index/_forcemerge?only_expunge_deletes=true
官方说明: The force merge API allows to force merging of one or more indices through an API. The merge relates to the number of segments a Lucene index holds within each shard. The force merge operation allows to reduce the number of segments by merging them.
This call will block until the merge is complete. If the http connection is lost, the request will continue in the background, and any new requests will block until the previous force merge is complete.
注意:在业务使用高峰期间避免执行强制merge,会导致对集群的读写性能下降,且merge的整个过程会比较久。
使用场景:
- segments的数量较多时。一个ES索引由若干个分片组成,一个分片有若干个Lucene分段,较大的Lucene分段可以更有效的存储数据。
- 使用query_by_delete删除数据时,此时数据只是被标记为deleted,并未真正的物理删除,在search的时候依旧会去遍历该部分数据,使用merge为提升查询效率
查询未分配分片,场景:当集群监控度低于100%,
curl 10.110.106.22:9200/_cat/shards?h=index,shard,prirep,state,unassigned.reason| grep UNASSIGN
查看具体未分配分片的原因
cutl -s http://masterip:9200/_cluster/allocation/explain?pretty |less
查看具体节点
curl 10.110.106.22:9200/_nodes/节点名
修改是否重新分配,none为取消重新分配,all为开启重新分配,场景:节点维护时间短
curl -XPUT "http://10.116.106.35:9200/_cluster/settings" -d'
{
"transient" : {
"cluster.routing.allocation.enable" : "none"
}
}'
curl -XPUT "http://10.116.106.35:9200/_cluster/settings" -d'
{
"transient" : {
"cluster.routing.allocation.enable" : "all"
}
}'
设置重平衡
curl -XPUT "http://10.116.106.35:9200/PUT _cluster/settings" -d
{
"transient": {
"cluster.routing.rebalance.enable":"none"
}
}
节点间迁移分片 fromnode tonode
curl -XPOST 10.116.106.147:9200/_cluster/reroute -d '
{"commands":[
{"move":{
"index":"dms_ebil_discount_waybilldto~2018-11",
"shard":1,
"from_node" : "10.116.106.147:9303",
"to_node" : "10.116.106.152:9301"
}}]}'
动态添加慢日志,场景:查询时间超过2s的查询信息会输出在日志上,常用于问题诊断
curl -XPUT 10.116.106.205:9200/waybillinfo_prophet_monitor/_settings -d' {"index.search.slowlog.threshold.query.warn":"2s",
"index.search.slowlog.threshold.fetch.warn":"2s"
}'
#动态 给集群所有索引添加慢日志(ES7.6)
curl -XPUT -u elastic:bdp@elastic -H "Content-Type:application/json" 10.116.107.36:9200/ all/settings -d '{
"index.search.slowlog.threshold.query.warn":"5s",
"index.search.slowlog.threshold.query.info":"2s"
}'
查看节点nodeId
curl 10.116.106.35:9200/_cluster/state/nodes
查看节点状态
curl 10.116.106.35:9200/_nodes/节点名/stats
去除IP节点,场景:主机硬件维护
curl -X PUT "http://10.116.106.35:9200/_cluster/settings" -d '
{"transient":{"cluster.routing.allocation.exclude.ip":"10.116.106.47" }
}'
去除name节点,场景:节点异常
curl -X PUT "http://10.116.106.35:9200/_cluster/settings" -d '
{"transient":{"cluster.routing.allocation.exclude.name":"10.116.106.47:9300" }
}'
设置副本,可提高reindex和写入速度
curl -XPUT 10.116.106.35:9200/mcs_cas_ali_routequery~2019-05-10/_settings -d '
{"index" : { "number_of_replicas" : 0}}'
查看状态内存
curl 10.202.116.33:9200/_cluster/stats
修改副本数
curl -XPUT 10.117.106.9:9200/risp_waybills_v1/_settings -d
'{"index":{"number_of_replicas":0}}'
修改索引刷新间隔时间settings,可提高写入速度
curl -XPUT 10.117.106.9:9200/twitter/_settings -d'
{
"index" : {
"refresh_interval" : "30s"
}
}'
条件删除数据,生产环境删数据、删索引需谨慎,必须邮件跟业务确认,同时知会组内相关同事
curl 100.65.101.21:9200/risp_waybills_v1_3/_delete_by_query -d '{"query":{"match_all":{}}}'
设置更新间隔 不更新为-1
curl -XPUT 10.116.106.188:9200/tradition_*/_settings -d '
{"index" : {"refresh_interval" : "60s"}}'
防止同一个分片(shard)的主副本存在同一个物理机上
cluster.routing.allocation.same_shard.host: true
丢数据的索引重新分配分片
POST /_cluster/reroute -d '
{"commands" : [ {
"allocate_empty_primary" : {
"index" : "awsm_cos_message_to_bdp_es~2019-09",
"shard" : 24,
"node" : "10.216.21.62:9300",
"accept_data_loss":true
}
}
]
}'
添加mapping
curl -XPUT 10.117.106.17:9200/delayed_waybill_for_sme/_mapping/delayed_waybill_for_sme -d '{"properties": {"codMoney": {"type": "float"}}}'
设置索引每个节点只能保留1个分片
curl -XPUT master:9200/索引名称/_settings?pretty -d '
{
"index": {
"routing": {
"allocation": {
"total_shards_per_node": "1"
}
}
}
}'
官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/5.4/allocation-total-shards.html
修改节点最大分片数(ES7.6)
curl -s -XPUT -u elastic:Bdp1@elastic -H "Content-Type:application/json" " http://100.80.72.125:9200/_cluster/settings" -d
'{
"transient": {
"cluster": {
"max_shards_per_node":15000
}
}
}'
取消task任务
POST tasks/node_id:task_id/cancel