配置管理方案设计
- 索引级配置:
- 使用
index.blocks.read_only_allow_delete
属性:对于写入需求较低,读取需求高的索引,可以在业务低谷期,例如凌晨时段,将其设置为只读,使用PUT /{index}/_settings
API 进行设置,如:
{
"settings": {
"index.blocks.read_only_allow_delete": true
}
}
- 调整
index.refresh_interval
:对于写入频繁但对实时性要求不高的索引,可以适当增大index.refresh_interval
值,以减少段合并压力,提高写入性能。例如,将其从默认的1秒调整为5分钟:
{
"settings": {
"index.refresh_interval": "5m"
}
}
- 配置
index.number_of_replicas
:根据读负载情况,对于读需求高的索引,增加副本数。例如,从默认的1个副本增加到3个副本:
{
"settings": {
"index.number_of_replicas": 3
}
}
- 节点级配置:
- 使用
node.attr
属性:通过elasticsearch.yml
文件给不同节点设置属性,如node.attr.storage_type: high_speed
用于标识具有高速存储的节点。然后在索引创建或设置时,使用index.routing.allocation.include.{attr_name}
来指定索引应分配到哪些节点上。例如,对于写入性能要求高的索引,分配到具有高速存储的节点:
{
"settings": {
"index.routing.allocation.include.storage_type": "high_speed"
}
}
- 集群级配置:
- 使用
cluster.routing.allocation.cluster_concurrent_rebalance
:调整集群重新平衡时允许并发移动的分片数量,防止集群在调整时性能过度下降。例如,将其设置为5:
{
"persistent": {
"cluster.routing.allocation.cluster_concurrent_rebalance": 5
}
}
cluster.routing.allocation.node_concurrent_recoveries
:设置每个节点上允许并发恢复的分片数量,同样为了控制集群在节点故障恢复等操作时的性能影响,例如设置为3:
{
"persistent": {
"cluster.routing.allocation.node_concurrent_recoveries": 3
}
}
应对集群节点故障时配置的自动调整
- 自动分片重新分配:Elasticsearch 内置的自动分片分配机制会在节点故障时,自动将故障节点上的分片重新分配到其他健康节点上。通过合理配置上述集群级参数(如
cluster.routing.allocation.cluster_concurrent_rebalance
和cluster.routing.allocation.node_concurrent_recoveries
),可以控制重新分配过程对集群性能的影响。
- 动态调整副本数:可以通过监控工具(如Elasticsearch监控API或第三方监控工具)实时监测集群状态。当节点故障导致某些索引的副本数低于预期的高可用性水平时,使用API动态增加副本数。例如:
PUT /{index}/_settings
{
"settings": {
"index.number_of_replicas": {new_replica_count}
}
}
- 重新分配索引到合适节点:在节点故障后,根据剩余节点的属性和负载情况,重新评估索引的分配。可以利用
index.routing.allocation.include
和exclude
等属性,结合node.attr
设置,通过API重新配置索引的分配规则,将索引移动到更合适的节点,以优化读写性能。例如:
PUT /{index}/_settings
{
"settings": {
"index.routing.allocation.include.storage_type": "high_speed"
}
}