You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Terraform为AWS Aurora集群节点设置不同故障转移优先级

实现Aurora RDS集群节点独立故障转移优先级

可以实现,你可以通过以下两种方式为不同节点设置独立的故障转移优先级:

方式一:用列表变量匹配每个实例的优先级

  1. 修改variables.tf,把单个值的promotion_tier改成列表类型,支持传入多个优先级:
variable "promotion_tiers" {
  description = "每个RDS集群实例的故障转移优先级列表,索引对应实例创建顺序(值范围0-15,数值越低优先级越高)"
  type        = list(number)
  default     = [0, 1, 2, 2, 2] # 示例:主区3个节点设为0、1、2,次区2个节点统一设为2
}
  1. 调整main.tf里的promotion_tier字段,通过count.index调用列表中对应位置的值:
resource "aws_rds_cluster_instance" "default" {
  count                   = local.enabled ? var.cluster_size : 0
  identifier              = "${module.label.id}-${count.index+1}"
  cluster_identifier      = var.cluster_identifier
  engine                  = local.engine
  instance_class          = var.instance_type
  db_subnet_group_name    = local.db_subnet_group_name
  db_parameter_group_name = join("", aws_db_parameter_group.default.*.name)
  publicly_accessible     = var.publicly_accessible
  promotion_tier          = var.promotion_tiers[count.index] # 按实例顺序取对应优先级
  tags                    = module.label.tags
  monitoring_interval     = var.rds_monitoring_interval
  monitoring_role_arn     = var.rds_monitoring_role_arn
}

方式二:按主/次区域拆分实例资源分别配置

如果主区域和次要区域的实例是分开创建的,可以针对不同区域的实例单独设置优先级规则:

主区域3个节点配置

resource "aws_rds_cluster_instance" "primary_nodes" {
  count                   = local.enabled ? 3 : 0
  identifier              = "${module.label.id}-primary-${count.index+1}"
  cluster_identifier      = var.cluster_identifier
  engine                  = local.engine
  instance_class          = var.instance_type
  db_subnet_group_name    = local.primary_db_subnet_group_name
  db_parameter_group_name = join("", aws_db_parameter_group.default.*.name)
  publicly_accessible     = var.publicly_accessible
  promotion_tier          = count.index # 直接用索引设优先级:0(最高)、1、2
  tags                    = merge(module.label.tags, { "Region" = "Primary" })
  monitoring_interval     = var.rds_monitoring_interval
  monitoring_role_arn     = var.rds_monitoring_role_arn
}

次要区域2个节点配置

resource "aws_rds_cluster_instance" "secondary_nodes" {
  count                   = local.enabled ? 2 : 0
  identifier              = "${module.label.id}-secondary-${count.index+1}"
  cluster_identifier      = var.cluster_identifier
  engine                  = local.engine
  instance_class          = var.instance_type
  db_subnet_group_name    = local.secondary_db_subnet_group_name
  db_parameter_group_name = join("", aws_db_parameter_group.default.*.name)
  publicly_accessible     = var.publicly_accessible
  promotion_tier          = 2 # 次区节点统一设为较低优先级
  tags                    = merge(module.label.tags, { "Region" = "Secondary" })
  monitoring_interval     = var.rds_monitoring_interval
  monitoring_role_arn     = var.rds_monitoring_role_arn
}

注意事项

  • promotion_tier取值范围是0-15,数值越小故障转移优先级越高,0为最高优先级
  • 使用列表变量时,要保证列表长度和cluster_size一致,避免索引越界报错
  • 全局Aurora集群中,次要区域实例默认无法自动提升为主节点,所以次区节点优先级通常设为较高数值

内容的提问来源于stack exchange,提问作者sqllearner

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 05:22:42