27.06.2016, 16:11 | #1 |
Участник
|
kurthatlevik: How I saved thousands of dollars on my Azure environments!
Источник: https://kurthatlevik.wordpress.com/2...-environments/
============== I just love such headlines, because it instantly attracts attention. But in this case it is actually true. And Microsoft is even wants us to do this. I want to write how to automatically shut down and start up environments in Azure, so that you are not spending more than needed. This post is for newbies, and experts surely will bombard the comment section with improved suggestions on how to make it even better. In this example I have 4 environment running in Azure and the machine type I prefer is the D13_v2. This will cost me 3696 USD per month if I just let them stay on for 744 hours per month. But I only plan to use them 07:00 à 17:00 Monday to Friday. This is 200 hours per month, and then it will just cost 993 USD J A lot of fun can be done with these extra credits. So what is the next step? The trick is to use the Azure Powershell Runbook. Here is the step-by-step instruction on how to set it up: 1. Log into Azure, and open the Azure automation 2. Add an Automation Account. Create a name, like “TurnOffOnVM”. Select the subscription, and if a resource group should be created. Also if you want an Azure Run As Account. (I didn’t bother to have that, since I have no important stuff on these environments) 3. Then create an Asset named “automation” for holding credentials, that will run the shutdown/start up scripts. The credentials you are using must have the rights to run scripts and to start/stop VM’s. 4. Let’s create 2 Runbooks, that holds the scripts and schedules for the start and stop scripts. 5. Use the “Powershell Workflow” type 6. Let’s put in the “Start script”. It’s done here I have removed my VM-names in this example. If you wonder what your VM name is, it is the computer name, that can be seen here: Here is a copy-paste version of the Start-up script: workflow StartVM { $cred = get-automationpscredential -name “automation” add-azureaccount -credential $cred select-azuresubscription -subscriptionname “Microsoft Azure Enterprise” $VMs = Get-AzureVM foreach($VM in $VMs) { if ($VM.Name -In “VMName1”, “VMName2”, “VMName3”, “VMName4” ) { if ($VM.PowerState -ne “Started”) { Start-AzureVM -Name $VM.Name -ServiceName $VM.ServiceName -ErrorAction Continue } } } } 7. Let’s put in the “Stop script”. It is basically the same procedure as creating the “start script”, so I just add the copy-past version of the script. workflow StopVM { $cred = get-automationpscredential -name “automation” add-azureaccount -credential $cred select-azuresubscription -subscriptionname “Microsoft Azure Enterprise” $VMs = Get-AzureVM foreach($VM in $VMs) { if ($VM.Name -In “VMName1”, “VMName2”, “VMName3”, “VMName4” ) { if($vm.Status -eq ‘ReadyRole’) { Stop-AzureVm -Name $vm.Name -ServiceName $vm.ServiceName -Force } } } } Remember to press the “publish” button the scripts J 8. Let’s create a schedule (one for the Start runbook, and one for the stop runbook) 9. You can now monitor the start/stop scripts: 10. Go party with all the credits you have saved! And if you see me, and use this script, buy me a beer J Happy DAX’ing J Источник: https://kurthatlevik.wordpress.com/2...-environments/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|
|
Опции темы | Поиск в этой теме |
Опции просмотра | |
|