Files
dhcp-dns-manager/BUILD.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

275 lines
4.4 KiB
Markdown
Raw Permalink 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.
# 🔨 构建指南
如果在安装过程中遇到问题,请参考本指南。
---
## 问题:依赖下载失败
### 错误信息
```
go: github.com/google/gopacket@v1.2.3: reading github.com/google/gopacket/go.mod at revision v1.2.3: unknown revision v1.2.3
```
### 解决方案
已修复 `go.mod` 文件。请执行以下步骤:
#### 方法 1:重新运行安装脚本
```bash
cd /path/to/dhcp-dns-manager
sudo ./install.sh
```
#### 方法 2:手动修复
```bash
# 1. 进入项目目录
cd /path/to/dhcp-dns-manager
# 2. 删除旧的 go.sum(如果有)
rm -f go.sum
# 3. 清理模块缓存
go clean -modcache
# 4. 重新下载依赖
go mod download
# 5. 整理依赖
go mod tidy
# 6. 编译
go build -o dhcp-dns-manager ./cmd
```
---
## 问题:CGO 编译失败
### 错误信息
```
error: gcc failed: command not found
```
### 解决方案
需要安装 GCC 编译器:
**Debian/Ubuntu:**
```bash
sudo apt update
sudo apt install build-essential
```
**RHEL/CentOS:**
```bash
sudo yum install gcc make
```
**然后重新编译:**
```bash
go build -o dhcp-dns-manager ./cmd
```
---
## 问题:SQLite 驱动编译失败
### 错误信息
```
sqlite3.h: No such file or directory
```
### 解决方案
需要安装 SQLite 开发库:
**Debian/Ubuntu:**
```bash
sudo apt install libsqlite3-dev
```
**RHEL/CentOS:**
```bash
sudo yum install sqlite-devel
```
**然后重新编译:**
```bash
CGO_ENABLED=1 go build -o dhcp-dns-manager ./cmd
```
---
## 问题:Go 版本过低
### 错误信息
```
go: module requires Go 1.21
```
### 解决方案
安装最新版 Go
```bash
# 1. 下载
wget https://go.dev/dl/go1.21.0.linux-amd64.tar.gz
# 2. 解压
sudo tar -C /usr/local -xzf go1.21.0.linux-amd64.tar.gz
# 3. 添加到 PATH
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
source ~/.bashrc
# 4. 验证
go version
```
---
## 完整手动安装步骤
如果自动安装脚本失败,可以手动安装:
### 1. 安装依赖
```bash
# Debian/Ubuntu
sudo apt update
sudo apt install -y git build-essential libsqlite3-dev
# RHEL/CentOS
sudo yum install -y git gcc make sqlite-devel
```
### 2. 安装 Go(如果未安装)
```bash
wget https://go.dev/dl/go1.21.0.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.21.0.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
```
### 3. 编译程序
```bash
cd /path/to/dhcp-dns-manager
# 下载依赖
go mod download
go mod tidy
# 编译
CGO_ENABLED=1 go build -o dhcp-dns-manager ./cmd
```
### 4. 创建 systemd 服务
```bash
sudo nano /etc/systemd/system/dhcp-dns-manager.service
```
内容:
```ini
[Unit]
Description=DHCP & DNS Manager Service
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/path/to/dhcp-dns-manager
ExecStart=/path/to/dhcp-dns-manager/dhcp-dns-manager -config /path/to/dhcp-dns-manager/configs/config.json
Restart=always
[Install]
WantedBy=multi-user.target
```
### 5. 启动服务
```bash
sudo systemctl daemon-reload
sudo systemctl enable dhcp-dns-manager
sudo systemctl start dhcp-dns-manager
sudo systemctl status dhcp-dns-manager
```
### 6. 配置防火墙
```bash
# UFW
sudo ufw allow 53/udp
sudo ufw allow 67/udp
sudo ufw allow 8080/tcp
# Firewalld
sudo firewall-cmd --permanent --add-port=53/udp
sudo firewall-cmd --permanent --add-port=67/udp
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
```
---
## 验证安装
### 检查服务状态
```bash
systemctl status dhcp-dns-manager
```
### 检查端口监听
```bash
sudo netstat -ulpn | grep -E ':(53|67|8080)'
```
### 访问 Web 界面
```
http://your-server-ip:8080
```
---
## 常见错误速查
| 错误 | 原因 | 解决方案 |
|------|------|----------|
| `go: not found` | Go 未安装 | 安装 Go 1.21+ |
| `gcc: command not found` | 缺少编译器 | 安装 build-essential |
| `sqlite3.h: No such file` | 缺少 SQLite 头文件 | 安装 libsqlite3-dev |
| `permission denied` | 权限不足 | 使用 sudo |
| `port already in use` | 端口被占用 | 修改 config.json 端口 |
| `module not found` | 依赖未下载 | 运行 `go mod download` |
---
## 获取帮助
如果以上方法都无法解决问题:
1. 查看详细日志:
```bash
journalctl -u dhcp-dns-manager -f
```
2. 检查 Go 环境:
```bash
go version
go env
```
3. 提交 Issue 时请提供:
- 操作系统版本
- Go 版本
- 完整错误信息
- 已尝试的解决方案
---
**最后更新**: 2026-04-23