本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
SQL Server 設定
在 SQL Server 環境中執行這些步驟,以啟用 AWS 轉換現代化。
資料庫設定和組態
步驟 1:建立具有必要許可的資料庫使用者
建立具有必要許可的 AWS Transform 專用資料庫使用者。如果您已經有 DMS 結構描述轉換使用者,則可以重複使用它。
連線至 SQL Server 執行個體並執行下列命令:
-- Create the login in master database USE master; CREATE LOGIN [atx_user] WITH PASSWORD = 'YourStrongPassword123!'; -- Switch to your application database USE [YourDatabaseName]; CREATE USER [atx_user] FOR LOGIN [atx_user]; -- Grant required permissions GRANT VIEW DEFINITION TO [atx_user]; GRANT VIEW DATABASE STATE TO [atx_user]; ALTER ROLE [db_datareader] ADD MEMBER [atx_user]; -- Grant master database permissions USE master; GRANT VIEW SERVER STATE TO [atx_user]; GRANT VIEW ANY DEFINITION TO [atx_user];
注意
針對您要現代化的每個資料庫,重複資料庫特定的命令 (USE、CREATE USER、GRANT)。
db_datareader 角色僅適用於資料遷移,而不只是結構描述轉換。
db_datareader 角色會授予資料庫中所有資料表的讀取存取權
只有在執行資料遷移時,才需要此角色。
僅針對結構描述轉換 (沒有資料遷移),不需要 db_datareader 角色
其他許可 (VIEW DEFINITION、VIEW DATABASE STATE 等) 足以轉換結構描述
步驟 2:在 AWS Secrets Manager 中存放登入資料
將您的資料庫登入資料安全地存放在 AWS Secrets Manager 中。如果您已為 DMS 建立秘密,請略過此步驟。
在主控台中導覽至 AWS Secrets Manager
選擇儲存新的秘密
設定秘密:
秘密類型:其他資料庫的登入資料
資料庫:Microsoft SQL Server
使用者名稱:atx_user (或您選擇的使用者名稱)
密碼:您建立的密碼
伺服器名稱:您的 SQL Server 端點
資料庫名稱:您的資料庫名稱
連接埠:1433 (或您的自訂連接埠)
選擇下一步
輸入秘密名稱:atx-db-modernization-sqlserver
新增必要的標籤 (這些標籤為必要標籤):
金鑰:專案、值:atx-db-modernization
金鑰:擁有者、值:資料庫連接器
從剩餘的畫面選擇下一步
選擇存放區
請注意要用於下一個步驟的秘密 ARN
重要
資料庫密碼只能使用可列印的 ASCII 字元,不包括 '/'、'@'、'"' 和空格。排程刪除的秘密可能會導致轉換失敗。
步驟 3:建立必要的 DMS 角色
AWS 轉換需要 DMS 操作的特定 IAM 角色。使用以下 CloudFormation 範本部署這些角色。
注意
如果 AWS 您的帳戶已有現有的 DMS 相關角色,請修改此範本以重複使用這些資源,而不是建立重複項目。
使用下列內容建立名為 dms-roles.yaml 的檔案:
AWSTemplateFormatVersion: '2010-09-09' Description: 'DMS Service Roles for AWS Transform SQL Server Modernization' Resources: DMSCloudWatchLogsRole: Type: AWS::IAM::Role Properties: RoleName: dms-cloudwatch-logs-role AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Principal: Service: - dms.amazonaws.com - schema-conversion.dms.amazonaws.com Action: sts:AssumeRole ManagedPolicyArns: - arn:aws:iam::aws:policy/service-role/AmazonDMSCloudWatchLogsRole DMSS3AccessRole: Type: AWS::IAM::Role Properties: RoleName: dms-s3-access-role AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Principal: Service: - dms.amazonaws.com - schema-conversion.dms.amazonaws.com Action: sts:AssumeRole Policies: - PolicyName: S3TaggedAccess PolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Action: - s3:GetBucketLocation - s3:GetBucketVersioning - s3:PutObject - s3:PutBucketVersioning - s3:GetObject - s3:GetObjectVersion - s3:ListBucket - s3:DeleteObject Resource: arn:aws:s3:::atx-db-modernization-* Condition: StringEquals: aws:ResourceAccount: !Ref AWS::AccountId DMSSecretsManagerRole: Type: AWS::IAM::Role Properties: RoleName: dms-secrets-manager-role AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Principal: Service: - dms.amazonaws.com - schema-conversion.dms.amazonaws.com Action: sts:AssumeRole Policies: - PolicyName: SecretsManagerTaggedAccess PolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Action: - secretsmanager:GetSecretValue - secretsmanager:DescribeSecret Resource: '*' Condition: StringEquals: secretsmanager:ResourceTag/Project: atx-db-modernization secretsmanager:ResourceTag/Owner: database-connector DMSVPCRole: Type: AWS::IAM::Role Properties: RoleName: dms-vpc-role AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Principal: Service: - dms.amazonaws.com - schema-conversion.dms.amazonaws.com Action: sts:AssumeRole ManagedPolicyArns: - arn:aws:iam::aws:policy/service-role/AmazonDMSVPCManagementRole DMSServerlessRole: Type: AWS::IAM::ServiceLinkedRole Properties: AWSServiceName: dms.amazonaws.com Description: 'Service Linked Role for AWS DMS Serverless' Outputs: DMSCloudWatchLogsRoleArn: Description: ARN of the DMS CloudWatch Logs Role Value: !GetAtt DMSCloudWatchLogsRole.Arn DMSS3AccessRoleArn: Description: ARN of the DMS S3 Access Role Value: !GetAtt DMSS3AccessRole.Arn DMSSecretsManagerRoleArn: Description: ARN of the DMS Secrets Manager Role Value: !GetAtt DMSSecretsManagerRole.Arn DMSVPCRoleArn: Description: ARN of the DMS VPC Role Value: !GetAtt DMSVPCRole.Arn Export: Name: !Sub ${AWS::StackName}-VPCRole DMSServerlessRoleArn: Description: ARN of the DMS Serverless Role Value: !Sub 'arn:aws:iam::${AWS::AccountId}:role/aws-service-role/dms.amazonaws.com/AWSServiceRoleForDMSServerless' Export: Name: !Sub ${AWS::StackName}-ServerlessRole
使用 CLI 部署 CloudFormation AWS 堆疊:
aws cloudformation create-stack \ --stack-name dms-roles \ --template-body file://dms-roles.yaml \ --capabilities CAPABILITY_NAMED_IAM \ --region us-east-1
或使用 AWS 主控台部署:
在 AWS 主控台中導覽至 CloudFormation
選擇建立堆疊
選取上傳範本檔案
上傳 dms-roles.yaml 檔案
輸入堆疊名稱:dms-roles
確認 IAM 功能
選擇建立堆疊
步驟 4:設定網路安全
確保 AWS Transform、SQL Server 資料庫和其他 AWS 服務之間的網路連線正常。
安全群組組態 (建議的方法)
建議方法:使用安全群組型存取控制,而非 IP 型規則。這可提供更好的安全性、更輕鬆的管理,並與 AWS Transform 的架構無縫搭配運作。
為什麼要使用安全群組型存取控制?
DMS 結構描述轉換會在 VPC 中建立彈性網路界面 (ENIs)
您的資料庫不需要公開存取
AWS 轉換不會公開私有 IP 地址,使得 IP 型規則複雜
安全群組參考會在資源擴展時提供動態的自動更新
設定 SQL Server 安全群組
在 AWS 轉換中設定 DMS 結構描述轉換執行個體描述檔時,您可以指定 DMS SC 執行個體的安全群組。您的資料庫安全群組應允許來自此 DMS SC 安全群組的傳入流量。
Step-by-step組態:
識別 DMS 結構描述轉換安全群組:
這是在 AWS Transform 中建立執行個體描述檔時所指定
請注意安全群組 ID (例如 sg-0123456789abcdef0)
更新您的 SQL Server 安全群組傳入規則:
類型:自訂 TCP
連接埠:1433 (或您的自訂 SQL Server 連接埠)
來源:DMS 結構描述轉換安全群組 ID
描述:「允許 DMS 結構描述轉換存取」
對於 Aurora PostgreSQL 目標 (建立後):
類型:PostgreSQL
連接埠:5432 (或您的自訂 PostgreSQL 連接埠)
來源:DMS 結構描述轉換安全群組 ID
描述:「允許 DMS 結構描述轉換存取」
重要
對於最低權限安全模型很重要:如果您的組織使用預設封鎖所有流量的「最低權限」安全模型,您必須明確允許從 DMS 結構描述轉換安全群組到資料庫連接埠的傳入流量。請勿將連接埠 1433 開啟至所有來源或 IP 範圍。
必要的 AWS 服務連線
確保您的 VPC 可以與下列人員通訊:
AWS 轉換服務端點
AWS DMS 端點
Aurora PostgreSQL 端點
用於成品儲存的 S3 端點
AWS Secrets Manager 端點
AWS CodeConnections 端點
VPC 端點:針對私有網路,設定所需 AWS 服務的 VPC 端點,以避免網際網路閘道相依性。
外部託管資料庫的需求
如果您的 SQL Server 資料庫託管在 外部 AWS,請確保符合下列先決條件,然後在開始現代化之前完成設定步驟。
先決條件
-
具有 VPC AWS 的帳戶
-
VPC 與外部資料庫之間的網路連線。如需設定網路連線的詳細資訊,請參閱 AWS DMS 《 使用者指南》中的設定網路連線。
設定步驟
-
在 AWS Secrets Manager 中使用外部資料庫的連線詳細資訊建立秘密。如需詳細資訊,請參閱步驟 2:在 AWS Secrets Manager 中存放登入資料。
-
出現提示時,請提供 VPC ID 和安全群組 ID 以連線至外部資料庫。 AWS Transform 會提示您輸入此資訊,因為無法在 AWS 帳戶中解析秘密中的資料庫主機名稱。