Project

General

Profile

Azure VPS setup notes » History » Version 37

Jon Goldberg, 05/13/2022 09:45 PM

1 12 Jon Goldberg
{{last_updated_at}} by {{last_updated_by}}
2
3 14 Jon Goldberg
# Microsoft Azure - Setup
4 6 Jon Goldberg
5 14 Jon Goldberg
## For the Client
6 6 Jon Goldberg
7 22 Jon Goldberg
Hi there!  If I've directed you to this page, the part that concerns you are the first three sections only.  It's a bit convoluted, so feel free to ask me if you run into trouble! -Jon
8 14 Jon Goldberg
9 1 Jon Goldberg
[**NOTE**: Most of Microsoft's pages break with an ad blocker enabled.]
10 6 Jon Goldberg
11
### Get a Sponsorship
12
* [Go to the Nonprofit Microsoft Getting Started page](https://nonprofit.microsoft.com/en-us/getting-started).  Fill out the paperwork to be approved as a 501c3.  Approval can take 1 day or 3-4 weeks - I've seen both multiple times.
13
* Once approved, go to https://www.microsoft.com/en-us/nonprofits/azure to claim credits (or go directly to [Claiming Your Credits](https://nonprofit.microsoft.com/en-us/offers/azure).
14 14 Jon Goldberg
* You'll know your successful because you'll see a sponsorship listed on the [Sponsorship Page](https://www.microsoftazuresponsorships.com/Balance).
15 6 Jon Goldberg
16
### Create a Subscription
17
18 1 Jon Goldberg
* Check that you have credits in your sponsored account: https://www.microsoftazuresponsorships.com/Balance
19
* Visit the [Azure Portal](https://portal.azure.com).  
20
* Click the **Subscriptions** icon.
21
* Click the **Add** button.
22
* Add a subscription of type "Microsoft Azure Sponsorship" from the Azure portal. You will likely need to select **Show other subscription types** to see it.
23
 * **Note**: Even sponsored subscriptions require a credit card, make sure you have one available.
24
25 22 Jon Goldberg
### Grant access to other users
26
Microsoft is now enforcing two-factor authentication, so you need to create a separate user for me as your web vendor.
27
[Source](https://docs.microsoft.com/en-us/azure/cost-management-billing/manage/add-change-subscription-administrator) for instructions
28 26 Jon Goldberg
* Open the new subscription by clicking on it from the **Subscriptions** page.
29 22 Jon Goldberg
* Click **Access Control (IAM)** in the left navigation bar.
30
* Under *Grant access to this resource*, click **Add role assignments**.
31 25 Jon Goldberg
* On the *Role* tab, click **Owner** and press **Next**.
32
* On the *Members* tab, set *Assign Access* to **User, group, or service principal**, and click **Select Members**.
33
* In the *Search by name or email address* box, put the email of the new user and press **Save**.
34 22 Jon Goldberg
At this point, they'll receive an email to either log in with an existing Microsoft account or to create a new one.
35
36 16 Jon Goldberg
## Technical Configuration
37
To set up a free account, you must:
38
* Get a Sponsorship (see above)
39
* Create a Subscription linked to the Sponsorship (see above)
40
* (Strongly recommended) Grant access to the subscription to other users.
41
* Create a Resource Group linked to the Subscription
42
* Create a Virtual Machine (and associated resources) linked to the Resource Group
43 14 Jon Goldberg
44
### Create a resource group
45 6 Jon Goldberg
* Select "Resource Group" from the main Azure portal.  
46 28 Jon Goldberg
* Select **Create** and give it a name.
47 1 Jon Goldberg
* Your subscription should be pre-selected since you only have the one.
48 23 Jon Goldberg
* Click **Review and Create**, then **Create**.
49 6 Jon Goldberg
50 1 Jon Goldberg
### Create a virtual machine
51 14 Jon Goldberg
* Click on your new resource group in the Azure Portal.
52 29 Jon Goldberg
* Click **Create**.
53 30 Jon Goldberg
* Click **Create** under **Virtual MAchine**.
54 29 Jon Goldberg
* Search for the name of the image you want (e.g. `Debian 11 "Bullseye`).
55 23 Jon Goldberg
 * If you picked an image that shows an hourly cost, it's probably the wrong one.
56 31 Jon Goldberg
* See the screenshots below for configuration of the "Basics" and "Disk" tabs.  The other tabs I keep with the defaults.  My standard VPS type is now `D2as_v5`.
57
 * "D2" is general-purpose VM, we always select this.  "a" is AMD-series, "d" is temp disk included (we don't need this), "s" supports premium SSD disks.
58 9 Jon Goldberg
* I've attached a downloaded template for this VM, which as of now I haven't used yet, not sure how it works.
59
60
![Create a VM - Basics Tab](https://hq.megaphonetech.com/attachments/download/1771/Selection_999(010).png)
61
62 15 Jon Goldberg
![Create a VM - Disks Tab](Selection_1016.png)
63 6 Jon Goldberg
64 14 Jon Goldberg
### Post-provisioning configuration
65 10 Jon Goldberg
66 1 Jon Goldberg
#### Partition and format the attached disk
67 35 Jon Goldberg
Your VM (if it's D2s v3) will have an "OS disk" of 30GB it ships with.  Your attached disk is unformatted.  Partition and format the new disk:
68
* Use `fdisk -l` to determine the attached disk and change the first command below accordingly.
69 36 Jon Goldberg
70 18 Jon Goldberg
```shell
71 35 Jon Goldberg
DISK=/dev/sdb
72
sudo parted --script -a optimal $DISK mklabel gpt -- mkpart primary ext4 '0%' '100%'
73
sudo mkfs -t ext4 ${DISK}1
74 18 Jon Goldberg
```
75 17 Jon Goldberg
76 37 Jon Goldberg
#### Get serial console working
77
Serial console is necessary for single-user mode, and troubleshooting if SSH fails.
78
* Go to **Boot Diagnostics** in the VM's left nav.
79
* Click **Settings** at the top.
80
* Select **Enable with custom storage account**.
81
* Select **Create New**.
82
* Come up with a name.  Any name.
83
* Save with your custom boot selected.
84
85
Now Serial Console will work.
86
87 21 Jon Goldberg
#### Mount the attached disk
88 37 Jon Goldberg
Logging in with SSH:
89 1 Jon Goldberg
```shell
90 37 Jon Goldberg
91
From within *Serial Console*:
92
```shell
93
DISK=/dev/sdb
94 1 Jon Goldberg
# install lsof and rsync
95 37 Jon Goldberg
apt install lsof rsync
96
# Go to single-user mode
97
init 1
98 1 Jon Goldberg
# Ensure that no files are open in /var.
99
# This should come back empty. (Note that recently it hasn't been but seems to work anyway).
100 37 Jon Goldberg
lsof | grep /var
101
# pkill anything that's running, e.g. `pkill hv_kvp_daemon`.  It's OK if `systemd-journal` has files open.
102 1 Jon Goldberg
103 37 Jon Goldberg
mount ${DISK}1 /mnt
104
rsync -va /var/* /mnt
105
mv /var /var.old
106
umount /mnt
107
mkdir /var
108
mount ${DISK}1 /var
109
110
# Get the UUID of the drive for fstab
111
112
vi /etc/fstab
113 14 Jon Goldberg
```
114 37 Jon Goldberg
Add the following line to `/etc/fstab`, subbing in *your* UUID:
115 6 Jon Goldberg
```
116 37 Jon Goldberg
UUID=13523269-c397-46a4-93b5-cb9f108489da       /var     ext4    defaults    0 1
117 6 Jon Goldberg
```
118
119 8 Jon Goldberg
#### Modify Firewall Rules
120
* Click on your new virtual machine in the Azure portal.
121 14 Jon Goldberg
* Click **Networking** in the side navigation.
122 6 Jon Goldberg
* You should see your firewall settings.  They should look like the screenshot below, except they'll be missing the two items circled.
123
* Add the "allow_ping" and "Port_5665" rules to the *Inbound Port Rules* as shown in the screenshot.
124
125
![Firewall Rules](https://hq.megaphonetech.com/attachments/download/1772/Selection_999(012).png)
126
127
#### Add a swapfile
128
[Complete instructions are here](https://support.microsoft.com/en-us/help/4010058/how-to-add-a-swap-file-in-linux-azure-virtual-machines) but in short, add this to `/etc/waagent.conf` for an 8GB swapfile:
129
130
```
131 27 Jon Goldberg
    ResourceDisk.Format=y
132
    ResourceDisk.EnableSwap=y
133
    ResourceDisk.SwapSizeMB=8192
134
```
135 1 Jon Goldberg
136
Then run `service walinuxagent restart`.
137
138
## Post-deployment management
139
### Adding a new disk
140
Add a disk by going to the virtual machine and clicking "Disk", not by "Add Resource".  Then used the `parted` and `mkfs` commands from above.  Don't forget to modify `/etc/fstab`!