Azure   发布时间:2019-11-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Azure 基础 : 使用 Automation 定时开机大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

不知何时 Azure 为虚机提供了自动关机的功能。这是一个很棒的功能,可以帮助我们定时关闭虚机并释放掉资源以节省开支。如果某台虚机在夜间不需要提供服务,我们就可以把它配置为晚上的某个时间点自动关机:

title="Azure 基础 : 使用 Automation 定时开机" alt="Azure 基础 : 使用 Automation 定时开机" src="https://cn.js-code.com/res/2019/02-09/09/6672d990534f586aeeea713f56d5b70f.png" >

我们没有发现定时开机的相关配置!不仅如此,笔者在新建虚机的时候发现默认的设置中居然打开了定时关机的功能:

title="Azure 基础 : 使用 Automation 定时开机" alt="Azure 基础 : 使用 Automation 定时开机" src="https://cn.js-code.com/res/2019/02-09/09/d293dab3183accfd77cd8c50297a7507.png" >

Hell 脚本,在脚本中登录 Azure,然后执行开机的命令。如果要每天定时开机,可以创建一个计划任务定时执行 PowerSHell 脚本就可以了。考《http://www.cnblogs.com/sparkdev/p/6358266.html" target="_blank">Azure 基础:用 PowerSHell 自动登录》一文(只要把 demo 中重启虚机的命令改为启动命令就可以了)。但是这种方式有一个缺点:我们保存在文件中的登录信息会过期。也就是说每隔一段时间都需要重新登录一遍并导出新的登录信息到文件中。

@H_618_32@

title="Azure 基础 : 使用 Automation 定时开机" alt="Azure 基础 : 使用 Automation 定时开机" src="https://cn.js-code.com/res/2019/02-09/09/a94b68f36b77ad1c4da80073073ef34b.png" >

其中最重要的是一些执行各种自动化任务的 runbook:

title="Azure 基础 : 使用 Automation 定时开机" alt="Azure 基础 : 使用 Automation 定时开机" src="https://cn.js-code.com/res/2019/02-09/09/c6546889b5cfad8fd330da1f2d7be3f1.png" >

Hell 类型的 runbook:

title="Azure 基础 : 使用 Automation 定时开机" alt="Azure 基础 : 使用 Automation 定时开机" src="https://cn.js-code.com/res/2019/02-09/09/76feda5c800bbb3cb73780b07aca2f29.png" >

@H_618_32@

Hell 类型的 runbook 后就可以编辑真正干活的脚本了,在 runbook 的编辑器中输入下面的代码:

197_69@ = message = successfully.{ servicePrincipalConnection=Get-AutomationConnection -Name --servicePrincipal ` -TenantId servicePrincipalConnection-ApplicationId servicePrincipalConnection-CertificateThumbprint servicePrincipalConnection-AzureRmVM -Name 'vm name' -resourceGroupName 'resource group name' } catch { message = (!servicePrincipalConnection{ message = message{ Write-Error -message { = password = ConvertTo-SecureString password -AsPlaintext - = New-Object System.Management.Automation.PSCredential ,password = = m.comString[]] = ject = = message-Mailmessage -smtpServer ` -Credential ` -Usessl ` -Port 587 ` -from ` -to ` -subject ject ` -Body ` --Output succesfully.

相应的认证信息。脚本中使用的 AutomationConnection 名字为 AzureRunAsConnection,它是随着 Automation Account 一起创建的。如果 AzureRunAsConnection 不能满足需求,我们可以创建自定义的 AutomationConnection。

@H_618_32@

197_69@ = password = ConvertTo-SecureString password -AsPlaintext - = New-Object System.Management.Automation.PSCredential ,password = = m.comString[]] = ject = = message-Mailmessage -smtpServer ` -Credential ` -Usessl ` -Port 587 ` -from ` -to ` -subject ject ` -Body ` --Output succesfully.

@H_618_32@

title="Azure 基础 : 使用 Automation 定时开机" alt="Azure 基础 : 使用 Automation 定时开机" src="https://cn.js-code.com/res/2019/02-09/09/4391d86ff86eadd61d137493d45722a0.png" >

你的脚本,并输出执行的日志信息。通过这种方式我们可以检查脚本的执行情况并对脚本进行调整。

@H_618_32@

title="Azure 基础 : 使用 Automation 定时开机" alt="Azure 基础 : 使用 Automation 定时开机" src="https://cn.js-code.com/res/2019/02-09/09/844665015d1abb1fd8c766b2ac374c48.png" >

@H_618_32@

607_10998@的。由于内部是通过 Azure 的认证机制完成权限认证的,所以它能够完美的解决我们在其它方案中碰到的登录认证问题。

大佬总结

以上是大佬教程为你收集整理的Azure 基础 : 使用 Automation 定时开机全部内容,希望文章能够帮你解决Azure 基础 : 使用 Automation 定时开机所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。

标签: