# httpdownload **Repository Path**: kingofshihai/httpdownload ## Basic Information - **Project Name**: httpdownload - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-01 - **Last Updated**: 2026-03-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # HTTP文件下载服务 基于Go语言的轻量级HTTP文件下载服务器,用于提供MySQL备份文件下载。 ## 功能特点 - 支持通过HTTP协议下载指定文件 - 命令行参数配置端口和文件路径 - 访问日志记录 - 跨平台支持(Windows/Linux/macOS) - 静态编译,部署简单 ## 快速开始 ### 前置条件 - Go 1.19 或更高版本 - MySQL导出文件(backup.sql) ### 编译 ```bash # 克隆或下载代码到本地 go build -o httpdownload main.go ``` ### 运行 ```bash # 默认方式(端口8080,文件backup.sql) ./httpdownload # 自定义端口 ./httpdownload -port 9000 # 自定义文件路径 ./httpdownload -file /path/to/your/backup.sql # 同时使用自定义端口和文件路径 ./httpdownload -port 9000 -file /path/to/your/backup.sql ``` ### 访问方式 启动服务后,通过浏览器或HTTP客户端访问: ``` http://服务器IP:端口/download ``` 例如: - 本地访问:`http://localhost:8080/download` - 远程访问:`http://192.168.1.100:8080/download` ## 部署到Ubuntu服务器 ### 方式一:直接运行 ```bash # 1. 上传文件到服务器 scp httpdownload user@your-server:/home/user/ scp backup.sql user@your-server:/home/user/ # 2. SSH登录服务器 ssh user@your-server # 3. 运行服务 ./httpdownload ``` ### 方式二:后台运行(推荐) ```bash # 使用nohup后台运行 nohup ./httpdownload -port 8080 > download.log 2>&1 & # 查看运行状态 tail -f download.log # 查看进程 ps aux | grep httpdownload ``` ### 方式三:systemd服务(开机自启) 1. 创建服务文件: ```bash sudo nano /etc/systemd/system/httpdownload.service ``` 2. 添加以下内容: ```ini [Unit] Description=HTTP File Download Service After=network.target [Service] Type=simple User=your-user WorkingDirectory=/home/your-user ExecStart=/home/your-user/httpdownload -port 8080 -file /home/your-user/backup.sql Restart=on-failure RestartSec=5s [Install] WantedBy=multi-user.target ``` 3. 启用并启动服务: ```bash # 重新加载systemd配置 sudo systemctl daemon-reload # 设置开机自启 sudo systemctl enable httpdownload # 启动服务 sudo systemctl start httpdownload # 查看状态 sudo systemctl status httpdownload # 查看日志 sudo journalctl -u httpdownload -f ``` ## 命令行参数 | 参数 | 说明 | 默认值 | |------|------|--------| | `-port` | HTTP服务监听端口 | `8080` | | `-file` | 要提供的下载文件路径 | `backup.sql` | ## 日志输出 服务会输出访问日志,格式如下: ``` [2024-01-15 10:30:25] 192.168.1.50:52341 / 200 15.2ms ``` ## 防火墙配置 如果无法访问,请检查防火墙设置: ```bash # Ubuntu/Debian (ufw) sudo ufw allow 8080/tcp # CentOS/RHEL (firewalld) sudo firewall-cmd --permanent --add-port=8080/tcp sudo firewall-cmd --reload ``` ## 安全建议 1. 建议在内网使用,避免暴露在公网 2. 如需公网访问,建议添加认证机制或IP白名单 3. 定期更新备份文件 4. 监控服务日志,及时发现异常访问 ## 故障排查 ### 端口被占用 ```bash # 查看端口占用 sudo netstat -tlnp | grep 8080 # 更换端口运行 ./httpdownload -port 8081 ``` ### 文件无法访问 ```bash # 检查文件是否存在 ls -lh backup.sql # 检查文件权限 chmod 644 backup.sql ``` ### 服务无法启动 ```bash # 查看详细错误信息 ./httpdownload 2>&1 | tee error.log ``` ## 许可证 MIT License