ติดตั้ง Active Directory Domain Services บน Windows Server
Active Directory คือระบบจัดการผู้ใช้และเครื่องแบบรวมศูนย์ของ Windows เมื่อองค์กรมีเครื่องเกินสิบเครื่อง การจัดการบัญชีผู้ใช้แยกทีละเครื่องจะเริ่มควบคุมไม่ได้ ทั้งเรื่องรหัสผ่านที่ไม่ตรงกัน และพนักงานที่ลาออกแล้วแต่บัญชีบางเครื่องยังอยู่
คู่มือนี้ติดตั้ง Domain Controller เครื่องแรกสำหรับโดเมนใหม่ ใช้ได้กับ Windows Server 2019, 2022 และ 2025 โดยทำผ่าน Server Manager และให้คำสั่ง PowerShell คู่กันไปด้วย
สิ่งที่ต้องเตรียม
- Windows Server ที่ติดตั้งเสร็จแล้วและอัปเดตล่าสุด
- หน่วยความจำอย่างน้อย 4 GB และพื้นที่ดิสก์ว่าง 40 GB ขึ้นไป
- ชื่อโดเมนภายในที่วางแผนไว้ เช่น
corp.example.com - สิทธิ์ Administrator บนเครื่อง
คำแนะนำเรื่องการตั้งชื่อโดเมน อย่าใช้ชื่อเดียวกับโดเมนเว็บไซต์จริงของคุณ เช่น example.com เพราะจะทำให้เครื่องในโดเมนหาเว็บไซต์ภายนอกของบริษัทเองไม่เจอ ให้ใช้ซับโดเมนแทน เช่น corp.example.com หรือ ad.example.com และอย่าใช้ .local เพราะชนกับโพรโทคอล mDNS
ขั้นตอนที่ 1: ตั้ง IP แบบคงที่
Domain Controller ต้องมี IP ที่ไม่เปลี่ยน เพราะเครื่องลูกใช้มันเป็น DNS Server
Get-NetAdapter
New-NetIPAddress -InterfaceAlias "Ethernet" -IPAddress 10.0.0.10 `
-PrefixLength 24 -DefaultGateway 10.0.0.1
Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses 127.0.0.1
ตั้ง DNS ของตัวเองชี้มาที่ 127.0.0.1 เพราะเครื่องนี้จะกลายเป็น DNS Server เองหลังติดตั้งเสร็จ
ขั้นตอนที่ 2: เปลี่ยนชื่อเครื่อง
ต้องทำก่อนยกระดับเป็น Domain Controller เพราะเปลี่ยนชื่อทีหลังยุ่งยากมาก
Rename-Computer -NewName "DC01" -Restart
รอเครื่องรีสตาร์ตแล้วเข้าระบบใหม่
ขั้นตอนที่ 3: ติดตั้ง Role
ผ่าน Server Manager เลือก Manage แล้ว Add Roles and Features เลือก Active Directory Domain Services หรือใช้ PowerShell ซึ่งเร็วกว่ามาก
Install-WindowsFeature -Name AD-Domain-Services -IncludeManagementTools
Get-WindowsFeature -Name AD-Domain-Services
ขั้นตอนที่ 4: ยกระดับเป็น Domain Controller
Import-Module ADDSDeployment
Install-ADDSForest `
-DomainName "corp.example.com" `
-DomainNetbiosName "CORP" `
-ForestMode "WinThreshold" `
-DomainMode "WinThreshold" `
-InstallDns:$true `
-DatabasePath "C:\Windows\NTDS" `
-LogPath "C:\Windows\NTDS" `
-SysvolPath "C:\Windows\SYSVOL" `
-NoRebootOnCompletion:$false `
-Force:$true
ระบบจะถามรหัสผ่านสำหรับ Directory Services Restore Mode ซึ่งใช้กู้ระบบเมื่อ Active Directory เสียหาย เก็บรหัสนี้ไว้ในที่ปลอดภัยนอกเครื่อง เพราะจะต้องใช้ในวันที่แย่ที่สุดเท่านั้น
เครื่องจะรีสตาร์ตเอง เมื่อกลับมาให้เข้าระบบด้วย CORP\Administrator
ขั้นตอนที่ 5: ตรวจว่าติดตั้งสำเร็จ
Get-ADDomain
Get-ADForest
Get-ADDomainController
# ตรวจสุขภาพแบบละเอียด
dcdiag /v
nltest /dsgetdc:corp.example.com
ตรวจว่า DNS สร้างระเบียนที่จำเป็นครบ
Get-DnsServerZone
Resolve-DnsName -Name "_ldap._tcp.dc._msdcs.corp.example.com" -Type SRV
ระเบียน SRV เหล่านี้คือสิ่งที่เครื่องลูกใช้ค้นหา Domain Controller หากไม่มี เครื่องลูกจะเข้าโดเมนไม่ได้
ขั้นตอนที่ 6: สร้างโครงสร้าง OU
อย่าวางผู้ใช้ทั้งหมดไว้ใน Users ตามค่าเริ่มต้น เพราะจะใช้ Group Policy กับเฉพาะบางกลุ่มไม่ได้
New-ADOrganizationalUnit -Name "TDC" -Path "DC=corp,DC=example,DC=com"
New-ADOrganizationalUnit -Name "Users" -Path "OU=TDC,DC=corp,DC=example,DC=com"
New-ADOrganizationalUnit -Name "Computers" -Path "OU=TDC,DC=corp,DC=example,DC=com"
New-ADOrganizationalUnit -Name "Servers" -Path "OU=TDC,DC=corp,DC=example,DC=com"
New-ADOrganizationalUnit -Name "Groups" -Path "OU=TDC,DC=corp,DC=example,DC=com"
Get-ADOrganizationalUnit -Filter * | Select-Object Name, DistinguishedName
ขั้นตอนที่ 7: สร้างผู้ใช้และกลุ่ม
$pw = Read-Host -AsSecureString -Prompt "รหัสผ่านเริ่มต้น"
New-ADUser -Name "Somchai Jaidee" `
-GivenName "Somchai" -Surname "Jaidee" `
-SamAccountName "somchai" `
-UserPrincipalName "[email protected]" `
-Path "OU=Users,OU=TDC,DC=corp,DC=example,DC=com" `
-AccountPassword $pw `
-ChangePasswordAtLogon $true `
-Enabled $true
New-ADGroup -Name "Finance" -GroupScope Global `
-Path "OU=Groups,OU=TDC,DC=corp,DC=example,DC=com"
Add-ADGroupMember -Identity "Finance" -Members "somchai"
Get-ADGroupMember -Identity "Finance" | Select-Object Name
สร้างผู้ใช้จำนวนมากจากไฟล์ CSV
Import-Csv users.csv | ForEach-Object {
New-ADUser -Name $_.Name -SamAccountName $_.Username `
-UserPrincipalName "$($_.Username)@corp.example.com" `
-Path "OU=Users,OU=TDC,DC=corp,DC=example,DC=com" `
-AccountPassword (ConvertTo-SecureString $_.Password -AsPlainText -Force) `
-ChangePasswordAtLogon $true -Enabled $true
}
ขั้นตอนที่ 8: นำเครื่องลูกเข้าโดเมน
ที่เครื่องลูก ตั้ง DNS ให้ชี้มาที่ Domain Controller ก่อน ขั้นตอนนี้สำคัญที่สุดและเป็นสาเหตุที่คนเข้าโดเมนไม่ได้
Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses 10.0.0.10
Resolve-DnsName corp.example.com
Add-Computer -DomainName "corp.example.com" `
-OUPath "OU=Computers,OU=TDC,DC=corp,DC=example,DC=com" `
-Credential (Get-Credential CORP\Administrator) -Restart
ขั้นตอนที่ 9: เพิ่ม Domain Controller เครื่องที่สอง
Domain Controller เพียงเครื่องเดียวคือจุดตายของทั้งระบบ เมื่อเครื่องนี้ล่ม ทุกคนล็อกอินไม่ได้ ควรมีเครื่องที่สองเสมอ
# บนเครื่องที่สอง หลังตั้ง DNS ชี้ไป DC01 แล้ว
Install-WindowsFeature -Name AD-Domain-Services -IncludeManagementTools
Install-ADDSDomainController `
-DomainName "corp.example.com" `
-InstallDns:$true `
-Credential (Get-Credential CORP\Administrator) `
-Force:$true
หลังเสร็จ ให้แก้ DNS ของทั้งสองเครื่องให้ชี้หากันไขว้กัน โดยแต่ละเครื่องใช้ IP ของอีกเครื่องเป็น DNS ตัวแรก และ 127.0.0.1 เป็นตัวที่สอง
ปัญหาที่พบบ่อย
เครื่องลูกเข้าโดเมนไม่ได้ ขึ้นว่าหาโดเมนไม่พบ
เกือบทุกครั้งเป็นเรื่อง DNS ตรวจที่เครื่องลูกว่า DNS ชี้ไปที่ Domain Controller ไม่ใช่ 8.8.8.8 ด้วย ipconfig /all แล้วทดสอบด้วย nslookup corp.example.com
เวลาไม่ตรงกันจนล็อกอินไม่ได้
Kerberos ยอมให้เวลาต่างกันได้ไม่เกิน 5 นาที ตรวจด้วย w32tm /query /status และบังคับซิงก์ด้วย w32tm /resync บน Domain Controller ควรตั้งให้ซิงก์กับ NTP ภายนอก
w32tm /config /manualpeerlist:"time.navy.mi.th,0x8" /syncfromflags:manual /reliable:yes /update
Restart-Service w32time
dcdiag แจ้งข้อผิดพลาดเรื่อง SYSVOL
ตรวจว่าแชร์ SYSVOL และ NETLOGON ถูกสร้างแล้วด้วย net share หากไม่มี มักเป็นปัญหาการจำลองข้อมูล ให้ดู Event Log ใน Directory Service และ DFS Replication
ตั้งชื่อโดเมนผิดแล้วอยากแก้
การเปลี่ยนชื่อโดเมนทำได้แต่ซับซ้อนและเสี่ยงมาก หากยังไม่มีข้อมูลสำคัญ ให้ถอนการติดตั้งแล้วเริ่มใหม่จะเร็วกว่า ด้วย Uninstall-ADDSDomainController -ForceRemoval
ต้องการวางระบบ Active Directory พร้อม DR Site ที่มีทีมวิศวกรดูแล ติดต่อ THAI DATA CLOUD ได้ที่ https://thaidata.cloud/contact/
- Categories:
- Cloud
- Tags:
- Cloud
- Cloud Server
หมวดหมู่ที่น่าสนใจ
- Account Settings
- AD Server
- AI
- Alibaba Cloud
- Anti-Spam Gateway
- AWS Amazon Web Services
- Campaign
- CentOS/AlmaLinux
- Cloud
- Cloud Backup
- Cloud Communication
- Cloud Migration
- Cloud Security
- Cloud Server Management
- Cloud Solution
- Cloud Solution for Government
- Cloud Solutions by Industry
- Cloud Storage
- Cloud VPS App Plus +
- Cloud VPS DirectAdmin
- Cloud VPS Plesk
- CSR
- Cyber Security
- Cybersecurity
- Data Sovereignty
- Database Server
- DDoS
- Digital Tranformation
- Digital Transformation
- Direct Mail
- Directadmin
- Domainname
- Ecommerce
- ERP
- Generative AI
- Getting Started
- Google Cloud
- Google G Suite
- Huawei Cloud
- IT News
- Linux Server
- Managed Cloud Services
- Managed Service Provider
- Manual
- Microsoft
- Microsoft 365
- Microsoft Azure
- News
- On-premise
- Private Mail Server
- Promotion
- Recommend Solution (Enterprise)
- Server
- Sovereign Cloud
- THAI DATA CLOUD Platform
- Ubuntu
- Ubuntu
- Uncategorized
- VMware
- VPS Server
- Web Design
- Web Hosting
- Web Hosting (DirectAdmin)
- Web Hosting (Plesk)
- Web Technologies
- Windows Server
- Wordpress
- Zimbra
- เรื่องราวความประทับใจ
- โซลูชันสำหรับธุรกิจการผลิตและยานยนต์
- โซลูชันสำหรับธุรกิจการศึกษา
- โซลูชันสำหรับธุรกิจการเงิน
- โซลูชันสำหรับธุรกิจขนส่งและกระจายสินค้า
- โซลูชันสำหรับธุรกิจค้าปลีก
- โซลูชันสำหรับธุรกิจท่องเที่ยว
- โซลูชันสำหรับธุรกิจบริการสุขภาพและโรงพยาบาล
- โซลูชันสำหรับธุรกิจประกันภัย
- โซลูชันสำหรับธุรกิจพลังงานและสาธารณูปโภค
- โซลูชันสำหรับธุรกิจสื่อสารมวลชนและเอ็นเตอร์เทนเมนท์
- โซลูชันสำหรับธุรกิจอสังหาริมทรัพย์
- โซลูชันสำหรับธุรกิจเทคโนโลยี








