คุณสามารถใช้ RDS Drain Mode เพื่อดูแลโฮสต์เทอร์มินัลในฟาร์ม Remote Desktop Services หากคุณเปิดใช้งาน Drain Mode สำหรับเซิร์ฟเวอร์ RDS คุณสามารถป้องกันไม่ให้เซิร์ฟเวอร์รับการเชื่อมต่อ RDP ใหม่จากผู้ใช้ ในขณะที่การเชื่อมต่อ RD ปัจจุบันจะยังคงทำงานจนกว่าผู้ใช้จะล็อกออฟด้วยตนเองหรือโดยอัตโนมัติจากการหมดเวลาที่กำหนดของเซสชัน RDS จากนั้นคุณจะสามารถดูแลโฮสต์ Windows Server ได้โดยไม่รบกวนการดำเนินงานของฟาร์ม RDS (ติดตั้งอัปเดต, เปลี่ยนการตั้งค่าเซิร์ฟเวอร์หรือแอป, อัปเดตไฟล์การกำหนดค่า ฯลฯ)
Drain Mode บน Windows Server Remote Desktop Services คืออะไร?
Drain Mode 登場ใน Windows Server 2008 (Terminal Services Server Drain mode) เมื่อคุณตั้งค่าโฮสต์ RDS ให้อยู่ใน Drain Mode เซิร์ฟเวอร์จะไม่สามารถรับการเชื่อมต่อใหม่ของผู้ใช้ได้ โดยทั่วไปโหมดนี้ใช้เมื่อผู้ดูแลเซิร์ฟเวอร์ต้องดูแลเซิร์ฟเวอร์ (ติดตั้ง Windows Updates, กำหนดค่าหรืออัปเดตแอป) โดยไม่ส่งผลต่อความพร้อมใช้งานของฟาร์ม RDS ทั้งหมด โฮสต์ RDS สามารถทำงานใน 3 ประเภทของ Drain Mode ได้:
- Allow All Connections (โหมดเริ่มต้น) — โฮสต์ RD Session Host ยอมรับการเชื่อมต่อใหม่;
- Allow Reconnections, but Prevent New Logons — อนุญาตให้ผู้ใช้เชื่อมต่อกลับไปยังเซสชันที่มีอยู่ แต่ไม่อนุญาตเซสชันใหม่ หากคุณรีสตาร์ทเซิร์ฟเวอร์ ผู้ใช้จะไม่สามารถเชื่อมต่อกับมันได้;
- Allow Reconnections, but Prevent New Logons until the Server Is Restarted – โหมดนี้คล้ายกับโหมดก่อนหน้า แต่หลังจากรีสตาร์ท โหมดการล็อกอินของผู้ใช้จะรีเซ็ตกลับเป็น Allow All Connections
วิธีปฏิเสธการล็อกอินผู้ใช้ใหม่ไปยัง RD Session Server
คุณสามารถเปิดใช้งาน Drain Mode บนโฮสต์เซิร์ฟเวอร์ RDS ผ่านการตั้งค่า RDS Collection
- เปิด Server Manager -> All Servers -> และเพิ่มเซิร์ฟเวอร์ RDS ทั้งหมดของฟาร์ม;
- เลือก Remote Desktop Services ด้านซ้ายใน Server Manager เลือก RDS Collections;
- ในส่วน
HOST SERVERSเลือกเซิร์ฟเวอร์ที่ต้องการเปิดใช้งาน Drain Mode และเลือก Do not allow new connections ในเมนูบริบท
ผู้ใช้ที่มีเซสชัน Remote Desktop ที่ใช้งานอยู่จะสามารถเชื่อมต่อกลับไปยังเซิร์ฟเวอร์ได้ ในขณะที่การเชื่อมต่อใหม่ทั้งหมดจะถูกส่งต่อโดย RD Connection Broker ไปยังโฮสต์อื่นในฟาร์ม RDS ของคุณ
คุณยังสามารถตั้งค่า Drain Mode ท้องถิ่นบนโฮสต์ RDS ผ่าน Command Prompt โดยใช้คำสั่ง change logon
คำสั่งหลักสำหรับ Drain Mode
- ป้องกันการเชื่อมต่อผู้ใช้ใหม่:
change logon /drain— New user logons are DISABLED, but reconnections to existing sessions are ENABLED - เปิดใช้งาน Drain Mode จนกว่าจะรีสตาร์ทโฮสต์:
change logon /drainuntilrestart - ป้องกันผู้ใช้ที่มีเซสชันใช้งานอยู่จากการเชื่อมต่อ:
change logon /disable— Session logins are currently DISABLED - อนุญาตการเชื่อมต่อ:
change logon /enable - ตรวจสอบสถานะ Drain Mode:
change logon /query
mstsc /admin)
การแก้ไขปัญหาเมื่อไม่สามารถเปลี่ยน Drain Mode ได้
หากคุณพยายามตั้งค่า Drain Mode โดยใช้ change logon และเห็นข้อผิดพลาด:
Connections are currently ENABLED by Group Policy for this machine, unable to change.
หมายความว่า Drain Mode ถูกกำหนดค่าผ่าน GPO การตั้งค่านโยบายเรียกว่า Allow users to connect remotely using Remote Desktop Services และคุณสามารถค้นหาได้ภายใต้ส่วน GPO ต่อไปนี้: Administrative Templates -> Windows Components -> Remote Desktop Services -> Remote Desktop Session Host -> Connections
ปิดใช้งานนโยบายหรือตั้งค่าเป็น Not Configured
ตั้งค่า Drain Mode สำหรับ Windows Server RDS Host ผ่าน PowerShell
คุณสามารถจัดการการตั้งค่า Drain Mode ของคอลเลกชันโฮสต์ RDS หรือเซิร์ฟเวอร์ RDS แบบสแตนด์อโลนโดยใช้ PowerShell:
Import-Module RemoteDesktop
# ปฏิเสธการเชื่อมต่อ RDP ใหม่ไปยัง Remote Desktop Services Host
Set-RDSessionHost -SessionHost mun-saprdsh1.woshub.com -NewConnectionAllowed No -ConnectionBroker mun-saprdcb.woshub.com
# อนุญาตการเชื่อมต่อ
Set-RDSessionHost -SessionHost mun-saprdsh1.woshub.com -NewConnectionAllowed Yes -ConnectionBroker mun-saprdcb.woshub.com
เมื่อคุณเปิดหรือปิดใช้งาน Drain Mode ค่าของพารามิเตอร์รีจิสทรีต่อไปนี้จะเปลี่ยนแปลง:
- WinStationsDisabled HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\
- TSServerDrainMode HKLM\System\CurrentControlSet\Control\Terminal Server\
ตัวอย่างเช่น เมื่อเปิดใช้งาน Drain Mode ค่ารีจิสทรีจะถูกตั้งเป็น WinStationsDisabled = 0 และ TSServerDrainMode = 2
ตรวจสอบสถานะ Drain Mode ด้วย PowerShell
Get-WmiObject win32_terminalservicesetting -N "root\cimv2\terminalservices" | %{
if ($_.logons -eq 1){
"Disabled"}
Else {
switch ($_.sessionbrokerdrainmode)
{
0 {"Enabled"}
1 {"DrainUntilRestart"}
2 {"Drain"}
default {"error"}
}
}
}
เปิดใช้งาน Drain Mode ผ่าน PowerShell (เหมือน 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()