Files
dhcp-dns-manager/WINDOWS_GUIDE.md
T
CNBUGS AI 8ad4c3576d Fix DHCP client unable to get IP and config not persisting
- Fixed verifyAssignment being too strict for new clients
- Fixed parseRequestedIP string conversion bug
- Fixed response sent to 0.0.0.0 instead of broadcast address
- Added SO_BROADCAST support for UDP socket
- Fixed session persistence after page refresh (localStorage)
- Added in-memory session store for auth middleware
- Added config reloader so DHCP server picks up web UI changes dynamically
2026-04-24 16:03:54 +08:00

320 lines
5.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Windows 部署指南
本指南介绍如何在 Windows 系统上部署 DHCP & DNS 管理器。
---
## 方案一:使用 Docker Desktop(推荐)⭐
### 1. 安装 Docker Desktop
下载地址:https://www.docker.com/products/docker-desktop
安装完成后启动 Docker Desktop。
### 2. 准备项目文件
```powershell
# 创建目录
mkdir C:\dhcp-dns-manager
cd C:\dhcp-dns-manager
# 复制项目文件到此目录
# 确保包含:docker-compose.yml, configs/, web/ 等
```
### 3. 启动服务
双击运行 `start.bat` 或在 PowerShell 中执行:
```powershell
docker-compose up -d
```
### 4. 访问界面
浏览器打开:http://localhost:8080
---
## 方案二:本地运行(需要 Go 环境)
### 1. 安装 Go
下载:https://golang.org/dl/
选择 `go1.21.0.windows-amd64.msi` 安装。
验证安装:
```powershell
go version
```
### 2. 下载项目
```powershell
# 方式一:Git 克隆
git clone <your-repo-url>
cd dhcp-dns-manager
# 方式二:下载 ZIP 解压
```
### 3. 编译程序
```powershell
# 下载依赖
go mod download
# 编译
go build -o dhcp-dns-manager.exe ./cmd
# 或使用启动脚本
.\start.bat
```
### 4. 以 Windows 服务运行(可选)
使用 NSSMNon-Sucking Service Manager):
#### 下载 NSSM
https://nssm.cc/download
#### 安装服务
```powershell
# 以管理员身份打开 PowerShell
cd C:\path\to\nssm\win64
# 安装服务
.\nssm.exe install dhcp-dns-manager
# 在弹出的配置窗口中:
# - Path: C:\dhcp-dns-manager\dhcp-dns-manager.exe
# - Startup directory: C:\dhcp-dns-manager
# - Arguments: -config configs\config.json
```
#### 管理服务
```powershell
# 启动服务
net start dhcp-dns-manager
# 停止服务
net stop dhcp-dns-manager
# 查看状态
sc query dhcp-dns-manager
```
---
## 方案三:WSL2Windows Subsystem for Linux
### 1. 安装 WSL2
```powershell
# 以管理员身份运行 PowerShell
wsl --install
```
重启电脑后,WSL2 会自动安装 Ubuntu。
### 2. 在 WSL2 中部署
```bash
# 进入 WSL2
wsl
# 按照 Linux 部署指南操作
cd ~
git clone <your-repo>
cd dhcp-dns-manager
sudo ./install.sh
```
### 3. 访问服务
从 Windows 浏览器访问:
```
http://localhost:8080
```
---
## Windows 防火墙配置
如果启用了 Windows 防火墙,需要开放端口:
### PowerShell(管理员)
```powershell
# DNS (UDP 53)
New-NetFirewallRule -DisplayName "DHCP-DNS-Manager DNS" -Direction Inbound -Protocol UDP -LocalPort 53 -Action Allow
# DHCP (UDP 67)
New-NetFirewallRule -DisplayName "DHCP-DNS-Manager DHCP" -Direction Inbound -Protocol UDP -LocalPort 67 -Action Allow
# Web UI (TCP 8080)
New-NetFirewallRule -DisplayName "DHCP-DNS-Manager Web" -Direction Inbound -Protocol TCP -LocalPort 8080 -Action Allow
```
### 或使用图形界面
1. 打开"Windows Defender 防火墙"
2. 点击"高级设置"
3. 入站规则 → 新建规则
4. 端口 → TCP/UDP → 53, 67, 8080
5. 允许连接
---
## 常见问题
### Q: 端口被占用?
**检查占用端口的进程:**
```powershell
# 查看 8080 端口
netstat -ano | findstr :8080
# 查看 53 端口
netstat -ano | findstr :53
```
**解决方案:**
1. 修改 `configs\config.json` 中的端口
2. 或停止占用端口的服务
### Q: Docker 启动失败?
**检查 Docker 状态:**
```powershell
docker version
docker-compose version
```
**重启 Docker Desktop**
**检查端口冲突:**
```powershell
netstat -ano | findstr :53
netstat -ano | findstr :67
netstat -ano | findstr :8080
```
### Q: 权限不足?
**以管理员身份运行:**
- 右键点击 `start.bat`
- 选择"以管理员身份运行"
### Q: 数据库在哪里?
Windows 路径:
```
C:\dhcp-dns-manager\data\dhcp-dns.db
```
**备份数据库:**
```powershell
Copy-Item data\dhcp-dns.db data\dhcp-dns.db.backup
```
---
## 开机自启
### Docker 方式
Docker Desktop 会自动启动容器(需启用 Docker Desktop 开机启动)
### NSSM 服务方式
已自动配置开机启动
### 任务计划程序方式
1. 打开"任务计划程序"
2. 创建基本任务
3. 触发器:计算机启动时
4. 操作:启动程序
- 程序:`C:\dhcp-dns-manager\dhcp-dns-manager.exe`
- 参数:`-config configs\config.json`
- 起始于:`C:\dhcp-dns-manager`
---
## 性能优化
### 1. 排除杀毒软件扫描
将项目目录添加到杀毒软件排除列表:
- Windows 安全中心 → 病毒和威胁防护 → 管理设置 → 排除项
- 添加文件夹:`C:\dhcp-dns-manager`
### 2. 调整数据库性能
编辑 `configs\config.json`
```json
{
"database": {
"path": "data/dhcp-dns.db?_journal_mode=WAL&_synchronous=NORMAL"
}
}
```
### 3. 限制日志大小
```powershell
# 限制事件日志
wevtutil sl "Application" /ms:4194304
```
---
## 卸载
### Docker 方式
```powershell
docker-compose down
```
### NSSM 服务方式
```powershell
nssm remove dhcp-dns-manager confirm
```
### 手动删除
```powershell
# 停止服务
net stop dhcp-dns-manager
# 删除目录
Remove-Item -Recurse -Force C:\dhcp-dns-manager
```
---
## 技术支持
遇到问题可以:
1. 查看日志:
```powershell
# Docker 方式
docker-compose logs -f
# 直接运行
查看控制台输出
```
2. 检查事件查看器:
- Win + R → `eventvwr.msc`
- Windows 日志 → 应用程序
3. 提交 Issue
---
**最后更新**: 2026-04-23