Windows Server云服务器装机必备

以往可以通过Microsoft Store安装的App

首先一个很大的区别是Server没有Microsoft Store,所以很多App只能通过命令行的形式来安装。

比如巨好用的Windows Terminal,以及很顺手的包管理器winget,甚至是Ubuntu 22.04.1 LTS

无脑攻略

VC++ v14 Desktop Framework Package

很多App都依赖VC++ v14 Desktop Framework Package,比如Windows Terminalwinget,所以第一步先安装它。

下载Microsoft.VCLibs.x64.14.00.Desktop.appx,然后使用命令行安装:

1
Add-AppxPackage Microsoft.VCLibs.x64.14.00.Desktop.appx

Dotnet

Dotnet运行时也算是装机必备了,一次到位我们直接安装SDK。目前的LTS版本是6.0,截止写这篇博客时的最新版是6.0.401

Visual Studio和Visual Studio Code

VSVS Code就不用多说了。

Microsoft.UI.Xaml

Microsoft.UI.Xaml是一个UI库,被很多App使用(比如winget)。

Microsoft.UI.Xaml是一个面向开发者的库,它并没有直接提供可安装的msixbundle,所以安装方式有一点不一样。

首先去nuget下载最新的稳定版nupkg文件,然后解压,再安装包里的bundle。

1
2
3
Rename-Item -Path "microsoft.ui.xaml.2.7.3.nupkg" -NewName "microsoft.ui.xaml.2.7.3.zip"
Expand-Archive "microsoft.ui.xaml.2.7.3.zip" -DestinationPath "./microsoft.ui.xaml"
Add-AppxPackage "microsoft.ui.xaml\tools\AppX\x64\Release\Microsoft.UI.Xaml.2.7.appx"

*winget,不支持Windows Server

Windows Terminal

截止本文更新时间,最新版本是Windows Terminal v1.15.252

Windows Terminal从第一个版本开始,最低支持Windows内部版本18362.0。在阿里云的Windows Server上只支持2022,其它版本都嫌弃版本低(阿里云的2019内部版本是17763.3287)。

以往我们可以在微软商店里安装Windows Terminal,现在只能去github项目的release页面下载msixbundle文件。

然后手动运行命令安装:

1
2
3
4
5
# NOTE: If you are using PowerShell 7+, please run
# Import-Module Appx -UseWindowsPowerShell
# before using Add-AppxPackage.

Add-AppxPackage Microsoft.WindowsTerminal_<versionNumber>.msixbundle

依赖

z-jump

z-dump的安装方法参照另一篇博文,Windows Server没有区别。

*wsl,云服务器不支持二次虚拟化

docker

为了实现资源最大化利用,云服务器都是使用虚拟化技术来资源池化的。普通的云服务器不支持二次虚拟化

所以docker在windows server云服务器上只能使用windows container,使用场景大幅受限,几近鸡肋。

不支持Docker Desktop

如果想在虚拟机中安装Docker Desktop,需要嵌套虚拟化(nested virtualization)。很可惜,云服务通常都不支持嵌套虚拟化。

不过我们可以抛开Docker Desktop,直接使用Docker Engine

打开container功能

首先要打开container功能,开启后需要重启才会生效。

1
2
Install-WindowsFeature -Name Containers
Restart-Computer -Force

不同版本的Windows Server对Windows Container的适配性可以在这里查看,简单来说,在阿里云上最佳系统是Windows Server2019。因为阿里云没有Hyper-V,在没有Hyper-V的情况下,宿主只适配本版本的容器。而当前docker hub上镜像文件比较充足的是2019。

但如果没有第三方镜像文件要求就还是建议2022,可以在服务器上直接用Edge和安装Windows Terminal,体验要好很多。

安装docker

添加DockerMsftProvider

1
Install-Module -Name DockerMsftProvider -Repository PSGallery -Force

如果是新环境,会提示安装Nuget,输入Y同意:

最后安装docker

1
Install-Package -Name docker -ProviderName DockerMsftProvider -Force

这一步会比较慢,主要是因为服务器在海外,需要多给点耐心,也许要重试几次。

安装完成后,C:\Program Files\Docker会被添加进系统Path变量,需要重启后才生效。
如果不想重启,我们可以把它添加到用户Path变量

1
2
3
$dockerPath = Split-Path (Get-Command docker).Source
$userPath = [Environment]::GetEnvironmentVariable("PATH", "User") + [IO.Path]::PathSeparator + $dockerPath
[Environment]::SetEnvironmentVariable("Path", $userPath, "User")

启动docker服务

如果Docker Engine服务没有自动启动,手动启动它。

1
Start-Service docker

验证docker

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
PS C:\Users\Administrator> docker run --rm hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
09629875cd6e: Pull complete
7838a6eb98a6: Pull complete
1c2e00cf48a3: Pull complete
Digest: sha256:62af9efd515a25f84961b70f973a798d2eca956b1b2b026d0a4a63a3b0b6a3f2
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(windows-amd64, nanoserver-ltsc2022)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run a Windows Server container with:
PS C:\> docker run -it mcr.microsoft.com/windows/servercore:ltsc2022 powershell

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/get-started/