如何使用 cloudformation 模板创建 Amazon RDS aurora Master 和只读副本集群
Posted
技术标签:
【中文标题】如何使用 cloudformation 模板创建 Amazon RDS aurora Master 和只读副本集群【英文标题】:How to create Amazon RDS aurora Master and read replica cluster using cloudformation template 【发布时间】:2017-01-15 23:03:20 【问题描述】:使用 cloudformation 模板创建 Amazon RDS Master 和只读副本集群。
【问题讨论】:
【参考方案1】:我们可以使用以下 cloudformation 模板创建 Amazon Aurora RDS。只是我们需要在创建堆栈时传递我们的参数。
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Aurora Db Stack",
"Parameters":
"EnvironmentName":
"Description": "The string that will be prefixed to each instance name",
"Type": "String",
"MinLength": "3",
"MaxLength": "6",
"AllowedPattern": "[a-z0-9]*",
"ConstraintDescription": "Environment names must be 3-6 characters and contain only a-z and 0-9."
,
"DbUsername":
"Description": "App Db Username",
"Type": "String",
"MinLength": "5",
"MaxLength": "15",
"AllowedPattern": "[a-zA-Z][a-zA-Z0-9]*",
"ConstraintDescription": "must begin with a letter and contain only alphanumeric characters."
,
"DbPassword":
"Description": "App Db Password",
"NoEcho": "true",
"Type": "String",
"MinLength": "15",
"MaxLength": "41",
"AllowedPattern": "[a-zA-Z0-9]*",
"ConstraintDescription": "App Db Password must be 15-41 characters and contain only alpha numeric characters."
,
"DbType":
"Description": "App Db server RDS instance type",
"Type": "String",
"Default": "db.r3.large",
"AllowedValues": [
"db.r3.large",
"db.r3.xlarge",
"db.r3.2xlarge",
"db.r3.4xlarge",
"db.r3.8xlarge"
],
"ConstraintDescription": "must be a valid RDS instance type."
,
"DBIdentifierNameMaster":
"Description": "The string that will be prefixed to each instance name",
"Type": "String",
"MinLength": "3",
"MaxLength": "10",
"AllowedPattern": "[a-z0-9]*",
"ConstraintDescription": "Identifier names must be 3-6 characters and contain only a-z and 0-9."
,
"DBIdentifierNameReplica":
"Description": "The string that will be prefixed to each instance name",
"Type": "String",
"MinLength": "3",
"MaxLength": "10",
"AllowedPattern": "[a-z0-9]*",
"ConstraintDescription": "Identifier names must be 3-10 characters and contain only a-z and 0-9."
,
"Subnets":
"Type": "CommaDelimitedList",
"Default": "subnet-8ec5b8e6,subnet-1edcc277",
"Description": "The list of SubnetIds where the stack will be launched"
,
"DBSecurityGroupName":
"Type": "String",
"Description": "Security Group id"
,
"Resources":
"DBSubnetGroup":
"Type": "AWS::RDS::DBSubnetGroup",
"Properties":
"DBSubnetGroupDescription": "Dev DB subent groups",
"SubnetIds":
"Ref": "Subnets"
,
"Tags": [
"Key": "Name",
"Value":
"Fn::Join": [
"",
[
"PROJECT_NAME-",
"Ref": "EnvironmentName"
,
"-db"
]
]
]
,
"DBCluster":
"Type": "AWS::RDS::DBCluster",
"Properties":
"Engine": "aurora",
"MasterUsername":
"Ref": "DbUsername"
,
"MasterUserPassword":
"Ref": "DbPassword"
,
"DBSubnetGroupName":
"Ref": "DBSubnetGroup"
,
"VpcSecurityGroupIds": [
"Ref": "DBSecurityGroupName"
]
,
"RDSinstance":
"Type": "AWS::RDS::DBInstance",
"Properties":
"DBClusterIdentifier":
"Ref": "DBCluster"
,
"DBInstanceIdentifier":
"Ref": "DBIdentifierNameMaster"
,
"DBInstanceClass":
"Ref": "DbType"
,
"Engine": "aurora",
"DBParameterGroupName":
"Ref": "DbParameterGroup"
,
"DBSubnetGroupName":
"Ref": "DBSubnetGroup"
,
"PubliclyAccessible": "true",
"Tags": [
"Key": "Name",
"Value":
"Fn::Join": [
"",
[
"Master Database-",
"Ref": "EnvironmentName"
,
"-app-db"
]
]
]
,
"RDSinstance2":
"Type": "AWS::RDS::DBInstance",
"Properties":
"DBClusterIdentifier":
"Ref": "DBCluster"
,
"DBInstanceIdentifier":
"Ref": "DBIdentifierNameReplica"
,
"DBInstanceClass":
"Ref": "DbType"
,
"Engine": "aurora",
"DBParameterGroupName":
"Ref": "DbParameterGroup"
,
"DBSubnetGroupName":
"Ref": "DBSubnetGroup"
,
"PubliclyAccessible": "true",
"Tags": [
"Key": "Name",
"Value":
"Fn::Join": [
"",
[
"Read Replica Database-",
"Ref": "EnvironmentName"
,
"-app-db"
]
]
]
,
"DbParameterGroup":
"Type": "AWS::RDS::DBParameterGroup",
"Properties":
"Description": "AppDbParameters",
"Family": "aurora5.6",
"Parameters":
"log_bin_trust_function_creators": "on",
"explicit_defaults_for_timestamp": "0"
【讨论】:
它怎么知道哪个是master?你先定义的那个是主人吗? 您可以指定要命名为主或从的标识符,但在创建集群后,如果有任何故障转移,则读取副本或读取状态将改变,反之亦然。它不会将您的标识符名称用于故障转移。以上是关于如何使用 cloudformation 模板创建 Amazon RDS aurora Master 和只读副本集群的主要内容,如果未能解决你的问题,请参考以下文章
如何修复与 AWS::CloudFormation::Init 一起创建 EC2 的 cloudformation 模板
如何使用 cloudformation 模板创建 Amazon RDS aurora Master 和只读副本集群
如何使用 AWS Cloudformer 为现有 API Gateway 创建云形成模板?
如何使用cloudformation模板将两个EC2实例(安装AMI创建的Elasticsearch)作为多节点?