Skip to content

Commit

Permalink
Merge pull request #152 from microsoft/typofix202403
Browse files Browse the repository at this point in the history
Typofix202403
  • Loading branch information
ajendreieckm authored Apr 8, 2024
2 parents cfce5e6 + 3449646 commit 9c89638
Show file tree
Hide file tree
Showing 21 changed files with 190 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Tips and trick for maintaining the linux microhack.
az group list --query [].name -o tsv

# List all resources inside a resource group
sourceRgName=$(az group list --query "[?ends_with(name, 'source-rg')].name" -o tsv)
destinationRgName=$(az group list --query "[?ends_with(name, 'destination-rg')].name" -o tsv)
sourceRgName=$(az group list --query "[?starts_with(name, '$prefix') && ends_with(name, 'source-rg')].name" -o tsv)
destinationRgName=$(az group list --query "[?starts_with(name, '$prefix') && ends_with(name, 'destination-rg')].name"
az resource list -g $sourceRgName -o table
# Login to Azure with local user
Expand All @@ -28,8 +28,8 @@ az group delete --name ${prefix}1-$suffix-source-rg --yes --no-wait
# Install Azure SSH AAD
az vm extension set --publisher Microsoft.Azure.ActiveDirectory --name AADSSHLoginForLinux --ids $sourceVM1Id $sourceVM2Id
az quota create --resource-name StandardSkuPublicIpAddresses --scope /subscriptions/$subid/providers/Microsoft.Network/locations/$location --limit-object value=100 --resource-type PublicIpAddresses
az quota create -h
az login --use-device-code
# Assign application developer role to user of a group
# Get the object ID of the custom role
Expand All @@ -42,6 +42,30 @@ group_id=$(az ad group show --group 'MH - Linux Migration' --query id -o tsv)
az rest --method POST --uri "https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignments" --headers "Content-type=application/json" --body '{"@odata.type": "#microsoft.graph.unifiedRoleAssignment","roleDefinitionId": "'$role_id'","principalId": "'$group_id'","directoryScopeId": "/"}'
az rest --method POST --uri "https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignments" --headers "Content-type=application/json" --body '{"@odata.type": "#microsoft.graph.unifiedRoleAssignment","roleDefinitionId": "cf1c38e5-3621-4004-a7cb-879624dced7c","principalId": "'$group_id'","directoryScopeId": "/"}'
# Add needed providers
subid=651e7801-9bd4-457d-8e91-3afe3139da8d # MH - Linux Migration
az account set --subscription $subid
az provider register --namespace Microsoft.Compute
az provider show --namespace Microsoft.Compute --query "registrationState"
az provider register --namespace Microsoft.Network
az provider register --namespace Microsoft.Storage
az provider register --namespace Microsoft.Resources
az provider register --namespace Microsoft.KeyVault
az provider register --namespace Microsoft.OperationalInsights
az provider register --namespace Microsoft.OperationsManagement
az provider register --namespace Microsoft.Insights
# Increase quota
location=germanywestcentral
# not working because of MF requirement
az quota create --resource-name StandardSkuPublicIpAddresses --scope /subscriptions/$subid/providers/Microsoft.Network/locations/$location --limit-object value=100 --resource-type PublicIpAddresses
az quota create -h
# list quotas for public standard IPs via azure cli
az quota list --scope subscriptions/$subid/providers/Microsoft.Network/locations/$location --query "[?name=='StandardSkuPublicIpAddresses'].properties.limit"
az quota list --scope subscriptions/$subid/providers/Microsoft.Network/locations/$location --query "[?name=='PublicIPAddresses'].properties.limit"
az quota list --scope subscriptions/$subid/providers/Microsoft.Compute/locations/$location --query "[?name=='cores'].properties.limit"
~~~
### Linux
Expand Down Expand Up @@ -74,21 +98,60 @@ Per Table
### screen capture and mp4 to animated gif
Screen capture with Microsoft [Clipchamp](https://clipchamp.com/en/screen-recorder/)
~~~bash
~~~bash
# Install ffmpeg on Ubuntu
sudo apt install ffmpeg -y
# Install imagemagick
sudo apt install imagemagick -y
# Install gifsicle
sudo apt install gifsicle -y
cd resources
# verify video size
ffprobe -v error -select_streams v:0 -show_entries stream=width -of csv=s=x:p=0 ./media/mh.linux.login.mp4 # 1280x720
# increase imagemagick memory limit
free -h # 2.0G
sudo nano /etc/ImageMagick-6/policy.xml
sudo sed -i 's/<policy domain="resource" name="memory" value="256MiB"\/>/<policy domain="resource" name="memory" value="2GiB"\/>/g' /etc/ImageMagick-6/policy.xml
chmod +x ./resources/mp4togif.sh
# convert mp4 to gif
./mp4togif.sh ./media/mh.linux.login.mp4 ./media/mh.linux.login.gif
mv ./media/mh.linux.login.gif ../walkthrough/challenge-1/img/mh.linux.login.gif
./mp4togif.sh ./media/mh.linux.lb.test.mp4 ./media/mh.linux.lb.test.gif
mv ./media/mh.linux.lb.test.gif ../walkthrough/challenge-1/img/mh.linux.lb.test.gif
./mp4togif.sh ./media/mh.linux.webserver.test.mp4 ./media/mh.linux.webserver.test.gif
mv ./media/mh.linux.webserver.test.gif ../walkthrough/challenge-1/img/mh.linux.webserver.test.gif

~~~
### Git
The `git stash` command allows you to temporarily save changes that you have made to your working directory but do not want to commit yet. It takes your modified tracked files and staged changes, saves them away for later use, and then reverts them to the state of the last commit.
The changes stashed away by this command can be listed with `git stash list`, inspected with `git stash show`, and restored (potentially on top of a different commit) with `git stash apply`. Calling `git stash` without any arguments is equivalent to `git stash push`. A stash is by default listed as "WIP on branchname …", but you can give a more descriptive message on the command line when you create one.
The modifications stashed away by this command can be reapplied using `git stash apply` or `git stash pop`. You can also drop a stash with `git stash drop` after you are done with it.
~~~bash
git remote show
git remote -v
git remote show origin
git remote add msft https://github.com/microsoft/MicroHack.git
# store uncommited changes via stash
git stash
# create new branch to add changes
git checkout -b typofix202403
# apply stashed changes
git stash apply
git status
git add .
git commit -m "several fixes including changing Region"
git push --set-upstream msft typofix202403
gh pr create --title "typofix202403" --body "several fixes including changing Region" --base msft
~~~
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ The goal of this exercise is to...

### Learning resources
* [Create and managed Azure Migrate projects](https://learn.microsoft.com/en-us/azure/migrate/create-manage-projects)
* [Steup an appliance for physical servers](https://learn.microsoft.com/en-us/azure/migrate/how-to-set-up-appliance-physical)
* [Setup an appliance for physical servers](https://learn.microsoft.com/en-us/azure/migrate/how-to-set-up-appliance-physical)
* [Before you start / general prerequisites](https://learn.microsoft.com/en-us/azure/migrate/how-to-discover-applications#before-you-start)

### Solution - Spoilerwarning
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

# https://github.com/jclem/gifify
# Bash script which does make use of ffmpeg and imagemagick to create an animated gif from a mpf4 video file.
# Usage: ./mp4togif.sh <input file> <output file>
# Example: ./mp4togif.sh input.mp4 output.gif
Expand Down Expand Up @@ -39,7 +40,29 @@ if ! command -v convert >/dev/null 2>&1; then
exit 1
fi

ffmpeg -i $inputFileName -vf scale=320:-1 -r 10 -f image2pipe -vcodec ppm - >> ./mp4tgif.tmp
cat ./mp4tgif.tmp | convert +dither -delay 5 -loop 0 - $outputFileName
rm ./mp4tgif.tmp
width=$(ffprobe -v error -select_streams v:0 -show_entries stream=width -of csv=s=x:p=0 $inputFileName)
fps=10
speed=1
delay=$(bc -l <<< "100/$fps/$speed")

ffmpeg -i $inputFileName -vf scale=$width:-1:flags=lanczos -r $fps -f image2pipe -vcodec ppm - > ./media/mp4tgif.ppm
cat ./media/mp4tgif.ppm | convert +dither -delay $delay -loop 0 - ./media/mp4tgif.large.gif
gifsicle --optimize=3 --use-colormap web ./media/mp4tgif.large.gif > $outputFileName


# Convert the video to frames
# ffmpeg -i $inputFileName -vf "fps=$fps,scale=$width:-1:flags=lanczos" -c:v pam -f image2 ./media/output/frame%03d.pam
# convert -layers Optimize -delay 10 -loop 0 ./media/output/frame*.pam ./media/mp4tgif.large.gif
# gifsicle --optimize=3 --use-colormap web ./media/mp4tgif.large.gif > $outputFileName

######
# First pass: generate palette
# ffmpeg -y -i $inputFileName -vf "fps=10,scale=$width:-1:flags=lanczos,palettegen" ./media/palette.png
# # Second pass: use palette to create GIF
# ffmpeg -i $inputFileName -i ./media/palette.png -filter_complex "fps=10,scale=$width:-1:flags=lanczos[x];[x][1:v]paletteuse" ./media/output.large.gif
# # Optimize GIF
# gifsicle --optimize=3 --colors 512 ./media/output.large.gif > ./media/output.small.gif
######
# rm ./media/mp4tgif.ppm
# rm ./media/mp4tgif.large.gif

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,19 @@ Duration: 30 minutes

- Please ensure that you successfully verified the [General prerequisits](../../README.md#general-prerequisites) before continuing with this challenge.
- The Azure CLI is required to deploy the Bicep configuration of the Micro Hack.


- Download the *.bicep files from the [Resources](../../resources) to your local PC.

### ***Task 1: Get youre environment ready***

- Ensure you have access to the Azure Portal at https://portal.azure.com.

#### Start Cloud Shell

- Login to the Azure Portal at https://portal.azure.com.
- Launch **Cloud Shell** from the top navigation of the Azure portal.

![Screenshot showing how to start Azure Cloud Shell in the Azure portal.](./img/AzMigCloudShell1.png)
- The first time you start Cloud Shell you're prompted to create an Azure Storage account for the Azure file share.
![Screenshot showing the create storage prompt.](./img/AzMigCloudShell2.png)

- Select the **Subscription** used to create the storage account and file share.
- Select **Create storage**.

Expand Down Expand Up @@ -80,15 +78,15 @@ az account list
az account set --subscription '<REPLACE-WITH-YOUR-SUBSCRIPTION-NAME>'
~~~



### **Task 2: Deploy the Landing Zone for the Micro Hack**

The following command will deploy the landing zone for the Micro Hack. The landing zone contains all resources required for the Micro Hack. The deployment will take about 10 minutes.

> [!IMPORTANT] The following variables value should be changed to avoid conflicts with other deployments in your Azure subscription.
~~~bash
# Define prefix and suffix for all azure resources
prefix="51" # replace sm with your own prefix
prefix="1Team" # replace sm with your own prefix
suffix=a # replace a with your own suffix
# Have a look at all possible azure location with Azure CLI
az account list-locations -o table # List all possible Azure locations
Expand All @@ -97,13 +95,14 @@ location=germanywestcentral
# Get our Entra ID Object ID, will be needed to assign us Admin rights to the azure VMs
currentUserObjectId=$(az ad signed-in-user show --query id -o tsv)
# Define VM admin password and username
adminPassword='demo!pass123'
adminPassword='demo!pass123!'
adminUsername='microhackadmin'
# Create Azure Resources with Azure Bicep Resource Templates and Azure CLI
az deployment sub create --location $location --template-file ./resources/main.bicep --parameters prefix=$prefix currentUserObjectId=$currentUserObjectId location=$location adminPassword=$adminPassword suffix=$suffix adminUsername=$adminUsername
~~~

### **Task 3: Verify the deployed resources**

The bicep deployment should have created the following resources

- source-rg Resource Group containing the follwing resources
Expand All @@ -117,7 +116,8 @@ The bicep deployment should have created the following resources
You can get a list of all resources in the resource group with the following Azure CLI command:
~~~bash
# List all resource in the resource group
az resource list -g $(az group list --query "[?ends_with(name, 'source-rg')].name" -o tsv) -o table
sourceRgName=$(az group list --query "[?starts_with(name, '$prefix') && ends_with(name, 'source-rg')].name" -o tsv)
az resource list -g $sourceRgName --output table
~~~

- destination-rg Resource Group containing the follwing resources
Expand All @@ -127,7 +127,8 @@ az resource list -g $(az group list --query "[?ends_with(name, 'source-rg')].nam
You can get a list of all resources in the resource group with the following Azure CLI command:
~~~bash
# List all resource in the resource group
az resource list -g $(az group list --query "[?ends_with(name, 'destination-rg')].name" -o tsv) -o table
destinationRgName=$(az group list --query "[?starts_with(name, '$prefix') && ends_with(name, 'destination-rg')].name" -o tsv)
az resource list -g $destinationRgName -o table
~~~

The deployed architecture looks like following diagram:
Expand All @@ -145,15 +146,16 @@ Log into the first VM in the resource group with Azure Bastion and install the m

~~~bash
# Get the name of the resource group that ends with 'source-rg'
sourceRgName=$(az group list --query "[?ends_with(name, 'source-rg')].name" -o tsv)
sourceRgName=$(az group list --query "[?starts_with(name, '$prefix') && ends_with(name, 'source-rg')].name" -o tsv)
# Get the Azure Resource ID of the VMs in the source resource group
sourceVm1Id=$(az vm list -g $sourceRgName --query "[?ends_with(name, '${suffix}1')].id" -o tsv)
sourceVm2Id=$(az vm list -g $sourceRgName --query "[?ends_with(name, '${suffix}2')].id" -o tsv)
# Name of the Azure Bastion in the source resource group
TODO: Try to get the bastion name from the deployment output instead of hardcoding it.
sourceBastionName=${prefix}1$suffix-source-bastion
# Login to the first VM in the resource group with Azure Bastion
# IMPORTANT
az network bastion ssh -n $sourceBastionName -g $sourceRgName --target-resource-id $sourceVm1Id --auth-type password --username $adminUsername

# Inside the VM check if cloud-init is running
sudo cloud-init status # should return 'status: done', if not wait a few minutes and try again
# check if server is running
Expand All @@ -166,6 +168,8 @@ logout

![image](./img/mh.linux.webserver.test.gif)

![image](./img/mh.linux.webserver.test.gif)

### **Task 4: Verify Web Server availability**

The following instruction will guide you through the verification of the deployed web servers via the Azure Portal
Expand All @@ -176,6 +180,9 @@ The following instruction will guide you through the verification of the deploye
- Open web browser and navigate to http://LoadBalancerFrontEnd-IP-Address
- A simple website containing details about the request and response should be displayed

![image](./img/mh.linux.lb.test.gif)
- A simple website containing details about the request and response should be displayed

![image](./img/mh.linux.lb.test.gif)

You can verify things direclty via azure cli if you want to:
Expand Down Expand Up @@ -236,3 +243,4 @@ resh:{
You successfully completed challenge 1! 🚀🚀🚀

**[Home](../../README.md)** - [Next Challenge Solution](../challenge-2/solution.md)
**[Home](../../README.md)** - [Next Challenge Solution](../challenge-2/solution.md)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ Select *Servers, databases and web app* from the navigation pane on the left and

Select the *destination-rg* Resource Group, specify a name for the Azure Migrate Project and also select a geograpy where the data will be stored.

> [!IMPORTANT]
> Make sure to select the right subscription. In case there are several subscriptions available, please select the subscription that was used to deploy the Azure Landing Zone.

![image](./img/AzMig3.png)

Wait until the Azure Migrate Project has been created. Select *Servers, databases and web apps* from the navigation pane on the left.
Your previousley created Azure Migrate project should be preselected.
Your previously created Azure Migrate project should be preselected.

![image](./img/AzMig4.png)

Expand All @@ -63,7 +67,7 @@ In the Azure Portal select *Virtual machines* from the navigation pane on the le

Under Basics select the *source-rg* Resource Group and provide a name for the server. Select *Windows Server 2019 Datacenter - x64 Gen2* for the Image.

![image](./img/AzMigApp2_1.png)
![image](./img/AzMigApp2_2.png)

Accept the default disk settings and click next to select the *Networking* tab. Select the *source-vnet* Virtual Network, select the *source-subnet* Subnet and make sure to select *None* for the Public IP and NIC network security group.

Expand All @@ -88,7 +92,7 @@ You can also create the Azure Migrate Appliance VM via Azure Resource Manager Te
# Define a name for the VM which will be used for the Azure Migrate Appliance
migVmName=${prefix}1${suffix}Mig
# Get the name of the resource group that ends with 'source-rg'
sourceRgName=$(az group list --query "[?ends_with(name, 'source-rg')].name" -o tsv)
sourceRgName=$(az group list --query "[?starts_with(name, '$prefix') && ends_with(name, 'source-rg')].name" -o tsv)
# Get the name of the source vnet via Azure CLI
sourceVnetName=$(az network vnet list --query "[?ends_with(name, 'source-vnet')].name" -o tsv)
# Get the name of the source subnet
Expand Down Expand Up @@ -123,6 +127,10 @@ Select *Bastion* from the navigation pane on the left, provide the credentials t

### **Task 3: Install the Azure Migrate Appliance**

> [!IMPORTANT]
You will need to install Microsof Edge Browser or Chrome on the Azure Migrate Appliance VM. Internet Explorer 11 is not supported.
> - [New Windows 2019 server, how to install Microsoft Edge browser](https://learn.microsoft.com/en-us/answers/questions/937532/new-windows-2019-server-how-to-install-microsoft-e)
Open Microsoft Edge on the Windows Server 2019 system and navigate and login to the [Azure Portal](https://portal.azure.com).

![image](./img/AzMigApp7.png)
Expand All @@ -131,7 +139,7 @@ In the search bar enter *Azure Migrate* and select Azure Migrate from the list o

![image](./img/AzMig1.png)

Select *Servers, databases and web apps*, make sure that the previousley created Azure Migrate project is selected and klick *Discover*
Select *Servers, databases and web apps*, make sure that the previously created Azure Migrate project is selected and klick *Discover*

![image](./img/Discover1.png)

Expand Down Expand Up @@ -161,6 +169,8 @@ Change the PowerShell directory to the folder where the contents have been extra
Run the script named AzureMigrateInstaller.ps1 and select *A* to confirm script execution.

~~~powershell
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
cd .\AzureMigrateInstaller\
.\AzureMigrateInstaller.ps1
~~~
Expand Down Expand Up @@ -248,15 +258,12 @@ The friendly name will be used later on when specifiying the individual systems.
Next you need to provide the individual source server details and map them to a specific set of credentials. Make sure that validation is successfull.
~~~bash
# list all IPs of resource group source-rg
~~~bash
sourceRgName=$(az group list --query "[?starts_with(name, '$prefix') && ends_with(name, 'source-rg')].name" -o tsv)
az vm list-ip-addresses -g $sourceRgName -o table
~~~
> [!NOTE]
> List all IPs of resource group source-rg via Azure CLI
>
> ~~~bash
> az vm list-ip-addresses -g $(az group list --query "[?ends_with(name, 'source-rg')].name" -o tsv) -o table
> ~~~

![image](./img/Discover15_1.png)
Expand All @@ -283,3 +290,4 @@ The deployed architecture now looks like the following diagram.
![image](./img/Challenge-2.jpg)

**[Home](../../README.md)** - [Next Challenge Solution](../challenge-3/solution.md)
**[Home](../../README.md)** - [Next Challenge Solution](../challenge-3/solution.md)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9c89638

Please sign in to comment.