Skip to content

二进制部署

二进制部署是最简单直接的部署方式,无需 Docker,直接运行编译好的可执行文件。

适用场景

  • 不想使用 Docker 的环境
  • 对性能有更高要求的场景
  • 资源受限的嵌入式设备
  • 需要直接访问系统资源的场景

前置条件

  • 已完成环境要求检查
  • 已准备数据库(PostgreSQL 或 MySQL)
  • Linux/macOS/Windows 系统

快速开始

1. 下载二进制文件

Gitee Releases 下载对应平台的二进制文件:

平台文件名说明
Linux AMD64dns-go-linux-amd64主流服务器
Linux ARM64dns-go-linux-arm64ARM 服务器
macOS AMD64dns-go-darwin-amd64Intel Mac
macOS ARM64dns-go-darwin-arm64Apple Silicon
Windows AMD64dns-go-windows-amd64.exeWindows 服务器
FreeBSD AMD64dns-go-freebsd-amd64FreeBSD 系统

下载命令(Linux):

bash
# 下载最新版本
wget https://gitee.com/liumou_site/dns-go/releases/download/v2.0.0/dns-go-linux-amd64

# 或下载到指定目录
wget -O /usr/local/bin/dns-go \
  https://gitee.com/liumou_site/dns-go/releases/download/v2.0.0/dns-go-linux-amd64

2. 准备配置文件

创建配置目录和文件:

bash
# 创建目录
mkdir -p /opt/dns-go/config
mkdir -p /opt/dns-go/data
mkdir -p /opt/dns-go/logs

# 下载配置模板
cd /opt/dns-go
curl -o config/config.toml \
  https://gitee.com/liumou_site/dns-go/raw/master/vitepress/public/config.example.toml

编辑配置文件:

bash
vim config/config.toml

关键配置项:

toml
[database]
driver = "postgres"
host = "127.0.0.1"
port = 5432
username = "dnsgo"
password = "your_secure_password"  # ⚠️ 必须修改
database = "dns_go"
sslmode = "disable"

[jwt]
secret_key = "your_jwt_secret_key_min_32_chars"  # ⚠️ 必须修改
expires_in = 24

[valkey]
ip = "127.0.0.1"
port = 6379
password = ""
db = 0

3. 初始化数据库

PostgreSQL:

bash
# 创建用户
sudo -u postgres psql -c "CREATE USER dnsgo WITH PASSWORD 'your_password';"

# 创建数据库
sudo -u postgres psql -c "CREATE DATABASE dns_go OWNER dnsgo;"

MySQL:

bash
mysql -u root -p
sql
CREATE USER 'dnsgo'@'localhost' IDENTIFIED BY 'your_password';
CREATE DATABASE dns_go CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL PRIVILEGES ON dns_go.* TO 'dnsgo'@'localhost';
FLUSH PRIVILEGES;

4. 运行程序

Linux/macOS:

bash
# 添加执行权限
chmod +x dns-go-linux-amd64

# 运行程序
./dns-go-linux-amd64

# 或使用完整路径
/opt/dns-go/dns-go-linux-amd64

Windows:

powershell
# 在 PowerShell 中运行
.\dns-go-windows-amd64.exe

# 或在 CMD 中
dns-go-windows-amd64.exe

5. 验证部署

bash
# 检查程序是否在运行
ps aux | grep dns-go

# 查看监听端口
netstat -tlnp | grep dns-go

# 测试 Web 服务
curl http://localhost:8085/api/health

# 测试 DNS 服务
dig @localhost www.example.com

访问 Web 界面:http://localhost:8085

默认账号:admin / admin123

生产环境部署

使用 systemd 管理(Linux)

创建 systemd 服务文件:

bash
sudo tee /etc/systemd/system/dns-go.service > /dev/null <<EOF
[Unit]
Description=DNS-Go DNS Management Platform
After=network.target postgresql.service
Wants=postgresql.service

[Service]
Type=simple
User=dnsgo
Group=dnsgo
WorkingDirectory=/opt/dns-go
ExecStart=/opt/dns-go/dns-go-linux-amd64
Restart=always
RestartSec=5
StandardOutput=journal
StandardError=journal
SyslogIdentifier=dns-go

# Security
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=true
ReadWritePaths=/opt/dns-go/data /opt/dns-go/logs

[Install]
WantedBy=multi-user.target
EOF

创建运行用户:

bash
# 创建用户
sudo useradd -r -s /bin/false -d /opt/dns-go dnsgo

# 设置目录权限
sudo chown -R dnsgo:dnsgo /opt/dns-go

启动服务:

bash
# 重新加载 systemd
sudo systemctl daemon-reload

# 启动服务
sudo systemctl start dns-go

# 设置开机自启
sudo systemctl enable dns-go

# 查看状态
sudo systemctl status dns-go

# 查看日志
sudo journalctl -u dns-go -f

使用 Windows 服务(Windows)

使用 NSSM 将程序注册为 Windows 服务:

powershell
# 下载 NSSM
wget https://nssm.cc/release/nssm-2.24.zip

# 解压并复制到系统目录
copy nssm.exe C:\Windows\System32\

# 创建服务
nssm install DNS-Go

