Visual Studio 2015(JSON)からAzure上にCentOSをデプロイしてみたよ。

◆ Live配信スケジュール ◆
サイオステクノロジーでは、Microsoft MVPの武井による「わかりみの深いシリーズ」など、定期的なLive配信を行っています。
⇒ 詳細スケジュールはこちらから
⇒ 見逃してしまった方はYoutubeチャンネルをご覧ください
【5/21開催】Azure OpenAI ServiceによるRAG実装ガイドを公開しました
生成AIを活用したユースケースで最も一番熱いと言われているRAGの実装ガイドを公開しました。そのガイドの紹介をおこなうイベントです!!
https://tech-lab.connpass.com/event/315703/

Visual Studio 2015(以下Visual Studio)からAzure上にCentOSをデプロイします。

はじめに

Visual Studio でAzure リソースマネージャーのテンプレートを作成/デプロイし、Azure上にCentOSを構築、SSHでログインできるまでを試してみました。

Visual Stadioでプロジェクトを作成する。

  1. Visual Stadioを起動します。
  2. Visual Stadioでプロジェクトを作成します。テンプレートは、「Cloud」-「Azureリソースグループ」を選択します。%e3%82%ad%e3%83%a3%e3%83%97%e3%83%81%e3%83%a33
  3. テンプレートは、「Linux Virtual Machine Scale Set」を選択します。

%e3%82%ad%e3%83%a3%e3%83%97%e3%83%81%e3%83%a32

 

Azure リソースマネージャーのテンプレートを作成する。

    1. 「LinuxVirtualMachineScaleSet.json」に記載されている内容を削除し、以下の通り修正します。このファイルは実際にAzure上にリソースを作成するためのものになります。
{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "newStorageAccountName": {
      "type": "string",
      "metadata": {
        "description": "This is the name of the your storage account"
      }
    },
    "dnsNameForPublicIP": {
      "type": "string",
      "metadata": {
        "description": "This is the unique DNS name of the for the public IP for your VM"
      }
    },
    "adminUserName": {
      "type": "string",
      "metadata": {
        "description": "This is the username you wish to assign to your VMs admin account"
      }
    },
    "adminPassword": {
      "type": "securestring",
      "metadata": {
        "description": "This is the password you wish to assign to your VMs admin account"
      }
    },
    "vmSize": {
      "type": "string",
      "metadata": {
        "description": "Size of VM"
      }
    },
    "addressPrefix": {
      "type": "string",
      "metadata": {
        "description": "This is the addressPrefix"
      }
    },
    "subnet1name": {
      "type": "string",
      "metadata": {
        "description": "This is the subnet1Name"
      }
    },
    "subnet1Prefix": {
      "type": "string",
      "metadata": {
        "description": "This is the subnet1Prefix"
      }
    },
    "PublicIPAddressName": {
      "type": "string",
      "metadata": {
        "description": "This is the PublicIPAddressName"
      }
    },
    "vmName": {
      "type": "string",
      "metadata": {
        "description": "This is the vmName"
      }
    },
    "virtualNetworkName": {
      "type": "string",
      "metadata": {
        "description": "This is the virtualNetworkName"
      }
    },
    "nicName": {
      "type": "string",
      "metadata": {
        "description": "This is the nicName"
      }
    },
    "imagePublisher": {
      "type": "string",
      "metadata": {
        "description": "This is the imagePublisher"
      }
    },
    "imageVersion": {
      "type": "string",
      "metadata": {
        "description": "This is the imageVersion"
      }
    },
    "imageSKU": {
      "type": "string",
      "metadata": {
        "description": "This is the imageSKU"
      }
    },
    "imageOffer": {
      "type": "string",
      "metadata": {
        "description": "This is the imageOffer"
      }
    }
  },
  "variables": {
    "vmStorageAccountContainerName": "vhds",
    "publicIPAddressType": "Dynamic",
    "storageAccountType": "Standard_LRS",
    "vnetID": "[resourceId('Microsoft.Network/virtualNetworks',parameters('virtualNetworkName'))]",
    "subnet1Ref": "[concat(variables('vnetID'),'/subnets/',parameters('subnet1Name'))]"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "name": "[parameters('newStorageAccountName')]",
      "apiVersion": "2015-05-01-preview",
      "location": "[resourceGroup().location]",
      "properties": {
        "accountType": "[variables('storageAccountType')]"
      }
    },
    {
      "apiVersion": "2015-05-01-preview",
      "type": "Microsoft.Network/publicIPAddresses",
      "name": "[parameters('publicIPAddressName')]",
      "location": "[resourceGroup().location]",
      "properties": {
        "publicIPAllocationMethod": "[variables('publicIPAddressType')]",
        "dnsSettings": {
          "domainNameLabel": "[parameters('dnsNameForPublicIP')]"
        }
      }
    },
    {
      "apiVersion": "2015-05-01-preview",
      "type": "Microsoft.Network/virtualNetworks",
      "name": "[parameters('virtualNetworkName')]",
      "location": "[resourceGroup().location]",
      "properties": {
        "addressSpace": {
          "addressPrefixes": [
            "[parameters('addressPrefix')]"
          ]
        },
        "subnets": [
          {
            "name": "[parameters('subnet1Name')]",
            "properties": {
              "addressPrefix": "[parameters('subnet1Prefix')]"
            }
          }
        ]
      }
    },
    {
      "apiVersion": "2015-05-01-preview",
      "type": "Microsoft.Network/networkInterfaces",
      "name": "[parameters('nicName')]",
      "location": "[resourceGroup().location]",
      "dependsOn": [
        "[concat('Microsoft.Network/publicIPAddresses/', parameters('publicIPAddressName'))]",
        "[concat('Microsoft.Network/virtualNetworks/', parameters('virtualNetworkName'))]"
      ],
      "properties": {
        "ipConfigurations": [
          {
            "name": "ipconfig1",
            "properties": {
              "privateIPAllocationMethod": "Dynamic",
              "publicIPAddress": {
                "id": "[resourceId('Microsoft.Network/publicIPAddresses',parameters('publicIPAddressName'))]"
              },
              "subnet": {
                "id": "[variables('subnet1Ref')]"
              }
            }
          }
        ]
      }
    },
    {
      "apiVersion": "2015-06-15",
      "type": "Microsoft.Compute/virtualMachines",
      "name": "[parameters('vmName')]",
      "location": "[resourceGroup().location]",
      "dependsOn": [
        "[concat('Microsoft.Storage/storageAccounts/', parameters('newStorageAccountName'))]",
        "[concat('Microsoft.Network/networkInterfaces/', parameters('nicName'))]"
      ],
      "properties": {
        "hardwareProfile": {
          "vmSize": "[parameters('vmSize')]"
        },
        "osProfile": {
          "computerName": "[parameters('vmName')]",
          "adminUsername": "[parameters('adminUsername')]",
          "adminPassword": "[parameters('adminPassword')]"
        },
        "storageProfile": {
          "imageReference": {
            "publisher": "[parameters('imagePublisher')]",
            "offer": "[parameters('imageOffer')]",
            "sku": "[parameters('imageSKU')]",
            "version": "[parameters('imageVersion')]"
          },
          "osDisk": {
            "name": "osdisk1",
            "vhd": {
              "uri": "[concat('https://',parameters('newStorageAccountName'),'.blob.core.windows.net/',variables('vmStorageAccountContainerName'),'/','osdisk1.vhd')]"
            },
            "caching": "ReadWrite",
            "createOption": "FromImage"
          }
        },
        "networkProfile": {
          "networkInterfaces": [
            {
              "id": "[resourceId('Microsoft.Network/networkInterfaces',parameters('nicName'))]"
            }
          ]
        }
      }
    }
  ]
}
    1. 「LinuxVirtualMachineScaleSet.parameters.json」に記載されている内容を削除し、以下の通り修正します。valueの値は、利用者の環境に合わせ修正ください。このファイルは上記ファイルが利用するパラメータファイルになります。
{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "newStorageAccountName": {
      "value": "rhblog1" //Azure上のストレージアカウント名を指定
    },
    "adminUsername": {
      "value": "SIOS" //OSの管理者名を指定
    },
    "adminPassword": {
      "value": "*************************" //OSの管理者パスワードを指定
    },
    "dnsNameForPublicIP": {
      "value": "rhblogpip1"
    },
    "virtualNetworkName": {
      "value": "rhblognt1" //Azure上の仮想ネットワーク名を指定
    },
    "vmSize": {
      "value": "Standard_A0" //Azureのインスタンスサイズを指定
    },
    "vmName": {
      "value": "rhblog1" //Azureの仮想マシン名を指定
    },
    "publicIPAddressName": {
      "value": "rhblogpip1" 
    },
    "nicName": {
      "value": "rhblognic1"
    },
    "addressPrefix": {
      "value": "10.0.0.0/16" //仮想ネットワークのネットワークのIPレンジを指定
    },
    "subnet1Prefix": {
      "value": "10.0.0.0/24" //仮想ネットワークのサブネットのIPレンジを指定
    },
    "subnet1name": {
      "value": "subnet-1" //仮想ネットワークのサブネット名を指定
    },
    "imagePublisher": {
      "value": "OpenLogic" //インストールするOSを変更する場合は、https://azure.microsoft.com/ja-jp/documentation/articles/virtual-machines-linux-cli-ps-findimage/ 参照ください。
    },
    "imageVersion": {
      "value": "latest"
    },
    "imageSKU": {
      "value": "7.2"
    },
    "imageOffer": {
      "value": "CentOS"
    }
  }
}

デプロイをする。

  1. 「ソリューションエクスプローラ」のプロジェクト名を右クリックし、「配置」-「新しい配置」をクリックします。%e3%82%ad%e3%83%a3%e3%83%97%e3%83%81%e3%83%a36
  2. 「サブスクリプション」を指定、「リソースグループ」で「新規作成」を選択し、リソースグループを作成するリージョンを指定します。
  3. 「配置」をクリックするとデプロイが開始されます。%e3%82%ad%e3%83%a3%e3%83%97%e3%83%81%e3%83%a34

作成した仮想マシンにログインします。

  1. Azureの管理コンソールにログインします。(https://manage.windowsazure.com/)
  2. リソースグループを確認し、「SIOSBlog-0001」が作成されている事を確認します。
  3. グローバルIPを確認し、Tera TermなどでSSH(22)ポートにアクセスします。アクセスできれば完成です。%e3%82%ad%e3%83%a3%e3%83%97%e3%83%81%e3%83%a35

 

アバター画像
About サイオステクノロジーの中の人です 88 Articles
サイオステクノロジーで働く中の人です。
ご覧いただきありがとうございます! この投稿はお役に立ちましたか?

役に立った 役に立たなかった

0人がこの投稿は役に立ったと言っています。


ご覧いただきありがとうございます。
ブログの最新情報はSNSでも発信しております。
ぜひTwitterのフォロー&Facebookページにいいねをお願い致します!



>> 雑誌等の執筆依頼を受付しております。
   ご希望の方はお気軽にお問い合わせください!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


質問はこちら 閉じる