企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## 修改集群配置 控制索引生命周期管理检查符合策略标准的索引的频率,默认十分钟 ```json ## kibana的Dev Tools GET _cluster/settings PUT _cluster/settings { "persistent": { "indices.lifecycle.poll_interval": "60s" } } ## curl命令创建 curl -X PUT -H "Content-Type: application/json" 127.0.0.1:9200/_cluster/settings -d '{"persistent":{"indices.lifecycle.poll_interval":"60s"}}' ``` ## 创建生命周期规则 `hot`模式为 `最大主分片30gb` 自动切割分片 `warm` 模式为保留3天,合并字段,不保留副本数,只读分片 `delete`模式保留7天日志 ```json ## kibana的Dev Tools PUT _ilm/policy/messages_policy { "policy": { "phases": { "hot": { "min_age": "0ms", "actions": { "rollover": { "max_primary_shard_size": "30gb" } } }, "warm": { "min_age": "3d", "actions": { "forcemerge": { "max_num_segments": 1 }, "allocate": { "require": { "box_type": "warm" }, "number_of_replicas": 0 }, "readonly": {} } }, "delete": { "min_age": "7d", "actions": { "delete": {} } } } } } GET _ilm/policy/messages_policy DELETE _ilm/policy/messages_policy ## curl命令创建 curl -X PUT -H "Content-Type: application/json" 127.0.0.1:9200/_ilm/policy/messages_policy -d '{"policy":{"phases":{"hot":{"min_age":"0ms","actions":{"rollover":{"max_primary_shard_size":"30gb"}}},"warm":{"min_age":"3d","actions":{"forcemerge":{"max_num_segments":1},"allocate":{"require":{"box_type":"warm"},"number_of_replicas":0},"readonly":{}}},"delete":{"min_age":"7d","actions":{"delete":{}}}}}}' ``` > **注意**:启动elasticsearch配置文件中需要设置 `node.attr.box_type: hot` 或者 `node.attr.box_type: warm`。同一个es实例不能设置多个角色。否则不成功 ## 创建索引模板 关联上面创建生命周期规则 ```json ## kibana的Dev Tools PUT _index_template/messages_index { "index_patterns": ["messages-*"], "template": { "settings": { "number_of_shards": 2, "number_of_replicas": 1, "index.lifecycle.name": "messages_policy", "index.lifecycle.rollover_alias": "messages", "index.routing.allocation.require.box_type": "hot" } } } GET _index_template/messages_index DELETE _index_template/messages_index ## curl命令创建 curl -X PUT -H "Content-Type: application/json" 127.0.0.1:9200/_index_template/messages_index -d '{"index_patterns":["messages-*"],"template":{"settings":{"number_of_shards":2,"number_of_replicas":1,"index.lifecycle.name":"messages_policy","index.lifecycle.rollover_alias":"messages","index.routing.allocation.require.box_type":"hot"}}}' ``` ## 查看节点标签 ```json ## kibana的Dev Tools GET _cat/nodeattrs ## curl命令创建 curl -X GET 127.0.0.1:9200/_cat/nodeattrs ``` ## 创建索引 ```json ## kibana的Dev Tools PUT messages-000001 { "aliases": { "messages": { "is_write_index": true } } } ## curl命令创建 curl -X PUT -H "Content-Type: application/json" 127.0.0.1:9200/messages-000001 -d '{"aliases":{"test":{"is_write_index":true}}}' ``` ## 查看别名 ```json ## kibana的Dev Tools GET _alias/messages ## curl命令创建 curl -X GET 127.0.0.1:9200/_alias/messages ```