# 在弹出的窗口中配置:
# Path: C:\dns-go\dns-go-windows-amd64.exe
# Startup directory: C:\dns-go
# Arguments: (留空)

# 启动服务
nssm start DNS-Go

# 设置开机自启
nssm set DNS-Go Start SERVICE_AUTO_START

使用 launchd(macOS)

创建 plist 文件:

bash
sudo tee /Library/LaunchDaemons/com.dns-go.plist > /dev/null <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.dns-go</string>
    <key>ProgramArguments</key>
    <array>
        <string>/opt/dns-go/dns-go-darwin-amd64</string>
    </array>
    <key>WorkingDirectory</key>
    <string>/opt/dns-go</string>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
    <key>StandardOutPath</key>
    <string>/opt/dns-go/logs/stdout.log</string>
    <key>StandardErrorPath</key>
    <string>/opt/dns-go/logs/stderr.log</string>
</dict>
</plist>
EOF

启动服务:

bash
# 加载服务
sudo launchctl load /Library/LaunchDaemons/com.dns-go.plist

# 启动服务
sudo launchctl start com.dns-go

# 查看状态
sudo launchctl list | grep dns-go

常用操作

查看日志

Linux(systemd):

bash
# 实时查看日志
sudo journalctl -u dns-go -f

# 查看最近 100 行
sudo journalctl -u dns-go -n 100

# 查看今天的日志
sudo journalctl -u dns-go --since today

直接运行模式:

bash
# 程序输出到终端,直接查看
./dns-go-linux-amd64

# 或重定向到文件
./dns-go-linux-amd64 > /opt/dns-go/logs/app.log 2>&1 &

停止服务

systemd:

bash
sudo systemctl stop dns-go

直接运行:

bash
# 查找进程 PID
ps aux | grep dns-go

# 结束进程
kill <PID>

# 强制结束
kill -9 <PID>

重启服务

systemd:

bash
sudo systemctl restart dns-go

launchd:

bash
sudo launchctl stop com.dns-go
sudo launchctl start com.dns-go

更新版本

bash
# 1. 停止服务
sudo systemctl stop dns-go

# 2. 备份当前版本
cp /opt/dns-go/dns-go-linux-amd64 /opt/dns-go/dns-go-linux-amd64.backup

# 3. 下载新版本
wget -O /opt/dns-go/dns-go-linux-amd64 \
  https://gitee.com/liumou_site/dns-go/releases/download/v2.1.0/dns-go-linux-amd64

# 4. 添加执行权限
chmod +x /opt/dns-go/dns-go-linux-amd64

# 5. 启动服务
sudo systemctl start dns-go

# 6. 验证版本
/opt/dns-go/dns-go-linux-amd64 --version

命令行参数

DNS-Go 支持以下命令行参数:

参数说明示例
--version显示版本信息./dns-go --version
--config指定配置文件路径./dns-go --config /path/to/config.toml
--portWeb 服务端口./dns-go --port 8080
--dns-portDNS 服务端口./dns-go --dns-port 5353
--help显示帮助信息./dns-go --help

指定配置文件

bash
./dns-go-linux-amd64 --config /etc/dns-go/config.toml

修改监听端口

bash
# 修改 Web 端口
./dns-go-linux-amd64 --port 8080

# 修改 DNS 端口(需要 root 权限)
sudo ./dns-go-linux-amd64 --dns-port 53

故障排查

程序无法启动

bash
# 检查配置文件
/opt/dns-go/dns-go-linux-amd64 --config /opt/dns-go/config/config.toml

# 检查配置文件权限
ls -la /opt/dns-go/config/

# 检查端口占用
sudo netstat -tlnp | grep -E '8085|53'

权限不足

bash
# 绑定 53 端口需要 root 权限
sudo ./dns-go-linux-amd64

# 或使用 setcap 授权
sudo setcap cap_net_bind_service=+ep /opt/dns-go/dns-go-linux-amd64

# 之后可以普通用户运行
./dns-go-linux-amd64

数据库连接失败

bash
# 测试数据库连接
psql -h localhost -U dnsgo -d dns_go -c "SELECT 1;"

# 检查数据库服务状态
sudo systemctl status postgresql

# 检查数据库监听地址
sudo netstat -tlnp | grep 5432

日志文件权限

bash
# 确保日志目录可写
sudo chown -R dnsgo:dnsgo /opt/dns-go/logs

# 或设置适当的权限
sudo chmod 755 /opt/dns-go/logs

性能优化

系统调优

Linux 系统参数优化:

bash
# 编辑 /etc/sysctl.conf
sudo tee -a /etc/sysctl.conf <<EOF
# 增加文件描述符限制
fs.file-max = 65535

# 优化网络参数
net.core.somaxconn = 65535
net.ipv4.tcp_max_syn_backlog = 65535
EOF

# 应用配置
sudo sysctl -p

资源限制

修改 systemd 服务文件:

bash
sudo tee -a /etc/systemd/system/dns-go.service <<EOF

# 资源限制
LimitNOFILE=65535
LimitNPROC=4096
MemoryLimit=1G
EOF

sudo systemctl daemon-reload
sudo systemctl restart dns-go

相关文档

基于 MIT 许可发布