Files
gitea-deploy/README.md
T

71 lines
2.7 KiB
Markdown
Raw 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.
# 自建 Gitea 部署记录
这套脚本是用来把私有仓库从 GitHub 搬到自己的服务器上的,2026-11 实际跑过一次(OpenCloudOS 9.6 / 4 核 3.6G / amd64,Gitea 28.4.0)。
## 安装
```bash
sudo bash install-gitea.sh --port 3000
```
装完会打印地址、管理员账号密码。默认:
- 目录 `/opt/gitea`,systemd 服务名 `gitea`
- 数据库 SQLite(`/opt/gitea/data/gitea.db`),仓库文件在 `/opt/gitea/repositories`
- 关闭注册(`DISABLE_REGISTRATION=true`)、必须登录才能看(`REQUIRE_SIGNIN_VIEW=true`)
- 不启用内置 SSH(HTTP 推送就够用,也省得跟系统 22 端口打架)
常用参数:`--dir` `--port` `--domain` `--user` `--password` `--https`。
加人:
```bash
sudo runuser -u git -- /opt/gitea/gitea admin user create \
--username alice --password '密码' --email a@b.c \
--config /opt/gitea/custom/conf/app.ini
```
## 迁移仓库
在本地(放代码的机器)跑:
```bash
node push-all.mjs --url http://服务器:3000 --user gitea --token <令牌>
```
- 扫描 `~/workspace` 下每个项目目录;`--dirs` 可以换目录
- 没有 `.git` 的先 init + 提交,顺手补一个通用 `.gitignore`
- 在 Gitea 里建同名**私有**仓库(已存在就复用)
- 远端名用 `gitea`,不动原来的 `origin`;令牌只出现在那一次 push 的命令行里,不写进 `.git/config`
- `--dry` 只看会推什么
令牌在 `http://服务器:3000/user/settings/applications` 生成,勾「写: 仓库」和「写: 用户」。
## 备份
```bash
tar czf gitea-$(date +%F).tar.gz /opt/gitea/data /opt/gitea/repositories /opt/gitea/custom
```
数据库和仓库文件分开存,一起打包就行;恢复到同样路径即可。
## 已知取舍
- 用 SQLite,单机够用;多人高并发要换 MySQL/PostgreSQL
- 只跑 HTTP,没有证书;正式对外建议前面挂 Nginx + certbot
- 装机脚本从 `dl.gitea.com` 拉二进制,国内可能很慢(实测 40 分钟才下完),慢的话可以先在本地下好再 `scp` 上去
## 合作者
<a href="http://110.42.217.133:3000/clover"><img src="http://110.42.217.133:3000/avatars/1f792e843512244f2ec558c883531d9afd24cab0cf35e4f41635cb8805df3d88?size=40" width="24" height="24" alt="四叶草"> **四叶草** · [@clover](http://110.42.217.133:3000/clover)</a>
项目所有者:[@gitea](http://110.42.217.133:3000/gitea)。合作者拥有该仓库的管理权限(修改设置、合并 PR、管理合作者)。
## 许可证
本项目采用 **GNU General Public License v3.0** 许可,全文见 [LICENSE](LICENSE)。
Copyright (C) 2026 syc65535
你可以自由使用、修改和分发,但分发时必须以相同许可证开放源代码;本程序不提供任何担保。