当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 在 Windows Server RDS 主机上设置远程桌面耗尽模式

作者:精品下载站 日期:2024-12-14 23:02:48 浏览:14 分类:玩电脑

在 Windows Server RDS 主机上设置远程桌面耗尽模式


您可以使用RDS 耗尽模式来维护远程桌面服务场中的终端主机。如果为 RDS 服务器启用 Drain 模式,则可以阻止服务器接受新用户的 RDP 连接,并且当前 RD 连接将保持活动状态,直到用户因 RDS 会话超时手动或自动注销。然后,您将能够维护 Windows Server 主机,而无需中断 RDS 场操作(安装更新、更改服务器或应用程序设置、更新配置文件等)。

Windows Server 远程桌面服务上的耗尽模式是什么?

Drain Mode出现在Windows Server 2008中(终端服务服务器Drain模式)。当您将 RDS 主机置于耗尽模式时,它无法再接受新用户的连接。通常,当服务器管理员需要维护服务器(安装 Windows 更新、配置或更新应用程序)而不影响整个 RDS 场的可用性时,请使用该模式。 RDS主机可以工作在三种类型的Drain模式中:

  • 允许所有连接(默认模式)- RD 会话主机接受新连接;

  • 允许重新连接,但阻止新登录 - 允许用户重新连接到现有会话,但不允许新会话。如果重新启动服务器,用户将无法连接到它;

  • 允许重新连接,但在服务器重新启动之前阻止新的登录 - 此模式与前一种模式类似,但重新启动后,用户登录模式将重置为“允许所有连接”。

如何拒绝新用户登录 RD 会话服务器?

您可以通过 RDS 收集设置在 RDS 主机服务器上启用 Drain 模式。

  1. 打开服务器管理器->所有服务器->添加该场的所有RDS服务器;

  2. 在服务器管理器的左侧面板中选择远程桌面服务。选择RDS集合;

  3. 在里面

    HOST SERVERS

    部分,选择要为其启用耗尽模式的服务器,然后在上下文菜单中选择不允许新连接

[玩转系统] 在 Windows Server RDS 主机上设置远程桌面耗尽模式

具有活动远程桌面会话的用户将能够重新连接到服务器,而所有新连接将由 RD 连接代理转发到 RDS 场中的其他主机。

您还可以通过命令提示符在 RDS 主机上本地设置 Drain 模式。为了做到这一点,

change logon

使用命令。

[玩转系统] 在 Windows Server RDS 主机上设置远程桌面耗尽模式

要阻止新用户连接,请运行以下命令:

change logon /drain

[玩转系统] 在 Windows Server RDS 主机上设置远程桌面耗尽模式

New user logons are DISABLED, but reconnections to existing sessions are ENABLED

现在,如果新用户尝试直接连接到 RDS 主机(未使用 RD 连接代理时),则会出现以下错误:

Remote logins are currently disabled.

[玩转系统] 在 Windows Server RDS 主机上设置远程桌面耗尽模式

A logon request was denied because the RD Session Host server is currently in drain mode and therefore not accepting new user logons. To configure the server to allow new user logons, use the Remote Desktop Services Configuration tool.

以下命令启用 Drain 模式,直到主机重新启动:

change logon /drainuntilrestart

要阻止用户(即使有活动会话)连接到主机,请运行以下命令:

change logon /disable
Session logins are currently DISABLED

如果您以客户端会话模式连接到远程桌面会话主机,并使用上述命令禁用访问并注销 (logoff.exe),则您将只能通过控制台连接到服务器(

mstsc /admin

)。

要允许连接,请使用以下命令:

change logon /enable

要确保 RDS 服务器上是否启用了 Drain 模式,请运行以下命令:

change logon /query
Session logins are currently ENABLED

[玩转系统] 在 Windows Server RDS 主机上设置远程桌面耗尽模式

Connections are currently ENABLED by Group Policy for this machine, unable to change.

[玩转系统] 在 Windows Server RDS 主机上设置远程桌面耗尽模式

这意味着排水模式是通过 GPO 配置的。该策略设置称为允许用户使用远程桌面服务进行远程连接,您可以在以下 GPO 部分中找到它:管理模板 -> Windows 组件 -> 远程桌面服务 -> 远程桌面会话主机 -> 连接。

[玩转系统] 在 Windows Server RDS 主机上设置远程桌面耗尽模式

禁用该策略或将其设置为未配置

通过 PowerShell 设置 Windows Server RDS 主机的耗尽模式

您可以使用 PowerShell 管理 RDS 主机集合或独立 RDS 服务器的耗尽模式设置:

Import-Module RemoteDesktop
# To deny new RDP connections to the Remote Desktop Services Host
Set-RDSessionHost -SessionHost mun-saprdsh1.a-d.site -NewConnectionAllowed No -ConnectionBroker mun-saprdcb.a-d.site
# To allow connections
Set-RDSessionHost -SessionHost mun-saprdsh1.a-d.site -NewConnectionAllowed Yes -ConnectionBroker mun-saprdcb.a-d.site

如果启用或禁用漏极模式,以下寄存器参数的值将会更改:

  • WinStationsDisabled HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\

  • TSServerDrainMode HKLM\System\CurrentControlSet\Control\Terminal Server\

[玩转系统] 在 Windows Server RDS 主机上设置远程桌面耗尽模式

例如,当启用排水模式时,注册表值设置为

WinStationsDisabled = 0

TSServerDrainMode = 2

您还可以使用下面的 PowerShell 脚本确保主机上的 Drain 模式是否已启用:

Get-WmiObject win32_terminalservicesetting -N "root\cimv2\terminalservices" | %{
if ($_.logons -eq 1){
"Disabled"}
Else {
switch ($_.sessionbrokerdrainmode)
{
0 {"Enabled"}
1 {"DrainUntilRestart"}
2 {"Drain"}
default {"error"}
}
}
}

通过 PowerShell 启用 Drain 模式(类似于

change logon /Drain

):

$temp = (Get-WmiObject win32_terminalservicesetting -N "root\cimv2\terminalservices")
$temp.sessionbrokerdrainmode=2
$temp.put()

将 RDS 主机置于正常模式 (

change logon /enable

),运行此命令:

$temp = (Get-WmiObject win32_terminalservicesetting -N " root\cimv2\terminalservices ")
$temp.sessionbrokerdrainmode=0
$temp.logons=0
$temp.put()

[玩转系统] 在 Windows Server RDS 主机上设置远程桌面耗尽模式

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