介绍 (Introduction)

In earlier chapter, we explained how to run queries in multiple SQL servers using the SQL Central Management Server. In this new chapter, we will show how to propagate a job from a SQL Server Master Agent Job to a target server.

在前面的章节中,我们解释了如何使用SQL Central Management Server在多个SQL服务器中运行查询。 在这一新的章节中,我们将展示如何将作业从SQL Server主代理作业传播到目标服务器。

This feature is called Multiserver Administration. In a multiserver administration, you need a Master Server and one or more target servers. In the master server, you create a copy of the job and then it is copied and executed in the target servers.

此功能称为多服务器管理。 在多服务器管理中,您需要一个主服务器和一个或多个目标服务器。 在主服务器中,创建作业的副本,然后将其复制并在目标服务器中执行。

The jobs are scheduled to run and are executed in each Target Server.

作业计划运行,并在每个目标服务器中执行。

要求 (Requirements)

  • SQL Server Installed (2 SQL Servers or 2 SQL Server Instances). 已安装SQL Server(2个SQL Server或2个SQL Server实例)。
  • 2 SQL Server Agents running. 2个SQL Server代理正在运行。

入门 (Getting started)

  1. Open the regedit, to edit the Windows registry and change the registry \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\<instance_name>\SQL Server Agent\AllowDownloadedJobsToMatchProxyName to 1 in the master and target Servers.

    打开注册表编辑器,以编辑Windows注册表,并将主服务器和目标服务器中的注册表\ HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Microsoft SQL Server \ <instance_name> \ SQL Server Agent \ AllowDownloadedJobsToMatchProxyName更改为1。

    Figure 1. Registry图1.注册表

  2. In the SQL Server Management Studio go to the SQL Server Agent, right click and select the Multi Server Administration and select the Make this a Master option.

    在SQL Server Management Studio中,转到SQL Server代理,右键单击并选择“多服务器管理”,然后选择“ 使它成为主服务器”选项

    Figure 2. The Multi Server option图2.多服务器选项

  3. The wizard to create the master server will be displayed. Press Next.

    将显示创建主服务器的向导。 按下一步。

    Figure 3. The Master Server Wizard图3.主服务器向导

  4. The next window is the Master Server Operator. The operator can receive notification using email, pager address or with a net send address. Specify the address of your preference and press next.

    下一个窗口是主服务器操作员。 操作员可以使用电子邮件,寻呼机地址或网络发送地址接收通知。 指定您的首选项地址,然后按下一步。

    Figure 4. The address of the operator图4.操作员的地址

  5. In the Target Server window, we will select all the target servers. In this example, we only have one target server, but in the real-life, we may have several. Press the Add connection button to add a new target server.

    在“目标服务器”窗口中,我们将选择所有目标服务器。 在此示例中,我们只有一台目标服务器,但实际上,我们可能有几台。 按添加连接按钮以添加新的目标服务器。

    Figure 5. Target Servers图5.目标服务器

  6. Connect to the SQL Server that will be used as a Target Server.

    连接到将用作目标服务器SQL Server。

    Figure 6. Connection information图6.连接信息

  7. If everything is OK, you will receive a success message related to the compatibility between the 2 servers.

    如果一切正常,您将收到与两台服务器之间的兼容性有关的成功消息。

    Figure 7. Server Compatibility Check图7.服务器兼容性检查

  8. You can view the report, save the report in a file, in the clipboard or send the report by email. In this example, we will select the first option.

    您可以查看报告,将报告保存在文件中,剪贴板中或通过电子邮件发送报告。 在此示例中,我们将选择第一个选项。

    Figure 8. Report options图8.报告选项

  9. In this option, the report will show the result of the version compatibility between the master and target servers.

    在此选项中,报告将显示主服务器与目标服务器之间版本兼容性的结果。

    Figure 9. Compatibility Report图9.兼容性报告

  10. Figure 10. Actions to enlist the target server and create the MSX Operator.图10.注册目标服务器并创建MSX Operator的操作。

  11. You will notice that in the Master Server it says (MSX). It means that it is a Master Server. Right-click and select the New Job option.

    您会注意到,在主服务器中显示为(MSX)。 这意味着它是一个主服务器。 右键单击并选择“ 新作业”选项。

    Figure 11. Creating a new job.图11.创建一个新作业。

  12. We will create a backup in the target server. If you have several target servers, the backup will be created in all of them. 我们将在目标服务器中创建一个备份。 如果您有多个目标服务器,则将在所有目标服务器中创建备份。
  13. The creation of a job will be similar to local jobs. You just need a name and optionally a description.

    职位的创建将类似于本地职位。 您只需要一个名称和一个描述即可。

    Figure 12. Creating a backup图12.创建一个备份

  14. Go to the Steps page and click the New button to create a new Job.

    转到“步骤”页面,然后单击“新建”按钮以创建新的作业。

    Figure 13. Creating new steps图13.创建新步骤

  15. Specify the name and the command. In this example, we are backing up a database named db2 in the db2.bak file. You can modify the T-SQL sentences to your own needs:

    指定名称和命令。 在此示例中,我们将在db2.bak文件中备份名为db2的数据库。 您可以根据自己的需要修改T-SQL语句:

    BACKUP DATABASE [db2] TO DISK = N’C:\Backup\db2.bak’ WITH NO FORMAT
    GO

    备份数据库[db2]到磁盘= N'C:\ Backup \ db2.bak',不带格式

    Figure 14. The step to create backups图14.创建备份的步骤

  16. This is the key section, go to the Targets page and select the target multiple servers where you want to run the job. In this example, we have one target server. Select the option target to multiple servers and check the target server(s) where you want to run the job.

    这是关键部分,请转到“目标”页面,然后选择要在其中运行作业的目标多台服务器。 在此示例中,我们有一台目标服务器。 选择多个服务器的目标服务器,然后检查要在其中运行作业的目标服务器。

    Figure 15. Selecting Target servers图15.选择目标服务器

  17. Figure 16. Start Job at Step图16.在步骤开始作业

  18. If everything is OK, you will receive a Success message that the job was posted remotely for execution.

    如果一切正常,您将收到一条成功消息,说明该作业已远程发布以执行。

    Figure 17. Success execution message.图17.成功执行消息。

  19. A new backup will be created in the target server(s). As you can see, working with master and target servers is a straightforward process.

    将在目标服务器中创建一个新的备份。 如您所见,使用主服务器和目标服务器是一个简单的过程。

    Figure 18. The SQL Server backup created.图18.创建SQL Server备份。

