在 Windows Server 2019 Server Core 模式下,由于没有图形化界面(GUI),无法使用“服务器管理器”来安装角色和功能。但你可以通过 PowerShell 或 命令行工具(如 DISM) 来安装所需的角色和功能。
最常用且推荐的方法是使用 PowerShell 的 Install-WindowsFeature 命令。
✅ 方法一:使用 PowerShell 安装角色和功能
1. 查看可用的角色和功能
Get-WindowsFeature
这会列出所有可用的角色、角色服务和功能,已安装的会标记为 [X]。
2. 安装某个角色或功能
语法:
Install-WindowsFeature -Name <功能名称>
示例 1:安装 Web 服务器(IIS)
Install-WindowsFeature -Name Web-Server -IncludeManagementTools
Web-Server是 IIS 的主角色。-IncludeManagementTools会自动包含远程管理所需的工具(即使 Server Core 没有 GUI,某些管理工具仍可命令行使用)。
示例 2:安装文件服务器
Install-WindowsFeature -Name File-Services -IncludeManagementTools
示例 3:安装 .NET Framework 3.5(有时需要指定源)
Install-WindowsFeature -Name NET-Framework-Core -Source D:sourcessxs
⚠️ 注意:
.NET 3.5需要安装源文件(通常在 Windows Server 安装光盘的sxs文件夹中)。如果未指定-Source,可能会失败。
示例 4:同时安装多个角色
Install-WindowsFeature Web-Server, DHCP, DNS -IncludeManagementTools
✅ 方法二:使用 DISM 命令(适用于部分功能)
DISM 主要用于离线镜像或底层系统功能,但在 Server Core 上也可以用来启用某些功能。
例如安装 .NET 3.5:
dism /online /enable-feature /featurename:NetFx3 /all /source:D:sourcessxs
注意:
/source指向安装介质中的sxs目录。
📌 常用角色名称参考表
| 功能 | 名称 |
|---|---|
| Web 服务器 (IIS) | Web-Server |
| 文件服务器 | File-Services |
| 打印服务器 | Print-Services |
| DNS 服务器 | DNS |
| DHCP 服务器 | DHCP |
| Active Directory 域服务 | AD-Domain-Services |
| .NET Framework 3.5 | NET-Framework-Core |
| 远程服务器管理工具 | RSAT-*(如 RSAT-AD-Tools) |
| PowerShell 7+(需手动下载) | 不在默认功能中,需单独安装 |
🔁 安装后重启(如需要)
某些角色(如 AD DS、Failover Clustering)安装后需要重启:
Restart-Computer
或者延迟重启:
Restart-Computer -Force
🛠 提示与技巧
-
查看已安装的功能:
Get-WindowsFeature | Where-Object Installed -eq $true -
卸载功能:
Uninstall-WindowsFeature -Name Web-Server -
远程管理建议:
- 安装完角色后,建议使用 Windows Admin Center 或从另一台电脑使用 RSAT 工具进行管理。
-
确保网络和权限正常:
- 使用管理员权限运行 PowerShell。
- 确保服务器可以访问安装源(尤其是
.NET 3.5)。
总结
在 Windows Server 2019 Server Core 中安装角色和功能的最佳方式是:
✅ 使用 PowerShell 的 Install-WindowsFeature 命令,并根据需要添加 -IncludeManagementTools 和 -Source 参数。
这样可以在无 GUI 环境下高效、可靠地配置服务器。
如有具体想安装的角色(如域控制器、IIS、故障转移群集等),欢迎提供,我可以给出详细命令。
云小栈