azure - 一个 Azure 资源组只能使用一台 SFTP 服务器吗?

标签 azure sftp azure-resource-manager

是否只能使用 Azure 中的一个资源组创建一个按需 SFPT 服务器?

这是有关 Azure 上的 SFPT 的链接。 https://learn.microsoft.com/en-us/samples/azure-samples/sftp-creation-template/sftp-on-azure/

我尝试在同一资源组中创建第二个 SFPT,但之前的 SFPT 被新的替换

我尝试谷歌搜索这个问题,但找不到答案,所以我在这里发布这个问题。

最佳答案

是的,我们可以将多个 SFTP 服务器部署到我们的 Azure 资源组。

但是您使用的模板已经声明了默认变量,我们需要声明如下模板所示的参数,这样您就可以使用同一模板多次。

模板:-

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.4.63.48766",
      "templateHash": "17013458610905703770"
    }
  },
  "parameters": {
    "storageAccountType": {
      "type": "string",
      "defaultValue": "Standard_LRS",
      "metadata": {
        "description": "Storage account type"
      },
      "allowedValues": [
        "Standard_LRS",
        "Standard_ZRS",
        "Standard_GRS"
      ]
    },
    "storageAccountPrefix": {
      "type": "string",
      "defaultValue": "sftpstg",
      "metadata": {
        "description": "Prefix for new storage account"
      }
    },
    "fileShareName": {
      "type": "string",
      "defaultValue": "sftpfileshare",
      "metadata": {
        "description": "Name of file share to be created"
      }
    },
    "sftpUser": {
      "type": "string",
      "defaultValue": "sftp",
      "metadata": {
        "description": "Username to use for SFTP access"
      }
    },
    "sftpPassword": {
      "type": "securestring",
      "metadata": {
        "description": "Password to use for SFTP access"
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Primary location for resources"
      }
    },
    "containerGroupDNSLabel": {
      "type": "string",
      "defaultValue": "[uniqueString(resourceGroup().id, deployment().name)]",
      "metadata": {
        "description": "DNS label for container group"
      }
    },
     "sftpContainerGroupName": {
      "type": "string",
      "metadata": {
     "description": "cngroup for container group"
      }
    },
    "sftpContainerName": {
      "type": "string",
      "metadata": {
     "description": "container name"
      }
    }
 },
  "functions": [],
  "variables": {
    "sftpContainerImage": "atmoz/sftp:debian",
    "sftpEnvVariable": "[format('{0}:{1}:1001', parameters('sftpUser'), parameters('sftpPassword'))]",
    "storageAccountName": "[take(toLower(format('{0}{1}', parameters('storageAccountPrefix'), uniqueString(resourceGroup().id))), 24)]"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2019-06-01",
      "name": "[variables('storageAccountName')]",
      "location": "[parameters('location')]",
      "kind": "StorageV2",
      "sku": {
        "name": "[parameters('storageAccountType')]"
      }
    },
    {
      "type": "Microsoft.Storage/storageAccounts/fileServices/shares",
      "apiVersion": "2019-06-01",
      "name": "[toLower(format('{0}/default/{1}', variables('storageAccountName'), parameters('fileShareName')))]",
      "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
      ]
    },
    {
      "type": "Microsoft.ContainerInstance/containerGroups",
      "apiVersion": "2019-12-01",
      "name": "[parameters('sftpContainerGroupName')]",
      "location": "[parameters('location')]",
      "properties": {
        "containers": [
          {
            "name": "[parameters('sftpContainerName')]",
            "properties": {
              "image": "[variables('sftpContainerImage')]",
              "environmentVariables": [
                {
                  "name": "SFTP_USERS",
                  "secureValue": "[variables('sftpEnvVariable')]"
                }
              ],
              "resources": {
                "requests": {
                  "cpu": 1,
                  "memoryInGB": 1
                }
              },
              "ports": [
                {
                  "port": 22,
                  "protocol": "TCP"
                }
              ],
              "volumeMounts": [
                {
                  "mountPath": "[format('/home/{0}/upload', parameters('sftpUser'))]",
                  "name": "sftpvolume",
                  "readOnly": false
                }
              ]
            }
          }
        ],
        "osType": "Linux",
        "ipAddress": {
          "type": "Public",
          "ports": [
            {
              "port": 22,
              "protocol": "TCP"
            }
          ],
          "dnsNameLabel": "[parameters('containerGroupDNSLabel')]"
        },
        "restartPolicy": "OnFailure",
        "volumes": [
          {
            "name": "sftpvolume",
            "azureFile": {
              "readOnly": false,
              "shareName": "[parameters('fileShareName')]",
              "storageAccountName": "[variables('storageAccountName')]",
              "storageAccountKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2019-06-01').keys[0].value]"
            }
          }
        ]
      },
      "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
      ]
    }
  ],
  "outputs": {
    "containerDNSLabel": {
      "type": "string",
      "value": "[format('{0}.{1}.azurecontainer.io', reference(resourceId('Microsoft.ContainerInstance/containerGroups', parameters('sftpContainerGroupName'))).ipAddress.dnsNameLabel, reference(resourceId('Microsoft.ContainerInstance/containerGroups', parameters('sftpContainerGroupName')), '2019-12-01', 'full').location)]"
    }
  }
}

部署详细信息:- enter image description here

enter image description here

enter image description here

关于azure - 一个 Azure 资源组只能使用一台 SFTP 服务器吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71133733/

相关文章:

python - paramiko:打开和返回 sftp 连接的方法

azure - 我可以在 Azure 模板规范的 uiFormDefinition 中使用引用函数和 UI 控件(例如 'Microsoft.Solutions.ArmApiControl')吗?

azure - Xamarin.Android 无法在 Android 10 Q 中从 Azure 数据库中提取表

Azure DevOps 构建管道 - 失败的构建仍会部署到 Azure

sftp - 是什么原因导致SFTP中出现错误“无法规范化:没有这样的文件或目录”?

powershell - 使用 AzureRM powershell 创建和发布 Azure 经典云服务项目

Azure API 调用未记录

azure - 枚举 Azure 中云服务的所有实例

Azure 应用程序见解和 NLog

java - Java中将文件从一台FTP服务器复制到另一台FTP服务器