

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用 Amazon 为 SQL Server Always On FCI 设置多可用区基础架构 FSx
<a name="set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx"></a>

*Manish Garg、T.V.R.L.Phani Kumar Dadi、Nishad Mankar 和 RAJNEESH TYAGI，Amazon Web Services*

## Summary
<a name="set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx-summary"></a>

如果你需要快速迁移大量 Microsoft SQL Server Always On 故障转移群集实例 (FCIs)，这种模式可以帮助你最大限度地缩短配置时间。通过使用自动化和 Amazon FSx for Windows File Server，它可以减少手动工作、人为错误和部署大量集群所需的时间。

这种模式 FCIs 在 Amazon Web Services (AWS) 上的多可用区（多可用区）部署中为 SQL Server 设置基础设施。使用 AWS CloudFormation 模板可以自动配置此基础设施所需的 [AWS](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html) 服务。使用 PowerShell 命令在[亚马逊弹性计算云 (Amazon EC2)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html) 实例上安装 SQL Server 和创建集群节点。

该解决方案使用高度可用的多可用区 A [mazon f FSx or Windows](https://docs.aws.amazon.com/fsx/latest/WindowsGuide/what-is.html) 文件系统作为存储 SQL Server 数据库文件的共享见证。亚马逊 FSx 文件系统和托管 SQL Server 的 EC2 Windows 实例加入了适用于微软 Active Directory 的同一 AWS 目录服务（AWS 托管的微软 AD）域。

## 先决条件和限制
<a name="set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx-prereqs"></a>

**先决条件**
+ 一个有效的 Amazon Web Services account
+ 具有足够权限的 AWS 用户，可以使用 AWS CloudFormation 模板配置资源
+ AWS Directory Service for Microsoft Active Directory
+ AWS Secrets Manager 中用于向键值对中的 AWS Managed Microsoft AD 进行身份验证的凭证：
  + `ADDomainName`: <域名>
  + `ADDomainJoinUserName`: <域用户名>
  + `ADDomainJoinPassword`:<域用户密码>
  + `TargetOU`: <目标 OU 值>
**注意**  
在 AWS Systems Manager Automation 中，您将在 AWS 托管 Microsoft AD 加入活动中使用相同的键名。
+ 用于创建 SQL Server 安装和 Windows 服务或域账户的 SQL Server 媒体文件，这些文件将在集群创建期间使用
+ 虚拟私有云（VPC），具有位于不同可用区的两个公有子网、可用区中的两个私有子网、一个互联网网关、NAT 网关、路由表关联和一个跳转服务器

**产品版本**
+ Windows Server 2012 R2 和 Microsoft SQL Server 2016

## 架构
<a name="set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx-architecture"></a>

**源技术堆栈**
+  FCIs 使用共享云端硬盘的本地 SQL Server

**目标技术堆栈**
+ AWS EC2 实例
+  FSx 适用于 Windows 文件服务器的亚马逊
+ AWS Systems Manager Automation 运行手册
+ 网络配置（VPC、子网、互联网网关、NAT 网关、跳转服务器、安全组）
+ AWS Secrets Manager
+ AWS 托管的 Microsoft AD
+ Amazon EventBridge
+ AWS Identity and Access Management (IAM)

**目标架构**

下图显示了单个 AWS 区域中的一个 AWS 账户，其中一个 VPC 包括两个可用区、两个带有 NAT 网关的公有子网、第一个公有子网中的跳转服务器、两个私有子网（每个子网都有一个用于节点安全组中的 SQL Server 节点的 EC2 实例）以及一个连接到每个 SQL Server 节点的 Amazon FSx 文件系统。还包括 AWS Directory Service EventBridge、亚马逊、AWS Secrets Manager 和 AWS Systems Manager。

![\[包含公有子网和私有子网中的资源且带有节点安全组的多可用区架构。\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/f09c0164-be2d-4665-a574-7ec29fd25082/images/543829a9-e130-4542-9c4e-7518c6cbe967.png)


**自动化和扩展**
+ 您可以使用 AWS Systems Manager 加入 AWS 托管 Microsoft AD 并执行 SQL Server 安装。

## 工具
<a name="set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx-tools"></a>

**AWS 服务**
+ [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html) 可帮助您设置 AWS 资源，快速一致地配置这些资源，并在 AWS 账户和区域的整个生命周期中对其进行管理。
+ [AWS Di](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/what_is.html) rectory Service 提供了多种将微软活动目录 (AD) 与其他 AWS 服务配合使用的方式，例如亚马逊弹性计算云 (亚马逊 EC2)、适用于 SQL Server 的亚马逊关系数据库服务 (Amazon RDS) 和 FSx 适用于 Windows 文件服务器的亚马逊。
+ [亚马逊弹性计算云 (Amazon EC2)](https://docs.aws.amazon.com/ec2/) 在 AWS 云中提供可扩展的计算容量。您可以根据需要启动任意数量的虚拟服务器，并快速纵向扩展或缩减这些服务器。
+ [Amazon EventBridge](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-what-is.html) 是一项无服务器事件总线服务，可帮助您将应用程序与来自各种来源的实时数据连接起来。例如，AWS Lambda 函数、使用 API 目标的 HTTP 调用端点或其他 Amazon Web Services account 中的事件总线。
+ [AWS Identity and Access Management (AWS IAM)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) 通过控制验证和授权使用您 AWS 资源的用户，帮助您安全地管理对您 AWS 资源的访问。
+ [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html) 帮助您将代码中的硬编码凭证（包括密码）替换为对 Secrets Manager 的 API 调用，以便以编程方式检索密钥。
+ [AWS Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/what-is-systems-manager.html) 可帮助您管理在 Amazon Web Services Cloud 中运行的应用程序和基础设施。它简化了应用程序和资源管理，缩短了检测和解决操作问题的时间，并帮助您大规模安全地管理 AWS 资源。

**其他工具**
+ [PowerShell](https://learn.microsoft.com/en-us/powershell/)是一款在 Windows、Linux 和 macOS 上运行的微软自动化和配置管理程序。此模式使用 PowerShell 脚本。

**代码存储库**

此模式的代码可在 GitHub [aws-windows-failover-cluster-automat](https://github.com/aws-samples/aws-windows-failover-cluster-automation) ion存储库中找到。

## 最佳实践
<a name="set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx-best-practices"></a>
+ 用于部署此解决方案的 IAM 角色应遵守最低权限原则。有关更多信息，请参阅 [IAM 文档](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege)。
+ 遵循 A [WS CloudFormation 最佳实践](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/best-practices.html)。

## 操作说明
<a name="set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx-epics"></a>

### 部署基础设施
<a name="deploy-the-infrastructure"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 部署 Systems Manager CloudFormation 堆栈。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx.html) | AWS DevOps， DevOps 工程师 | 
| 部署基础设施堆栈。 | 成功部署 Systems Manager 堆`infra`栈后，创建堆栈，其中包括 EC2 实例节点、安全组、Amazon FSx for Windows 文件服务器文件系统和 IAM 角色。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx.html) | AWS DevOps， DevOps 工程师 | 

### 设置 Windows SQL Server Always On FCI
<a name="set-up-the-windows-sql-server-always-on-fci"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 安装 Windows 工具。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx.html) | AWS DevOps， DevOps 工程师，数据库管理员 | 
| 在 Active Directory 域服务中预存集群计算机的对象。 | 要在 Active Directory 域服务 (AD DS) 中预存集群名称对象 (CNO) 并为集群角色预留虚拟计算机对象 (VCO)，请按照 [Windows Server 文档](https://learn.microsoft.com/en-us/windows-server/failover-clustering/prestage-cluster-adds)中的说明进行操作。 | AWS DevOps、数据库管理员、工程师 DevOps  | 
| 创建 WSFC。 | 要创建 Windows Server Failover Clustering (WSFC) 集群，请执行以下操作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx.html) | AWS DevOps、数据库管理员、工程师 DevOps  | 
| 安装 SQL Server 失效转移群集。 | 设置 WSFC 集群后，在主实例 (节点 1) 上安装 SQL Server 集群。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx.html)<pre>D:\setup.exe /Q  `<br />/ACTION=InstallFailoverCluster `<br />/IACCEPTSQLSERVERLICENSETERMS `<br />/FEATURES="SQL,IS,BC,Conn"  `<br />/INSTALLSHAREDDIR="C:\Program Files\Microsoft SQL Server"  `<br />/INSTALLSHAREDWOWDIR="C:\Program Files (x86)\Microsoft SQL Server"  `<br />/RSINSTALLMODE="FilesOnlyMode"  `<br />/INSTANCEID="MSSQLSERVER" `<br />/INSTANCENAME="MSSQLSERVER"  `<br />/FAILOVERCLUSTERGROUP="SQL Server (MSSQLSERVER)"  `<br />/FAILOVERCLUSTERIPADDRESSES="IPv4;<2nd Sec Private Ip node1>;Cluster Network 1;<subnet mask>"  `<br />/FAILOVERCLUSTERNETWORKNAME="<Fail over cluster Network Name>"  `<br />/INSTANCEDIR="C:\Program Files\Microsoft SQL Server"  `<br />/ENU="True"  `<br />/ERRORREPORTING=0  `<br />/SQMREPORTING=0  `<br />/SAPWD="<Domain User password>" `<br />/SQLCOLLATION="SQL_Latin1_General_CP1_CI_AS"  `<br />/SQLSYSADMINACCOUNTS="<domain\username>" `<br />/SQLSVCACCOUNT="<domain\username>"  /SQLSVCPASSWORD="<Domain User password>" `<br />/AGTSVCACCOUNT="<domain\username>"  /AGTSVCPASSWORD="<Domain User password>" `<br />/ISSVCACCOUNT="<domain\username>" /ISSVCPASSWORD="<Domain User password>"  `<br />/FTSVCACCOUNT="NT Service\MSSQLFDLauncher"  `<br />/INSTALLSQLDATADIR="\\<FSX DNS name>\share\Program Files\Microsoft SQL Server"  `<br />/SQLUSERDBDIR="\\<FSX DNS name>\share\data"  `<br />/SQLUSERDBLOGDIR="\\<FSX DNS name>\share\log" `<br />/SQLTEMPDBDIR="T:\tempdb"  `<br />/SQLTEMPDBLOGDIR="T:\log"  `<br />/SQLBACKUPDIR="\\<FSX DNS name>\share\SQLBackup" `<br />/SkipRules=Cluster_VerifyForErrors `<br />/INDICATEPROGRESS</pre> | AWS DevOps、数据库管理员、工程师 DevOps  | 
| 向集群添加一个辅助节点。 | 要将 SQL Server 添加到辅助节点（节点 2），请运行以下PowerShell 命令。<pre>D:\setup.exe /Q  `<br />/ACTION=AddNode `<br />/IACCEPTSQLSERVERLICENSETERMS `<br />/INSTANCENAME="MSSQLSERVER"  `<br />/FAILOVERCLUSTERGROUP="SQL Server (MSSQLSERVER)" `<br />/FAILOVERCLUSTERIPADDRESSES="IPv4;<2nd Sec Private Ip node2>;Cluster Network 2;<subnet mask>" `<br />/FAILOVERCLUSTERNETWORKNAME="<Fail over cluster Network Name>" `<br />/CONFIRMIPDEPENDENCYCHANGE=1 `<br />/SQLSVCACCOUNT="<domain\username>"  /SQLSVCPASSWORD="<Domain User password>" `<br />/AGTSVCACCOUNT="domain\username>"  /AGTSVCPASSWORD="<Domain User password>" `<br />/FTSVCACCOUNT="NT Service\MSSQLFDLauncher" `<br />/SkipRules=Cluster_VerifyForErrors `<br />/INDICATEPROGRESS</pre> | AWS DevOps、数据库管理员、工程师 DevOps  | 
| 测试 SQL Server FCI。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx.html) | 数据库管理员、工程师 DevOps  | 

### 清理 资源
<a name="clean-up-resources"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 清理资源。 | 要清理资源，请使用 AWS CloudFormation 堆栈删除流程：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx.html)堆栈删除过程完成之后，堆栈将处于 `DELETE_COMPLETE` 状态。默认情况下，处于该`DELETE_COMPLETE`状态的堆栈不会显示在 CloudFormation 控制台中。要显示已删除的堆栈，您必须按照在 [AWS CloudFormation 控制台上查看已删除](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-console-view-deleted-stacks.html)堆栈中所述更改堆栈视图筛选条件。如果删除失败，则堆栈将处于 `DELETE_FAILED` 状态。有关解决方案，请参阅 CloudFormation 文档中的[删除堆栈失败](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/troubleshooting.html#troubleshooting-errors-delete-stack-fails)。 | AWS DevOps、数据库管理员、工程师 DevOps  | 

## 问题排查
<a name="set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx-troubleshooting"></a>


| 问题 | 解决方案 | 
| --- | --- | 
| AWS CloudFormation 模板失败 | 如果 CloudFormation 模板在部署过程中出现故障，请执行以下操作：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx.html) | 
| AWS Managed Microsoft AD | 若要解决加入问题，请执行以下步骤：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx.html) | 

## 相关资源
<a name="set-up-multi-az-infrastructure-for-a-sql-server-always-on-fci-by-using-amazon-fsx-resources"></a>
+ [使用 FSx 适用于 Windows 的亚马逊文件服务器简化微软 SQL Server 高可用性部署](https://aws.amazon.com/blogs/storage/simplify-your-microsoft-sql-server-high-availability-deployments-using-amazon-fsx-for-windows-file-server/)
+ [ FSx 用于搭载微软 SQL Server 的 Windows 文件服务器](https://docs.aws.amazon.com/fsx/latest/WindowsGuide/sql-server.html)