一些常见问题 (Some common problems)

A very common problem when you are creating the target server (step 10) is the following message:

创建目标服务器(步骤10)时,一个非常常见的问题是以下消息:

This error is related to the encryption between the master and target server.

此错误与主服务器和目标服务器之间的加密有关。

If you have this error, verify that the registry
\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\<instance_name>\SQL Server Agent\MsxEncryptChannelOptions matches in the master and the target servers. If not, modify the registries. This registry controls the encryption between the master and target server. The value 0 means no encryption. 1 means to encrypt without a certificate and 2 with a certificate.

如果出现此错误,请验证注册表
\ HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Microsoft SQL Server \ <实例名称> \ SQL Server代理\ MsxEncryptChannelOptions在主服务器和目标服务器中匹配。 如果不是,请修改注册表。 该注册表控制主服务器和目标服务器之间的加密。 值0表示不加密。 1表示不使用证书进行加密,2表示使用证书。

一些管理选项 (Some administrative options)

In the master server (MSX), it is posible to administer the Multi server configuration. Right click on the SQL Server Agent and in the Multi Server Administration, select Manage Target Servers.

在主服务器(MSX)中,可以管理多服务器配置。 右键单击SQL Server代理,然后在“多服务器管理”中选择“ 管理目标服务器”。

The target server status tab shows the list of target servers, the local time

目标服务器状态选项卡显示目标服务器列表,本地时间

(the data and time of the target server in the local time) and the last time that the target server polled the master.

(目标服务器在本地时间中的数据和时间)以及目标服务器上次轮询主服务器的时间。

The force poll button forces the poll of the selected target server to the master server. The Force Defection button allows defecting the target server and the post-instruction allows posting the instructions.

强制轮询按钮将选定目标服务器的轮询强制到主服务器。 强制删除按钮可以使目标服务器损坏,而后指令则可以发布指令。

The Download Instruction shows the operations sent to the target servers, specifying the Object Name, Date posted and the Date that it was downloaded.

下载指令显示发送到目标服务器的操作,并指定对象名称,发布日期和下载日期。

需要代理时 (When the proxy is required)

If a proxy is necessary, you will need to create a credential and then associate it with the proxy. Make sure that the proxy name is the same in the Master and Target servers.

如果需要代理,则需要创建一个证书,然后将其与代理关联。 确保主服务器和目标服务器中的代理名称相同。

如何删除目标服务器 (How to remove the target server)

The option to remove the target server from the Multi-Server. You can do that on the target server.

从多服务器中删除目标服务器的选项。 您可以在目标服务器上执行此操作。

Go to the SQL Server Agent, right click and select Multi Server Administration>Defect

转到SQL Server代理,右键单击并选择“多服务器管理”>“缺陷”

结论 (Conclusion)

