本文介绍如何通过将 NSG 的源配置和安全规则复制到另一个区域,来将 NSG 重定位到新区域。
先决条件
- 请确保 Azure 网络安全组位于目标 Azure 区域中。
- 将新的 NSG 关联到目标区域中的资源。
- 若要导出 NSG 配置并部署模板,以便在另一区域创建 NSG,需要“网络参与者”角色或更高级别的角色。
- 确定源网络布局和当前正在使用的所有资源。 此布局包括但不限于负载均衡器、公共 IP 和虚拟网络。
- 验证 Azure 订阅是否允许在已使用的目标区域中创建 NSG。 请联系支持部门,启用所需配额。
- 确保订阅提供足够的资源,以便为此过程添加 NSG。 请参阅 Azure 订阅和服务限制、配额和约束。
准备
以下步骤说明如何使用资源管理器模板准备网络安全组,以进行配置和安全规则的移动,并使用门户将 NSG 配置和安全规则移到目标区域。
导出和修改模板
若要使用 Azure 门户导出和修改模板,请执行以下操作:
登录到 Azure 门户。
选择“所有资源”,然后选择你的存储帐户。
选择 >“自动化”“导出模板”>。
在“导出模板”边栏选项卡中选择“部署”。
选择“模板”>“编辑参数”,在在线编辑器中打开 parameters.json 文件。
若要编辑 NSG 名称的参数,请更改 parameters 下的 value 属性:
{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", "contentVersion": "1.0.0.0", "parameters": { "networkSecurityGroups_myVM1_nsg_name": { "value": "<target-nsg-name>" } } }
将编辑器中的源 NSG 值更改为目标 NSG 的所选名称。 请务必将名称括在引号中。
在编辑器中选择“保存”。
选择“模板”“编辑模板”,在联机编辑器中打开 template.json 文件。
若要编辑要将 NSG 配置和安全规则移到其中的目标区域,请在在线编辑器中更改 resources 下的 location 属性:
"resources": [ { "type": "Microsoft.Network/networkSecurityGroups", "apiVersion": "2019-06-01", "name": "[parameters('networkSecurityGroups_myVM1_nsg_name')]", "location": "<target-region>", "properties": { "provisioningState": "Succeeded", "resourceGuid": "2c846acf-58c8-416d-be97-ccd00a4ccd78", } } ]
若要获取区域位置代码,请参阅 Azure 位置。 区域的代码是不带空格的区域名称,Central US = centralus。
也可选择更改模板中的其他参数,这些参数是可选的,具体取决于你的要求:
安全规则 - 可以通过编辑的方式设置哪些规则能够部署到目标 NSG 中,只需在 template.json 文件的 securityRules 节中添加或删除规则即可:
"resources": [ { "type": "Microsoft.Network/networkSecurityGroups", "apiVersion": "2019-06-01", "name": "[parameters('networkSecurityGroups_myVM1_nsg_name')]", "location": "<target-region>", "properties": { "provisioningState": "Succeeded", "resourceGuid": "2c846acf-58c8-416d-be97-ccd00a4ccd78", "securityRules": [ { "name": "RDP", "etag": "W/\"c630c458-6b52-4202-8fd7-172b7ab49cf5\"", "properties": { "provisioningState": "Succeeded", "protocol": "TCP", "sourcePortRange": "*", "destinationPortRange": "3389", "sourceAddressPrefix": "*", "destinationAddressPrefix": "*", "access": "Allow", "priority": 300, "direction": "Inbound", "sourcePortRanges": [], "destinationPortRanges": [], "sourceAddressPrefixes": [], "destinationAddressPrefixes": [] } } ] } }
若要完成在目标 NSG 中添加或删除规则的操作,还需编辑 template.json 文件末尾的自定义规则类型,具体格式见下面的示例:
{ "type": "Microsoft.Network/networkSecurityGroups/securityRules", "apiVersion": "2019-06-01", "name": "[concat(parameters('networkSecurityGroups_myVM1_nsg_name'), '/Port_80')]", "dependsOn": [ "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('networkSecurityGroups_myVM1_nsg_name'))]" ], "properties": { "provisioningState": "Succeeded", "protocol": "*", "sourcePortRange": "*", "destinationPortRange": "80", "sourceAddressPrefix": "*", "destinationAddressPrefix": "*", "access": "Allow", "priority": 310, "direction": "Inbound", "sourcePortRanges": [], "destinationPortRanges": [], "sourceAddressPrefixes": [], "destinationAddressPrefixes": [] } }
在在线编辑器中选择“保存”。
重新部署
- 选择“基本信息”“订阅”,以选择要将目标 NSG 部署到的订阅。>
- 选择基本信息中的>“资源组”,以便选择将目标 NSG 部署到的资源组。 可以单击“新建”来为目标 NSG 创建新的资源组。 确保该名称不同于现有 NSG 的源资源组名称。
- 选择“基本信息”“位置”,以确认是否将其设置为要将 NSG 部署到的目标位置。>
- 在“设置”下,确认名称是否与先前在 parameters 编辑器中输入的名称相匹配。
- 选中“条款和条件”下的框。
- 选择“购买”按钮,以部署目标网络安全组。
弃用
若要丢弃目标 NSG,请删除包含目标 NSG 的资源组。 为此,请从门户上的仪表板中选择该资源组,然后选择概述页顶部的“删除”。
清除
若要提交更改并完成 NSG 的移动,请删除源 NSG 或资源组。 为此,请从门户上的仪表板中选择该网络安全组或资源组,然后选择每个页面顶部的“删除”。
后续步骤
在本教程中,我们将 Azure 网络安全组从一个区域移到了另一个区域,并清理了源资源。 若要详细了解如何在区域之间移动资源,以及如何在 Azure 中进行灾难恢复,请参阅: