
はじめに
前回までに、Azule CLIを利用して、リソースグループと仮想ネットワーク、その仮想ネットワーク内にサブネット、ネットワークセキュリティーグループ、パブリックIP、NIC、ストレージアカウントを作成しました。これらのリソースが仮想マシンを作成する上で必要です。
仮想マシン
では、仮想マシンを作成していきます。
OS image を選択
事前にどの発行者のどのimagesを選ぶかを決めます。
publisherを次のコマンドで表示します。
# azure vm image list-publishers
表示された発行者の中からお目当ての発行者を選択します。
次に、選択したpublisherがどんなimagesを提供しているのかを確認します。
# azure vm image list-offers
表示されたoffersの中からお目当てのofferを選択します。
次に選択したOfferが提供しているUrnを選択します。
# azure vm image list
今回はCanonical:UbuntuServer:16.10:16.10.201610201
を選択しました。
仮想マシンの作成
早速仮想マシンを作成します。
次のコマンドで仮想マシンを作成する事ができます。
[code]
# azure vm create \
-g \ #リソースグループ名を指定
-n \ #仮想マシン名を指定
-l \ #ロケーションを指定
–os-type \ #OSタイプを指定(windows or linux)
–image-urn \ #事前作業でのimage-urn を指定
–admin-username \ #admin-usernameを指定
–generate-ssh-keys \ #公開鍵と秘密鍵を作成する
–vm-size \ #vmのサイズを指定
–public-ip-name \ #パブリックIP名を指定
–nic-name \ #NIC名を指定
–vnet-name \ #VNet名を指定
–vnet-subnet-name \ #サブネットを指定
–storage-account-name #ストレージを指定
[/code]
VMのサイズは次のサイトを参考にしてください。
https://azure.microsoft.com/ja-jp/documentation/articles/virtual-machines-size-specs/
[code]
# azure vm create -g TestResourceGroup -n TestUbuntu \
-l japaneast –os-type Linux \
–image-urn Canonical:UbuntuServer:16.10:16.10.201610201 \
–admin-username testuser –generate-ssh-keys \
–vm-size Standard_D1 –public-ip-name TestPIP \
–nic-name TestNIC –vnet-name TestVNet \
–vnet-subnet-name TestSNet –storage-account-name asstorage
info: Executing command vm create
+ Looking up the VM “TestUbuntu”
info: You can use /root/.azure/ssh/TestUbuntu-key.pem private key for SSH authentication.
info: Verifying the public key SSH file: /root/.azure/ssh/TestUbuntu-cert.pem
info: Using the VM Size “Standard_D1”
info: The [OS, Data] Disk or image configuration requires storage account
+ Looking up the storage account asstorage
+ Looking up the NIC “TestNIC”
info: Found an existing NIC “TestNIC”
info: Found an IP configuration with virtual network subnet id “/subscriptions/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee/resourceGroups/TestResourceGroup/providers/Microsoft.Network/virtualNetworks/TestVNet/subnets/TestSNet” in the NIC “TestNIC”
info: This NIC IP configuration is already configured with the provided public ip “TestPIP”
info: The storage URI ‘https://asstorage.blob.core.windows.net/’ will be used for boot diagnostics settings, and it can be overwritten by the parameter input of ‘–boot-diagnostics-storage-uri’.
+ Creating VM “TestUbuntu”
info: vm create command OK
[/code]
少し時間はかかりましたが、作成できたようです。
確認
次のコマンドで確認できます。
# azure vm list -g
[code]
# azure vm list -g TestResourceGroup
info: Executing command vm list
+ Getting virtual machines
data: ResourceGroupName Name ProvisioningState PowerState Location Size
data: —————– ———- —————– ———- ——— ———–
data: TestResourceGroup TestUbuntu Succeeded VM running japaneast Standard_D1
info: vm list command OK
[/code]
TestResourceGroupに仮想マシンTestUbuntuが作成できました。
接続テスト
公開鍵は仮想マシン作成時に--generate-ssh-keys
を指定したので、/root/.azure/ssh/TestUbuntu-key.pem
に生成されています。
接続するパブリックIPは次のコマンドで確認できます。
# azure network public-ip list -g
ssh接続してみます。
[code]
# ssh testuser@PublicIP -i /root/.azure/ssh/TestUbuntu-key.pem
testuser@TestUbuntu:~$ uname -a
Linux TestUbuntu 4.8.0-26-generic #28-Ubuntu SMP Tue Oct 18 14:39:52 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[/code]
終わりに
今回はAzure CLIをつかって一つ一つリソースを作りました。かなり面倒でしたが、すこしAzureの理解が深まったのではないでしょうか。
以上で「Azure CLI で仮想マシンを作成する」は終了です。
お疲れ様でした。
因みに仮想マシンは起動している状態だと課金されるのでいらない場合は下記のコマンドでリソースグループを削除できます。
# azure group delete
参考


コメント投稿