Skip to content

安装部署

本页面将详细介绍 GoSpeedTest 的各种安装和部署方法。

系统要求

  • 操作系统:Linux、macOS、Windows
  • 内存:最低 512MB,推荐 1GB+
  • 磁盘:最低 10MB
  • 网络:用于测速需要足够的带宽

构建选项

方式一:使用构建脚本

bash
# 克隆项目
git clone https://gitee.com/liumou_site/GoSpeedTest.git
cd GoSpeedTest

# 构建所有目标(当前平台)
python3 build.py

# 构建所有平台(跨平台)
python3 build.py --all

# 只构建服务器
python3 build.py --target server

# 只构建客户端
python3 build.py --target client

方式二:手动构建

bash
# 构建服务器
go build -o GoSpeedTest server.go

# 构建 CLI 客户端
go build -o GoSpeedTest-CLI cmd/client/main.go

# 交叉编译 - Linux
GOOS=linux GOARCH=amd64 go build -o GoSpeedTest server.go

# 交叉编译 - Windows
GOOS=windows GOARCH=amd64 go build -o GoSpeedTest.exe server.go

# 交叉编译 - macOS
GOOS=darwin GOARCH=arm64 go build -o GoSpeedTest-mac server.go

服务端配置

命令行参数

参数默认值说明
-port8080HTTP 服务器监听端口
-modedebug运行模式(debug/release)
-tcp-port12306TCP 服务器端口
-addr0.0.0.0监听地址

环境变量

bash
# 设置运行模式
export GIN_MODE=release

# 运行服务器
./GoSpeedTest -port 8080

作为系统服务

systemd 服务配置

创建 /etc/systemd/system/gospeedtest.service

ini
[Unit]
Description=GoSpeedTest Server
After=network.target

[Service]
Type=simple
User=nobody
WorkingDirectory=/opt/gospeedtest
ExecStart=/opt/gospeedtest/GoSpeedTest -port 8080 -mode release
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

启动服务:

bash
# 重载配置
systemctl daemon-reload

# 启动服务
systemctl start gospeedtest

# 设置开机自启
systemctl enable gospeedtest

# 查看状态
systemctl status gospeedtest

验证部署

bash
# 检查服务是否正在运行
curl http://localhost:8080/health

# 或者访问 Web 界面
# 浏览器打开 http://localhost:8080

常见问题

端口被占用

如果 8080 端口被占用,可以使用其他端口:

bash
./GoSpeedTest -port 8081

防火墙配置

如果需要开放端口:

bash
# Ubuntu/Debian
ufw allow 8080/tcp

# CentOS/RHEL
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload

基于 LGPL-3.0 许可证发布