Windows 域控服务器部署与配置
适用读者:企业 IT 管理员、系统工程师 目标:从零开始部署 Windows Server Active Directory 域控制器,配置域策略、用户管理、组织单元结构。
1. Active Directory 概述
1.1 什么是 Active Directory
Active Directory (AD) 是 Microsoft 的目录服务,用于: - 集中管理:统一管理用户、计算机、组、权限 - 身份认证:单点登录(SSO) - 组策略:集中配置和管理客户端 - 资源访问:控制文件、打印机、应用的访问权限
1.2 核心概念
| 概念 | 说明 | 示例 |
|---|---|---|
| 域(Domain) | 管理边界,共享同一个 AD 数据库 | pharma.local |
| 域控制器(DC) | 运行 AD 服务的服务器 | DC01.pharma.local |
| 组织单元(OU) | 容器,用于组织对象 | OU=Users,OU=Shanghai,DC=pharma,DC=local |
| 用户(User) | 用户账号 | john.doe@pharma.local |
| 组(Group) | 用户集合,用于权限管理 | GG_IT_Admins |
| 组策略(GPO) | 配置策略,应用到用户或计算机 | Desktop Wallpaper Policy |
| 林(Forest) | 多个域的集合 | pharma.local + research.pharma.local |
1.3 域控架构
┌─────────────────────────────────────────────────┐
│ pharma.local 域 │
│ │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ DC01 │◄──────►│ DC02 │ │
│ │ (主域控) │ 复制 │ (备域控) │ │
│ │ 上海机房 │ │ 北京机房 │ │
│ └──────────────┘ └──────────────┘ │
│ │ │ │
│ └────────────┬───────────┘ │
│ │ │
│ ┌────────────▼───────────┐ │
│ │ 客户端计算机 │ │
│ │ (加入域) │ │
│ └─────────────────────────┘ │
└─────────────────────────────────────────────────┘
2. 环境准备
2.1 硬件要求
| 组件 | 最低配置 | 推荐配置(500 用户) |
|---|---|---|
| CPU | 2 核 | 4 核 |
| 内存 | 4GB | 16GB |
| 磁盘 | 60GB | 200GB(SSD) |
| 网络 | 1Gbps | 1Gbps(双网卡冗余) |
2.2 软件要求
- 操作系统:Windows Server 2022 Standard/Datacenter
- 许可证:Windows Server CAL(客户端访问许可证)
- 网络:固定 IP 地址、DNS 配置
2.3 网络规划
域控服务器:
- 主域控(DC01):10.10.40.10
- 备域控(DC02):10.10.40.11
- 子网掩码:255.255.255.0
- 网关:10.10.40.1
- DNS:127.0.0.1(指向自己)
域名:
- NetBIOS 名称:PHARMA
- 完全限定域名(FQDN):pharma.local
3. 安装主域控(DC01)
3.1 配置服务器基本信息
# 设置计算机名
Rename-Computer -NewName "DC01" -Restart
# 设置静态 IP
New-NetIPAddress -InterfaceAlias "Ethernet" -IPAddress 10.10.40.10 -PrefixLength 24 -DefaultGateway 10.10.40.1
# 设置 DNS(暂时指向公共 DNS,安装 AD 后改为 127.0.0.1)
Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses ("8.8.8.8","8.8.4.4")
# 禁用 IPv6(可选)
Disable-NetAdapterBinding -Name "Ethernet" -ComponentID ms_tcpip6
# 设置时区
Set-TimeZone -Id "China Standard Time"
3.2 安装 AD DS 角色
# 安装 Active Directory 域服务角色
Install-WindowsFeature -Name AD-Domain-Services -IncludeManagementTools
# 验证安装
Get-WindowsFeature -Name AD-Domain-Services
3.3 提升为域控制器
# 导入 AD DS 部署模块
Import-Module ADDSDeployment
# 创建新林和域
Install-ADDSForest `
-DomainName "pharma.local" `
-DomainNetbiosName "PHARMA" `
-ForestMode "WinThreshold" `
-DomainMode "WinThreshold" `
-InstallDns:$true `
-DatabasePath "C:\Windows\NTDS" `
-LogPath "C:\Windows\NTDS" `
-SysvolPath "C:\Windows\SYSVOL" `
-Force:$true
# 输入 DSRM(目录服务还原模式)密码
# 服务器将自动重启
参数说明:
- DomainName:域的 FQDN
- DomainNetbiosName:NetBIOS 名称(15 字符以内)
- ForestMode / DomainMode:功能级别(WinThreshold = Windows Server 2016)
- InstallDns:自动安装 DNS 服务器
- DatabasePath:AD 数据库路径
- SysvolPath:SYSVOL 共享路径
3.4 验证安装
# 重启后,以域管理员身份登录:PHARMA\Administrator
# 验证域控角色
Get-ADDomainController
# 输出示例:
# ComputerObjectDN : CN=DC01,OU=Domain Controllers,DC=pharma,DC=local
# DefaultPartition : DC=pharma,DC=local
# Domain : pharma.local
# Enabled : True
# Forest : pharma.local
# HostName : DC01.pharma.local
# IPv4Address : 10.10.40.10
# IsGlobalCatalog : True
# IsReadOnly : False
# OperatingSystem : Windows Server 2022 Standard
# 验证 DNS
nslookup pharma.local
# 应返回 10.10.40.10
# 验证 FSMO 角色(5 个操作主机角色)
netdom query fsmo
# 输出:
# Schema master DC01.pharma.local
# Domain naming master DC01.pharma.local
# PDC DC01.pharma.local
# RID pool manager DC01.pharma.local
# Infrastructure master DC01.pharma.local
3.5 配置 DNS 指向自己
# 将 DNS 指向自己(127.0.0.1)
Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses ("127.0.0.1","10.10.40.11")
# 10.10.40.11 是备域控(稍后部署)
4. 安装备域控(DC02)
4.1 配置服务器基本信息
# 设置计算机名
Rename-Computer -NewName "DC02" -Restart
# 设置静态 IP
New-NetIPAddress -InterfaceAlias "Ethernet" -IPAddress 10.10.40.11 -PrefixLength 24 -DefaultGateway 10.10.40.1
# 设置 DNS(指向主域控)
Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses ("10.10.40.10","127.0.0.1")
4.2 安装 AD DS 角色
Install-WindowsFeature -Name AD-Domain-Services -IncludeManagementTools
4.3 加入现有域并提升为域控
# 导入模块
Import-Module ADDSDeployment
# 加入现有域
Install-ADDSDomainController `
-DomainName "pharma.local" `
-InstallDns:$true `
-Credential (Get-Credential PHARMA\Administrator) `
-DatabasePath "C:\Windows\NTDS" `
-LogPath "C:\Windows\NTDS" `
-SysvolPath "C:\Windows\SYSVOL" `
-Force:$true
# 输入域管理员密码和 DSRM 密码
# 服务器将自动重启
4.4 验证复制
# 在 DC01 或 DC02 上执行
# 查看复制状态
repadmin /replsummary
# 输出示例:
# Replication Summary Start Time: 2025-11-11 16:00:00
# Beginning data collection for replication summary, this may take awhile:
# .....
# Source DSA largest delta fails/total %% error
# DC01 00m:15s 0 / 5 0
# DC02 00m:20s 0 / 5 0
# 查看复制伙伴
repadmin /showrepl
# 强制复制
repadmin /syncall /AdeP
5. 创建组织单元(OU)结构
5.1 OU 设计原则
推荐的 OU 结构(按地理位置 + 部门):
pharma.local
├── Domain Controllers(系统自动创建)
├── Shanghai(上海)
│ ├── Users(用户)
│ │ ├── IT
│ │ ├── RD(研发)
│ │ ├── QA(质量)
│ │ ├── Production(生产)
│ │ └── Admin(行政)
│ ├── Computers(计算机)
│ │ ├── Desktops
│ │ ├── Laptops
│ │ └── Servers
│ └── Groups(组)
├── Beijing(北京)
│ ├── Users
│ ├── Computers
│ └── Groups
└── Service Accounts(服务账号)
5.2 创建 OU
# 创建顶级 OU
New-ADOrganizationalUnit -Name "Shanghai" -Path "DC=pharma,DC=local"
New-ADOrganizationalUnit -Name "Beijing" -Path "DC=pharma,DC=local"
New-ADOrganizationalUnit -Name "Service Accounts" -Path "DC=pharma,DC=local"
# 创建上海子 OU
New-ADOrganizationalUnit -Name "Users" -Path "OU=Shanghai,DC=pharma,DC=local"
New-ADOrganizationalUnit -Name "Computers" -Path "OU=Shanghai,DC=pharma,DC=local"
New-ADOrganizationalUnit -Name "Groups" -Path "OU=Shanghai,DC=pharma,DC=local"
# 创建部门 OU
$departments = @("IT", "RD", "QA", "Production", "Admin")
foreach ($dept in $departments) {
New-ADOrganizationalUnit -Name $dept -Path "OU=Users,OU=Shanghai,DC=pharma,DC=local"
}
# 创建计算机类型 OU
$computerTypes = @("Desktops", "Laptops", "Servers")
foreach ($type in $computerTypes) {
New-ADOrganizationalUnit -Name $type -Path "OU=Computers,OU=Shanghai,DC=pharma,DC=local"
}
# 验证 OU 结构
Get-ADOrganizationalUnit -Filter * | Select-Object Name, DistinguishedName
6. 创建用户和组
6.1 创建用户
# 创建单个用户
New-ADUser `
-Name "John Doe" `
-GivenName "John" `
-Surname "Doe" `
-SamAccountName "john.doe" `
-UserPrincipalName "john.doe@pharma.local" `
-Path "OU=IT,OU=Users,OU=Shanghai,DC=pharma,DC=local" `
-AccountPassword (ConvertTo-SecureString "P@ssw0rd123!" -AsPlainText -Force) `
-Enabled $true `
-ChangePasswordAtLogon $true `
-EmailAddress "john.doe@pharma.com" `
-Title "IT Manager" `
-Department "IT" `
-Company "Pharma Corp" `
-OfficePhone "+86-21-12345678" `
-MobilePhone "+86-138-0000-0000"
# 批量创建用户(从 CSV)
# 准备 CSV 文件:users.csv
# FirstName,LastName,Username,Department,Title
# John,Doe,john.doe,IT,IT Manager
# Jane,Smith,jane.smith,RD,Scientist
$users = Import-Csv -Path "C:\users.csv"
foreach ($user in $users) {
$ouPath = "OU=$($user.Department),OU=Users,OU=Shanghai,DC=pharma,DC=local"
New-ADUser `
-Name "$($user.FirstName) $($user.LastName)" `
-GivenName $user.FirstName `
-Surname $user.LastName `
-SamAccountName $user.Username `
-UserPrincipalName "$($user.Username)@pharma.local" `
-Path $ouPath `
-AccountPassword (ConvertTo-SecureString "P@ssw0rd123!" -AsPlainText -Force) `
-Enabled $true `
-ChangePasswordAtLogon $true `
-Department $user.Department `
-Title $user.Title
}
6.2 创建组
# 创建全局安全组(用于权限管理)
New-ADGroup `
-Name "GG_IT_Admins" `
-GroupScope Global `
-GroupCategory Security `
-Path "OU=Groups,OU=Shanghai,DC=pharma,DC=local" `
-Description "IT Administrators"
New-ADGroup -Name "GG_FileServer_RD_Read" -GroupScope Global -GroupCategory Security -Path "OU=Groups,OU=Shanghai,DC=pharma,DC=local"
New-ADGroup -Name "GG_FileServer_RD_Write" -GroupScope Global -GroupCategory Security -Path "OU=Groups,OU=Shanghai,DC=pharma,DC=local"
New-ADGroup -Name "GG_LIMS_Users" -GroupScope Global -GroupCategory Security -Path "OU=Groups,OU=Shanghai,DC=pharma,DC=local"
New-ADGroup -Name "GG_VPN_Users" -GroupScope Global -GroupCategory Security -Path "OU=Groups,OU=Shanghai,DC=pharma,DC=local"
# 将用户添加到组
Add-ADGroupMember -Identity "GG_IT_Admins" -Members "john.doe"
Add-ADGroupMember -Identity "GG_VPN_Users" -Members "john.doe","jane.smith"
6.3 组命名规范
推荐命名规范:
- GG_:全局组(Global Group)
- DL_:域本地组(Domain Local Group)
- UG_:通用组(Universal Group)
示例:
- GG_IT_Admins:IT 管理员全局组
- DL_FileServer_RD_Read:研发文件夹只读权限(域本地组)
- GG_VPN_Users:VPN 用户全局组
权限分配模式(AGDLP):
1. 用户账号(Account)→ 全局组(Global Group)
2. 全局组 → 域本地组(Domain Local Group)
3. 域本地组 → 资源权限(Permission)
示例:
- john.doe → GG_RD_Staff → DL_FileServer_RD_Write → 研发文件夹(写权限)
7. 配置组策略(GPO)
7.1 创建 GPO
# 创建新的 GPO
New-GPO -Name "Desktop Wallpaper Policy" -Comment "Set company wallpaper"
# 链接 GPO 到 OU
New-GPLink -Name "Desktop Wallpaper Policy" -Target "OU=Users,OU=Shanghai,DC=pharma,DC=local"
# 查看 GPO
Get-GPO -All | Select-Object DisplayName, GpoStatus, CreationTime
7.2 常用 GPO 配置
7.2.1 密码策略
路径:Computer Configuration > Policies > Windows Settings > Security Settings > Account Policies > Password Policy
配置:
- Enforce password history: 24 passwords remembered
- Maximum password age: 90 days
- Minimum password age: 1 day
- Minimum password length: 12 characters
- Password must meet complexity requirements: Enabled
- Store passwords using reversible encryption: Disabled
# 使用 PowerShell 配置(需要在 DC 上执行)
Set-ADDefaultDomainPasswordPolicy `
-Identity pharma.local `
-ComplexityEnabled $true `
-MinPasswordLength 12 `
-MaxPasswordAge 90.00:00:00 `
-MinPasswordAge 1.00:00:00 `
-PasswordHistoryCount 24
7.2.2 账户锁定策略
路径:Computer Configuration > Policies > Windows Settings > Security Settings > Account Policies > Account Lockout Policy
配置:
- Account lockout duration: 30 minutes
- Account lockout threshold: 5 invalid logon attempts
- Reset account lockout counter after: 30 minutes
7.2.3 桌面壁纸
路径:User Configuration > Policies > Administrative Templates > Desktop > Desktop > Desktop Wallpaper
配置:
- Enabled
- Wallpaper Name: \\pharma.local\NETLOGON\wallpaper.jpg
- Wallpaper Style: Fill
7.2.4 禁用 USB 存储
路径:Computer Configuration > Policies > Administrative Templates > System > Removable Storage Access
配置:
- Removable Disks: Deny read access: Enabled
- Removable Disks: Deny write access: Enabled
7.2.5 软件部署
路径:Computer Configuration > Policies > Software Settings > Software installation
步骤:
1. 右键 > New > Package
2. 选择 MSI 文件(存放在网络共享)
3. 选择部署方式:Assigned(强制安装)或 Published(可选安装)
7.2.6 映射网络驱动器
路径:User Configuration > Preferences > Windows Settings > Drive Maps
配置:
- Action: Create
- Location: \\pharma.local\shares\department
- Drive Letter: H:
- Reconnect: Enabled
- Label as: Department Share
7.3 GPO 优先级
GPO 应用顺序(从低到高):
1. Local(本地策略)
2. Site(站点)
3. Domain(域)
4. OU(组织单元)
后应用的策略会覆盖先应用的策略。
示例:
- Domain GPO:密码长度 8 位
- OU GPO:密码长度 12 位
- 最终结果:12 位(OU 策略优先级更高)
强制(Enforced)和阻止继承(Block Inheritance):
- Enforced:强制应用,不被子 OU 覆盖
- Block Inheritance:阻止继承父 OU 的策略
7.4 刷新 GPO
# 在客户端强制刷新 GPO
gpupdate /force
# 查看应用的 GPO
gpresult /r
# 生成详细报告(HTML)
gpresult /h C:\gpo_report.html
8. 客户端加入域
8.1 配置客户端 DNS
在客户端计算机上:
1. 打开"网络和共享中心"
2. 更改适配器设置
3. 右键网卡 > 属性 > IPv4
4. 设置 DNS:
- 首选 DNS:10.10.40.10(主域控)
- 备用 DNS:10.10.40.11(备域控)
8.2 加入域(GUI)
1. 右键"此电脑" > 属性
2. 点击"更改设置"
3. 点击"更改"
4. 选择"域",输入:pharma.local
5. 点击"确定"
6. 输入域管理员账号:PHARMA\Administrator
7. 重启计算机
8.3 加入域(PowerShell)
# 在客户端执行
Add-Computer -DomainName "pharma.local" -Credential (Get-Credential PHARMA\Administrator) -Restart
# 或指定 OU
Add-Computer `
-DomainName "pharma.local" `
-OUPath "OU=Laptops,OU=Computers,OU=Shanghai,DC=pharma,DC=local" `
-Credential (Get-Credential PHARMA\Administrator) `
-Restart
8.4 验证加入域
# 查看计算机域信息
Get-ComputerInfo | Select-Object CsDomain, CsDomainRole
# 输出示例:
# CsDomain : pharma.local
# CsDomainRole : MemberWorkstation
# 测试域连接
Test-ComputerSecureChannel -Verbose
# 输出:True
9. 日常管理
9.1 重置用户密码
# 重置密码
Set-ADAccountPassword -Identity john.doe -Reset -NewPassword (ConvertTo-SecureString "NewP@ssw0rd!" -AsPlainText -Force)
# 要求下次登录时更改密码
Set-ADUser -Identity john.doe -ChangePasswordAtLogon $true
# 解锁账户
Unlock-ADAccount -Identity john.doe
9.2 禁用/启用用户
# 禁用用户
Disable-ADAccount -Identity john.doe
# 启用用户
Enable-ADAccount -Identity john.doe
# 查看禁用的用户
Search-ADAccount -AccountDisabled | Select-Object Name, SamAccountName
9.3 查询用户信息
# 查询单个用户
Get-ADUser -Identity john.doe -Properties *
# 查询所有用户
Get-ADUser -Filter * | Select-Object Name, SamAccountName, Enabled
# 查询特定部门的用户
Get-ADUser -Filter {Department -eq "IT"} | Select-Object Name, Title
# 查询最近 30 天未登录的用户
$date = (Get-Date).AddDays(-30)
Get-ADUser -Filter {LastLogonDate -lt $date} -Properties LastLogonDate | Select-Object Name, LastLogonDate
9.4 备份 AD
# 使用 Windows Server Backup 备份系统状态(包含 AD)
wbadmin start systemstatebackup -backupTarget:E: -quiet
# 或使用 PowerShell
Install-WindowsFeature Windows-Server-Backup
$policy = New-WBPolicy
$target = New-WBBackupTarget -VolumePath E:
Add-WBBackupTarget -Policy $policy -Target $target
Add-WBSystemState -Policy $policy
Start-WBBackup -Policy $policy
10. 监控与故障排查
10.1 监控 AD 健康状态
# 检查 AD 复制
repadmin /replsummary
# 检查 FSMO 角色
netdom query fsmo
# 检查 DNS
dcdiag /test:dns
# 全面诊断
dcdiag /v
# 检查 SYSVOL 复制
dfsrdiag replicationstate
10.2 常见问题
问题 1:客户端无法加入域
错误:找不到网络路径
排查步骤:
1. 检查客户端 DNS 是否指向域控
2. Ping 域名:ping pharma.local
3. 检查防火墙(端口 53, 88, 389, 445, 3268)
4. 检查时间同步(误差不能超过 5 分钟)
问题 2:GPO 未应用
排查步骤:
1. 在客户端运行:gpupdate /force
2. 检查 GPO 链接:Get-GPInheritance -Target "OU=Users,OU=Shanghai,DC=pharma,DC=local"
3. 检查 GPO 状态:Get-GPO -Name "Desktop Wallpaper Policy"
4. 查看事件日志:Event Viewer > Applications and Services Logs > Microsoft > Windows > GroupPolicy
问题 3:AD 复制失败
排查步骤:
1. 检查网络连接:ping DC02.pharma.local
2. 检查复制状态:repadmin /showrepl
3. 强制复制:repadmin /syncall /AdeP
4. 检查事件日志:Event Viewer > Directory Service
11. 最佳实践
- 至少部署 2 台域控:主备冗余
- 定期备份:每天备份系统状态
- 监控复制:确保 DC 之间正常复制
- OU 结构清晰:便于管理和应用 GPO
- 组命名规范:使用前缀(GG_、DL_)
- 最小权限原则:不要滥用 Domain Admins
- 定期审查权限:每季度审查用户和组
- 测试 GPO:先在测试 OU 测试,再推广
- 文档化:记录 OU 结构、GPO 配置
- 时间同步:确保所有服务器时间一致
参考资源: - Microsoft Active Directory 官方文档 - Windows Server 2022 管理指南 - Active Directory Best Practices