As you can see, creating a master server and target servers is a straightforward process. Once configured, you can send jobs to multiple servers at the same time.

如您所见,创建主服务器和目标服务器是一个简单的过程。 配置完成后,您可以同时将作业发送到多个服务器。

Some useful stored procedures:

一些有用的存储过程:

  • sp_add_targetservergroup sp_add_targetservergroup
  • sp_delete_targetserver sp_delete_targetserver

Some useful system views:

一些有用的系统视图:

  • dbo.sysdownloadlist dbo.sys下载列表
  • dbo.systargetservers dbo.systargetservers

翻译自: https://www.sqlshack.com/how-to-execute-jobs-on-multiple-sql-servers/

如何在多个SQL Server上执行作业相关推荐

  1. sql server在执行批处理时出现错误。错误消息为: 目录名无效

    今天在客户服务器上的sql server上执行脚本,报错提示"在执行批处理时出现错误.错误消息为:目录名无效",第一反应就是客户是不是在服务器装了360,因为之前有类似问题,360 ...

  2. SQL Server查询执行计划–基础

    为什么查询执行对SQL Server性能很重要? (Why is query execution important for SQL Server performance?) SQL Server性能 ...

  3. aws rds监控慢sql_在AWS RDS SQL Server上使用SSIS包

    aws rds监控慢sql In the first part of the article, Explore SQL Server Integration Services (SSIS) on AW ...

  4. aws rds监控慢sql_在AWS RDS SQL Server上的SSAS中部署表格数据库

    aws rds监控慢sql In this article, we are going to explore Analysis Service for AWS RDS SQL Server in de ...

  5. sql查询初学者指南_面向初学者SQL Server查询执行计划–类型和选项

    sql查询初学者指南 When a DBA is working with the SQL Server, he/she might sometimes say that the execution ...

  6. 如何对SQL Server实例执行性能测试

    介绍 (Introduction) 目标听众 (Intended audience) This document is intended for application developers and ...

  7. aws rds监控慢sql_探索AWS RDS SQL Server上SQL Server集成服务(SSIS)

    aws rds监控慢sql In the previous article, Deploy tabular databases in SSAS on AWS RDS SQL Server, we ex ...

  8. sql查询初学者指南_面向初学者SQL Server查询执行计划–聚集索引运算符

    sql查询初学者指南 We have discussed how to created estimated execution plans and actual execution plans in ...

  9. sql查询初学者指南_面向初学者SQL Server查询执行计划–非聚集索引运算符

    sql查询初学者指南 Now that we understand what Clustered Index Scan and Clustered Index Seek are, how they o ...

最新文章

  1. 直播 | 顾险峰教授讲座:对抗生成网络的几何理论解释
  2. 4种事务特性,5种隔离级别,7种传播行为
  3. jzoj1264,P2866-乱头发节,糟糕的一天Bad Hair Day【单调栈】
  4. 【渝粤教育】国家开放大学2018年春季 0674-22T财务管理 参考试题
  5. 80. 删除排序数组中的重复项 II golang
  6. vue 鼠标点击事件_VBA代码解决方案第115讲:点击鼠标实现精准控制触发事件的VBA代码第二方案...
  7. SVN-关于分支创建合并
  8. 快速简易的分解歌词文件
  9. java ora 01002_遇到了ora-01002,fetch out of sequence
  10. at.allow与at.deny及cron.allow与cron.deny优先级的比较
  11. css之限制文本行数,超出部分显示 “...“
  12. java 排序sort_Java排序方法sort的使用详解(转)
  13. 51单片机数码管表白
  14. 【20保研】中南大学计算机学院2019年全国优秀大学生暑期夏令营通知
  15. win8运行matlab7.0,Win8.1系统中matlab7.0不兼容的解决方法
  16. 数据分析师兴起并繁荣背后的原因
  17. CentOS6 图形界面(gnome)安装
  18. 转行程序员日记--2020-08-12
  19. linux ping库函数,在Linux上用C++实现Ping
  20. 25000 字详解 23 种设计模式(多图 + 代码)

热门文章

  1. python退出函数_【转】python 退出程序的方式
  2. dos怎么退出debug_电脑主板坏了怎么办?浅谈主板常见的故障以及应对办法
  3. node sqlite 插入数据_方便且实用,Python内置的轻量级数据库实操
  4. CentOS常用基础命令大全
  5. hdu 1171 dp(多重背包)
  6. 数据可视化js框架 d3.js入门
  7. kubernetes之四:存储
  8. hexo+github+hexo-theme-matery搭建个人免费博客
  9. LeetCode(905)——按奇偶排序数组(JavaScript)
  10. redis-shake简介