从Azure Portal连接到VM所需的步骤 [英] Steps needed to connect to VM from Azure Portal
问题描述
我想按以下顺序创建Runbook:
I would like to create runbook(s) that in below order will:
1.启动特定的虚拟机
1. Startup a specific VM
2.在VM上运行本地命令(例如,启动Linux或Windows服务)
2. Run local command on VM (e.g. start Linux or Windows services)
我有一本启动特定Linux VM的运行手册,但似乎无法弄清楚如何将探针连接到VM并运行特定命令.
I have a runbook that starts a specific Linux VM, but I cannot seem to work out how to connect prober to the VM and run the specific command.
因此,启动VM"脚本如下:
So the "Start VM" script looks like this:
$ connection = Get-AutomationConnection-名称AzureRunAsConnection
Login-AzureRmAccount -ServicePrincipal -Tenant $ connection.TenantID`
-ApplicationId $ connection.ApplicationID -CertificateThumbprint $ connection.CertificateThumbprint
Start-AzureRmVM-名称'VM'-ResourceGroupName'RG'
$connection = Get-AutomationConnection -Name AzureRunAsConnection
Login-AzureRmAccount -ServicePrincipal -Tenant $connection.TenantID `
-ApplicationId $connection.ApplicationID -CertificateThumbprint $connection.CertificateThumbprint
Start-AzureRmVM -Name 'VM' -ResourceGroupName 'RG'
但是我对登录虚拟机时使用哪个功能和/或如何执行相关命令感到困惑.
But I'm confused about which function to use when logging on to the VM and/or how to execute the relevant command.
我没有运气就使用了几种不同的命令:
I have used several different commands without luck:
#1
Set-AzureRmVMCustomScriptExtension -ResourceGroupName RG`
-VMName VM`
-位置北欧"; `
-FileUri https://xxxcloudstorage.blob.core.windows.net/scripts/`
-运行'copyfile.sh'`
-名称"RunScript"
#1
Set-AzureRmVMCustomScriptExtension -ResourceGroupName RG`
-VMName VM`
-Location "North Europe" `
-FileUri https://xxxcloudstorage.blob.core.windows.net/scripts/ `
-Run 'copyfile.sh' `
-Name "RunScript"
#2
Invoke-AzureRmVMRunCommand -ResourceGroupName'RG'-名称'VM'-CommandId'RunShellScript'-ScriptPath'/home/tdj/test.sh'
#2
Invoke-AzureRmVMRunCommand -ResourceGroupName 'RG' -Name 'VM' -CommandId 'RunShellScript' -ScriptPath '/home/tdj/test.sh'
#3
Add-AzureAccount
错误:字典中不存在给定的键.
#3
Add-AzureAccount
Error: The given key was not present in the dictionary.
#4
新的SSHSession
错误:由于使用了强制开关,主机密钥尚未得到验证.
#4
New-SSHSession
Error: Host key is not being verified since Force switch is used.
---------------------------------------------------
-----------------------------------------------
我怀疑由于PS脚本中没有提供SSH密钥文件或VM中没有存储SSH密钥文件而导致登录部分失败.
I suspect the login part could be failing due to no SSH keyfile is provided in the PS script or stored on the VM.
总体而言,我正在寻找快速概述"或步骤列表"从Azure门户连接到VM并运行命令或脚本(本地存储或从Azure云存储存储)需要什么:
Overall I'm looking for a "quick overview" or "step list" what is needed in order to connect from Azure Portal to VM and run a command or script (store locally or from Azure cloud storage):
我需要为每个VM创建一个凭据吗?
Do I need to create a Credential for each VM?
我需要为每个VM创建一个连接吗?
Do I need to create a Connection for each VM?
是否有2个证书"AzureClassicRunAsCertificate"?和"AzureRunAsCertificate";足以登录到本地VM?
Are the 2 certificates "AzureClassicRunAsCertificate" and "AzureRunAsCertificate" sufficient to logon to local VM?
我也不知道是否可以运行启动虚拟机".部分,然后选择运行命令"在同一个Runbook中,或者如果我必须在第1个Runbook中包含第2个Runbook.
Also I'm not sure if can run the "Start VM" part and then the "Run command" in the same runbook or if I have to include the 2'nd runbook in the 1'st.
谢谢
Tom
推荐答案
一个小更新:
我在脚本下面运行,并得到了这个令人误解的错误,该错误表明它期望VM为Windows服务器.
I ran below script and got this misleading error which indicates that it expects the VM to be a Windows server.
谁能解释为什么会这样?实际上,这是我第一次收到显示某种VM访问权限的返回消息(但错误消息可能是错误的)...
Can anyone explain why this occurs? It's actually the first time I have got a return message showing some kind of VM access (but the error message could be wrong)...
PS脚本:
conn = Get-AutomationConnection -Name AzureRunAsConnection
Login-AzureRmAccount -ServicePrincipal -Tenant
conn = Get-AutomationConnection -Name AzureRunAsConnection
Login-AzureRmAccount -ServicePrincipal -Tenant
conn.TenantID`
-ApplicationId
conn.TenantID `
-ApplicationId
这篇关于从Azure Portal连接到VM所需的步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!