补充说明
本教程介绍 2Panel 从源码编译、发布 GitHub Release 到目标服务器一键安装、卸载、升级的完整流程,适用于个人项目自建发布链路。
项目:2Panel|计划任务管理面板 仓库:https://github.com/meimolihan/2panel 编译发布主机:fnOS(Debian) 部署测试主机:Debian Linux(amd64/arm64)
重要规则
- GitHub 不允许直接覆盖已发布 Release,正式环境版本号单向递增;内测可删除重建同名 tag。
- 一键脚本使用
releases/latest/download,脚本不需要硬编码版本号。- 编译机器 ≠ 业务运行机器;fnOS 只做编译发布,业务跑在目标 Debian 主机。
一、编译发布机(fnOS)环境准备
1.1 安装依赖
apt update
apt install git curl
安装 Go 环境(需要 Go 1.21+),确保 go version 正常输出。
1.2 安装 gh 命令行工具并授权 GitHub
gh auth login
选择 GitHub.com → SSH → 网页授权登录,务必勾选 repo 权限。
校验授权结果
gh auth status
输出必须包含:Token scopes: admin:public_key, gist, read:org, repo
1.3 拉取源码
git clone git@github.com:meimolihan/2panel.git
cd 2panel
go mod download
项目目录结构
2panel/
├── scripts/install.sh # 远程一键安装脚本
├── scripts/uninstall.sh # 卸载脚本
├── scripts/build-release.sh # 交叉编译脚本
└── internal/server/web/index.html # 前端UI页面
二、配置一键安装脚本
修改 scripts/install.sh 头部配置,填写你的 GitHub 用户名
GITHUB_OWNER="meimolihan"
GITHUB_REPO="2Panel"
DEFAULT_PORT=8080
DEFAULT_DATA_DIR="/var/lib/2panel"
提交推送至 main 分支
git add scripts/install.sh
git commit -m "fix: set github owner"
git push origin main
三、交叉编译生成静态二进制
CGO_ENABLED=0,生成无系统依赖静态二进制,支持 amd64、arm64。
3.1 使用编译脚本(推荐)
export VERSION=v0.1.0
./scripts/build-release.sh
ls -la dist/
产物:
2panel_linux_amd642panel_linux_arm64
3.2 手动编译兜底(脚本异常时)
rm -rf dist && mkdir -p dist
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o dist/2panel_linux_amd64 .
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o dist/2panel_linux_arm64 .
ls dist
四、创建 GitHub Release 并上传二进制
VERSION=v0.1.0
gh release create "$VERSION" \
dist/2panel_linux_amd64 \
dist/2panel_linux_arm64 \
--title "$VERSION" \
--notes "2Panel - Scheduled Task Manager"
校验 Release
访问:https://github.com/meimolihan/2panel/releases/tag/v0.1.0
- 状态:Published,不是 Draft 草稿
- Assets 内必须存在两个编译二进制,不要只看源码 zip/tar.gz。
测试下载链接有效性
curl -I https://github.com/meimolihan/2panel/releases/latest/download/2panel_linux_amd64
返回 302 Found 正常;返回 404 代表附件缺失。
五、目标服务器远程一键安装
目标服务器需要 root 权限,已安装 curl。
5.1 预检查国内网络
curl -sSL https://raw.githubusercontent.com/meimolihan/2panel/main/scripts/install.sh
输出 shell 脚本内容 = 网络正常;卡住超时需要网络代理。
5.2 执行一键安装
bash -c "$(curl -sSL https://raw.githubusercontent.com/meimolihan/2panel/main/scripts/install.sh)"
交互步骤:
请输入监听端口 [默认: 8080]:回车使用默认,或填写自定义端口请输入数据目录 [默认: /var/lib/2panel]:回车使用默认路径- 脚本自动下载二进制、创建 systemd 服务、启动程序
- 输出 Web 访问地址,日志输出 admin 随机初始密码
部署后运维命令
# 查看服务状态
systemctl status 2panel
# 实时日志
journalctl -u 2panel -f
# 重启服务
systemctl restart 2panel
# 查看版本
2panel -version
访问示例:http://10.10.10.246:8080
- 账号:
admin - 密码:首次启动日志输出,登录后必须修改密码
六、一键卸载
bash -c "$(curl -sSL https://raw.githubusercontent.com/meimolihan/2panel/main/scripts/uninstall.sh)"
交互:
卸载将停止并移除 2panel 服务与程序,是否继续?[y/N]y:确认卸载,继续下一步N:取消卸载,退出脚本
是否删除数据目录 /var/lib/2panel?(包含数据库、任务脚本和日志)[Y/n]Y:删除数据库、任务、全部数据n:保留业务数据,只删除程序与服务
卸载完成:systemd 服务移除、二进制文件删除。
七、新版本发布两种模式
模式 1:递增新版本(正式环境,推荐)
不要复用旧 tag,版本号向上迭代,例如 v0.1.0 → v0.1.1
cd /vol1/1000/GitHub/2panel
git add .
git commit -m "v1.0.0 首个稳定版"
git push origin main
export VERSION=v1.0.0
./scripts/build-release.sh
gh release create "$VERSION" dist/2panel_linux_amd64 dist/2panel_linux_arm64 --title "$VERSION" --notes "v1.0.0 首个稳定版"
目标服务器升级,直接重跑安装脚本,自动拉取 latest,覆盖二进制,systemd 自动重启
bash -c "$(curl -sSL https://raw.githubusercontent.com/meimolihan/2panel/main/scripts/install.sh)"
2panel -version
模式 2:删除重建同名 Release(仅限内测,无线上用户)
⚠️ 已有服务器依赖该版本绝对禁止执行,会造成旧版本下载 404。
cd /vol1/1000/GitHub/2panel
# 删除github release
gh release delete v1.0.0 --yes
# 删除本地与远端git tag
git tag -d v1.0.0
git push origin --delete v1.0.0
# 重新编译
export VERSION=v1.0.0
./scripts/build-release.sh
# 重建release上传附件
gh release create "$VERSION" \
dist/2panel_linux_amd64 \
dist/2panel_linux_arm64 \
--title "$VERSION" \
--notes "2Panel - Scheduled Task Manager"
八、故障排查表
| 现象 | 排查方案 |
|---|---|
| gh release create 返回 401 Unauthorized | 执行 gh auth login 重新授权,确保 token 具备 repo 权限 |
| 下载二进制返回 404 | 检查 Release 是否 Published,Assets 文件名严格匹配脚本 |
| raw.githubusercontent.com 卡住超时 | 国内网络限制,配置代理,或将 scripts/install.sh 镜像到 Gitee 中转 |
| 服务启动失败 | journalctl -u 2panel -n 100 查看日志;检查端口占用、目录权限 |
| 编译报错缺失依赖 | 项目目录执行 go mod download |
fnOS 本机执行 2panel: command not found |
fnOS 是编译机,没有安装服务;测试运行使用完整路径 ./dist/2panel_linux_amd64 |
九、前端 UI 修改流程
前端为内嵌单文件 internal/server/web/index.html
- 修改 html 样式、布局、交互(三原色配色、卡片样式等)
- fnOS 编译机重新完整发布流程:提交代码 → 编译 → 创建 Release
- 目标服务器重跑一键安装脚本升级生效。
十、极简速查复制块
发布新版本速记
git add .
git commit -m "xxx"
git push origin main
export VERSION=v0.x.x
./scripts/build-release.sh
gh release create "$VERSION" dist/2panel_linux_amd64 dist/2panel_linux_arm64 --title "$VERSION" --notes "更新说明"