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主代理作業傳播到目標服務器。
sqlserver執行計劃怎么看, 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.
第一個執行SQL十八, 作業計劃運行,并在每個目標服務器中執行。
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。
使用sql查看服務器上的所有數據庫? 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代理,右鍵單擊并選擇“多服務器管理”,然后選擇“ 使它成為主服務器”選項 。
sql執行錯誤。
The wizard to create the master server will be displayed. Press Next.
將顯示創建主服務器的向導。 按下一步。
sqlserver中最重要的管理工具,
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.
下一個窗口是主服務器操作員。 操作員可以使用電子郵件,尋呼機地址或網絡發送地址接收通知。 指定您的首選項地址,然后按下一步。
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.
在“目標服務器”窗口中,我們將選擇所有目標服務器。 在此示例中,我們只有一臺目標服務器,但實際上,我們可能有幾臺。 按添加連接按鈕以添加新的目標服務器。
Connect to the SQL Server that will be used as a Target Server.
連接到將用作目標服務器SQL Server。
If everything is OK, you will receive a success message related to the compatibility between the 2 servers.
如果一切正常,您將收到與兩臺服務器之間的兼容性有關的成功消息。
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.
您可以查看報告,將報告保存在文件中,剪貼板中或通過電子郵件發送報告。 在此示例中,我們將選擇第一個選項。
In this option, the report will show the result of the version compatibility between the master and target servers.
在此選項中,報告將顯示主服務器與目標服務器之間版本兼容性的結果。
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)。 這意味著它是一個主服務器。 右鍵單擊并選擇“ 新作業”選項。
The creation of a job will be similar to local jobs. You just need a name and optionally a description.
職位的創建將類似于本地職位。 您只需要一個名稱和一個描述即可。
Go to the Steps page and click the New button to create a new Job.
轉到“步驟”頁面,然后單擊“新建”按鈕以創建新的作業。
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',不帶格式
走
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.
這是關鍵部分,請轉到“目標”頁面,然后選擇要在其中運行作業的目標多臺服務器。 在此示例中,我們有一臺目標服務器。 選擇多個服務器的目標服務器,然后檢查要在其中運行作業的目標服務器。
If everything is OK, you will receive a Success message that the job was posted remotely for execution.
如果一切正常,您將收到一條成功消息,說明該作業已遠程發布以執行。
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.
將在目標服務器中創建一個新的備份。 如您所見,使用主服務器和目標服務器是一個簡單的過程。
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表示使用證書。
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.
下載指令顯示發送到目標服務器的操作,并指定對象名稱,發布日期和下載日期。
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.
如果需要代理,則需要創建一個證書,然后將其與代理關聯。 確保主服務器和目標服務器中的代理名稱相同。
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代理,右鍵單擊并選擇“多服務器管理”>“缺陷”
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:
一些有用的存儲過程:
Some useful system views:
一些有用的系統視圖:
翻譯自: https://www.sqlshack.com/how-to-execute-jobs-on-multiple-sql-servers/
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态