使用 SQL Server 复制设置异地冗余

Important

如果你要创建一个 AD FS 场并使用 SQL Server 来存储配置数据,可以使用 SQL Server 2008 或更高版本。

如果要使用 SQL Server 作为 AD FS 配置数据库,则可以使用 SQL Server 复制为 AD FS 场设置异地冗余。 异地冗余在两个地理上相隔很远的站点之间复制数据,以便应用程序可以从一个站点切换到另一个站点。 这样一来,如果一个站点发生故障,仍可以在第二个站点上获取所有配置数据。 有关详细信息,请参阅使用 SQL Server 的联合服务器场中的“SQL Server 异地冗余”部分。

Prerequisites

安装并配置 SQL 服务器场。 有关详细信息,请参阅 https://technet.microsoft.com/evalcenter/hh225126.aspx。 在初始 SQL Server 上,确保 SQL Server 代理服务正在运行并设置为自动启动。

为异地冗余创建第二个(副本)SQL Server

  1. 安装 SQL Server(有关详细信息,请参阅 https://technet.microsoft.com/evalcenter/hh225126.aspx)。 将生成的 CreateDB.sql 和 SetPermissions.sql 脚本文件复制到副本 SQL Server。

  2. 确保 SQL Server 代理服务正在运行并设置为自动启动

  3. Run Export-AdfsDeploymentSQLScript on the primary AD FS node to create CreateDB.sql and SetPermissions.sql files. 例如:PS:\>Export-AdfsDeploymentSQLScript -DestinationFolder . –ServiceAccountName CONTOSO\gmsa1$. 显示如何在主 AD FS 节点上运行 Export-AdfsDeploymentSQLScript 的屏幕截图。

  4. 将脚本复制到辅助服务器。 在 SQL Management Studio 中打开 CreateDB.sql 脚本,然后单击“执行”显示在 SQL Management Studio 中打开 CreateDB.sql 脚本的屏幕截图。

  5. 在 SQL Management Studio 中打开 SetPermissions.sql 脚本,然后单击“执行”显示在 SQL Management Studio 中打开 SetPermissions.sql 脚本的屏幕截图。

Note

还可以从命令行使用以下命令。

c:\>sqlcmd –i CreateDB.sql

c:\>sqlcmd –i SetPermissions.sql

在初始 SQL Server 上创建发布服务器设置

  1. From the SQL Server Management studio, under Replication, right click Local Publications and choose New Publication...Screenshot that shows the New Publication menu option.

  2. On the New Publication Wizard screen click Next.
    Screenshot that shows the New Publication Wizard screen.

  3. On Distributor page, choose local server as distributor and click Next. 显示在何处选择本地服务器作为分发服务器的屏幕截图。

  4. On the Snapshot folder page, enter \\SQL1\repldata in place of default folder. (注意:你可能必须自行创建此共享)。 显示在何处输入默认“快照”文件夹的路径的屏幕截图。

  5. Choose AdfsConfigurationV3 as the publication database and click Next. 显示在何处选择“AdfsConfigurationV3”作为发布数据库的屏幕截图。

  6. On Publication Type, choose Merge publication and click Next. 显示位置的屏幕截图

  7. On Subscriber Types, choose SQL Server 2008 or later and click Next. 显示在何处选择“SQL Server 2008 或更高版本”的屏幕截图。

  8. On the Articles page select Tables node to select all tables, then un-check SyncProperties table (this one should not be replicated)
    Screenshot that shows where to clear the SyncProperties (IdentityServerPolicy) check box.

  9. On the Articles page, select User Defined Functions node to select all User Defined Functions and click Next.. 显示在何处选中“用户定义的函数”复选框的屏幕截图。

  10. On the Article issues page click Next. 显示“文章问题”屏幕的屏幕截图。

  11. 在“筛选表行”页上,单击“下一步”显示“筛选表行”屏幕的屏幕截图。

  12. On the Snapshot Agent page, choose defaults of Immediate and 14 days, click Next. 显示快照代理屏幕的屏幕截图。
    可能需要为 SQL 代理创建域帐户。 使用为域帐户 CONTOSO\sqlagent 配置 SQL 登录名中的步骤为此新 AD 用户创建 SQL 登录名并分配特定的权限。

  13. On the Agent Security page, click Security Settings and enter the username/password of a domain account (not a GMSA) created for the SQL agent and click OK. Click Next. 显示在何处输入域帐户的用户名和密码的屏幕截图。

  14. On the Wizard Actions page, click Next. 显示“向导操作”屏幕的屏幕截图。

  15. 完成向导页上,为您的发布输入一个名称,然后单击完成显示在何处为发布输入名称的屏幕截图。

  16. 创建发布后,应会看到成功状态。 Click Close. 显示发布成功完成的屏幕截图。

  17. 返回 SQL Server Management Studio,右键单击新的发布,然后单击“启动复制监视器”显示“启动复制监视器”菜单选项的屏幕截图。

在副本 SQL Server 上创建订阅设置

确保已按如上所述在初始 SQL Server 上创建发布者设置,然后完成以下过程:

  1. On the replica SQL Server, from SQL Server Management studio, under Replication, right click Local Subscriptions and choose New Subscription.... Screenshot that shows where to select New Subscription.

  2. 在“新建订阅向导”页上,单击“下一步”显示“新建订阅向导”屏幕的屏幕截图。

  3. On the Publication page, select the publisher from the drop-down. Expand AdfsConfigurationV3 and select the name of the publication created above and click Next. 显示在何处展开“AdfsConfigurationV3”并选择创建的发布的名称的屏幕截图。

  4. 合并代理位置页上,选择在其订阅服务器上运行每个代理(拉取订阅)(默认设置),然后单击下一步显示“在订阅服务器上运行每个代理(拉取订阅)”选项的屏幕截图。
    此选项连同下面的“订阅类型”共同决定了冲突解决逻辑。 有关详细信息,请参阅检测并解决合并复制冲突

  5. On the Subscribers page, select AdfsConfigurationV3 as the subscriber database and click Next. 显示“订阅服务器”屏幕的屏幕截图。

  6. 在“合并代理安全性”页上,单击“...”并使用省略号图标框输入为 SQL 代理创建的域帐户(不是 GMSA)的用户名和密码,然后单击“下一步”显示“合并代理安全性”屏幕的屏幕截图。

  7. On Synchronization Schedule, choose Run Continuously and click Next. 显示在何处选择“持续运行”的屏幕截图。

  8. On Initialize Subscriptions, click Next. 显示“初始化订阅”屏幕的屏幕截图。

  9. On Subscription Type, choose Client and click Next.

    Implications of this are documented here and here. 本质上,我们采用简单的“第一个发布者获胜”的冲突解决方式,并且不需要重新发布给其他订阅者。 显示“订阅类型”屏幕的屏幕截图。

  10. On the Wizard Actions page, ensure Create the subscription is checked and click Next. 显示在何处确认是否已选择“创建订阅”选项的屏幕截图。

  11. 在“完成向导”页上,单击“完成”显示“完成向导”屏幕的屏幕截图。

  12. 订阅完成创建过程后,应会看到成功消息。 Click Close. 设置异地冗余

验证初始化和复制过程

  1. On the primary SQL server, right-click the Replication node and click Launch Replication Monitor.

  2. In Replication Monitor, click the publication.

  3. On the All Subscriptions tab, right click and View Details.

    You should be able to see many entries under Actions for the initial replication.

  4. 此外,可以在“SQL Server 代理\作业”节点下查看计划了哪些作业来执行发布/订阅操作。 只会显示本地作业,因此在故障排除时请务必检查发布服务器和订阅服务器。 Right-click a job and select View History to view execution history and results.

为域帐户 CONTOSO\sqlagent 配置 SQL 登录名

  1. Create a new login on the primary and replica SQL Server called CONTOSO\sqlagent (the name of the new domain user created and configured on the Agent Security page in the procedures above.)

  2. In SQL Server, right-click the login you created, and select Properties, then under the User Mapping tab, map this login to AdfsConfiguration and AdfsArtifact databases with public and db_genevaservice roles. 另外,将此登录名映射到分发数据库,并为 distribution 表和 adfsconfiguration 表添加 db_owner 角色。 在主要和副本 SQL Server 上,都可以执行此操作。 有关详细信息,请参阅 复制代理安全模式

  3. 为相应的域帐户授予对配置为分发服务器的共享的读写权限。 确保对共享权限和本地文件权限都设置读写权限。

将 AD FS 节点配置为指向 SQL Server 副本群集

设置异地冗余后,可以通过 AD FS 配置向导 UI 或 Windows PowerShell,使用标准的 AD FS“加入”场功能,将 AD FS 场节点配置为指向副本 SQL Server 场。

如果使用 AD FS 配置向导 UI,请选择“将联合服务器添加到联合服务器场”Do NOT select Create the first federation server in a federation server farm.

If you use Windows PowerShell, run Add-AdfsFarmNode. Do NOT run Install-AdfsFarm.

When prompted, provide the host and instance name of the replica SQL Server, NOT the initial SQL server.