In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
This is the first technology-related tip on this blog, and I won't go into details about the use of the technical components involved here, because I'm sure you can learn about them through the official documentation. If you are an IT rookie who still looks dazed after reading the official documents, personal advice is to start with the basics and then look at the specific needs and solutions.
In this article we will cover two concepts, one is Azure automation, and the other is resource's tag.
I won't say much about Tag, most systems or platforms will have the Key-value logo function.
Automation, at least understand the basic concepts of runbook, job, and schedule before you can move on.
Requirements: in order to avoid unnecessary waste of resources, many test development environments can be shut down during non-working hours to achieve cost savings.
If your company has too much money to burn, you can proudly ignore this need.
If you don't have much to say, post runbook for your reference:
Workflow Autoshutdown_by_tag
{
$connectionName = "AzureRunAsConnection"
Try
{
$servicePrincipalConnection=Get-AutomationConnection-Name $connectionName
"Logging in to Azure..."
Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint `
-EnvironmentName AzureChinaCloud
}
Catch {
If (! $servicePrincipalConnection)
{
$ErrorMessage = "Connection $connectionName not found."
Throw $ErrorMessage
} else {
Write-Error-Message $_ .Exception
Throw $_. Exception
}
}
$subs = Get-AzureRmSubscription
Foreach ($sub in $subs)
{
Select-AzureRmSubscription-SubscriptionId $sub.SubscriptionId-ErrorAction Continue
$VMs = Get-AzureRmVm-status | Where-Object {$_ .Tags.Keys-eq "AutoShutdown"-and $_ .Tags.Values-eq "Yes"}
ForEach-Parallel-ThrottleLimit 10 ($VM in $VMs)
{
If ($vm.powerstate-eq "VM deallocated")
{Write-Output "$($VM.Name) is already shutdown"}
Else
{Write-Output "Stop: $($VM.Name)"; Stop-AzureRMVM-Name $VM.Name-ResourceGroupName $VM.ResourceGroupName-force}
}
}
}
Specific description:
1. First of all, the purpose of this runbook is to traverse all virtual machines under your account that have a label Autoshutdown and have a value of Yes, and detect their powerstate, and execute the stop-AzureRMVM command to shut down if it is not deallocated. Labels and values can be customized exactly to their preferences.
two。 This runbook needs to be associated with the corresponding schedule to be executed on time, and the details of how to do it will not be explained in detail.
3. The run as account of this Automation cannot be expired, and you must have access to the corresponding virtual machine. The custom role in RBAC will be covered in a special article later, so I won't go into it here.
4. Instead of a normal powershell script, workflow is used here. The main advantage is that it can operate in parallel. Here, "ForEach-Parallel-ThrottleLimit 10" sets up to shut down up to 10 virtual machines at the same time. When there are a large number of virtual machines on your cloud platform, sequential operations will consume a lot of script running time. Generally speaking, the shutdown action of a virtual machine ranges from 5 to 10 minutes, and it is very likely that your job will time out.
5. The boot runbook is similar to the shutdown, except that the start-AzureRMVM command is used. In addition, in the new AzureRM.Compute module, stop-AzureRMVM needs to be confirmed by human-computer interaction, so it needs to be enforced with-force, and this small tip can be used in any other similar powershell command.
In fact, there are some other knowledge points involved here, some of which I will describe in detail in other tips. But if you just want to get this feature running, it's actually very easy.
For an IT practitioner, you can make a living if you only know what it is. But once you meet a master, you will still reveal your true colors, and it is natural to be despised by others. So we still know why.
Generally speaking, the mastery of IT knowledge is divided into four stages: User-- > Know what--- > troubleshooting--- > Expert. If you are in a technology-related position, you should at least reach the Troubleshooting or expert level in your professional field, and at least know what for others. Here also involves the construction of the knowledge system, and then I will share some relevant experience.
I hope this article can enlighten the friends who maintain Azure on a daily basis. If you have any suggestions, please feel free to leave a comment for discussion.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.