106 lines
2.6 KiB
Markdown
106 lines
2.6 KiB
Markdown
# Gitea 初始化指南
|
|
|
|
## 访问地址
|
|
- **Web:** http://49.235.172.252:8080
|
|
- **SSH:** `git@49.235.172.252:2222`
|
|
|
|
## 安装向导配置
|
|
|
|
打开 http://49.235.172.252:8080 后,填写以下配置:
|
|
|
|
### 数据库设置
|
|
- **数据库类型:** SQLite3(保持默认)
|
|
|
|
### 通用设置
|
|
- **站点标题:** gch3n Git
|
|
- **仓库根目录:** `/data/git/gitea-repositories`
|
|
- **Git 域名:** `49.235.172.252`
|
|
- **SSH 服务端口:** `2222`
|
|
- **Gitea 基础 URL:** `http://49.235.172.252:8080/`
|
|
- **日志路径:** `/data/gitea/log`
|
|
|
|
### 可选设置
|
|
- **启用发送邮件:** 暂时不勾选(后续可配置)
|
|
- **服务器和其他服务设置:** 保持默认
|
|
|
|
### 管理员账号设置
|
|
- **管理员用户名:** (你自己定)
|
|
- **密码:** (强密码)
|
|
- **电子邮箱:** (你的邮箱)
|
|
|
|
## 安装后配置
|
|
|
|
### 1. 创建第一个仓库
|
|
1. 点击右上角 + → 新建仓库
|
|
2. 仓库名称: `my-app`
|
|
3. 初始化仓库: 勾选 "添加 README"
|
|
|
|
### 2. 本地 Git 配置
|
|
|
|
```bash
|
|
# 配置 Git 用户信息(如果没配置过)
|
|
git config --global user.name "Your Name"
|
|
git config --global user.email "your@email.com"
|
|
|
|
# 生成 SSH 密钥(如果没有)
|
|
ssh-keygen -t ed25519 -C "your@email.com"
|
|
|
|
# 复制公钥到 Gitea
|
|
cat ~/.ssh/id_ed25519.pub
|
|
# 在 Gitea 网页: 用户设置 → SSH/GPG 密钥 → 添加密钥
|
|
|
|
# 克隆仓库
|
|
git clone ssh://git@49.235.172.252:2222/用户名/my-app.git
|
|
cd my-app
|
|
|
|
# 或者关联现有项目
|
|
git remote add origin ssh://git@49.235.172.252:2222/用户名/my-app.git
|
|
git push -u origin main
|
|
```
|
|
|
|
### 3. 启用 CI/CD (Gitea Actions)
|
|
|
|
1. 在 Gitea 管理后台 → 配置 → 启用 Actions
|
|
2. 在仓库设置 → Actions → 启用
|
|
3. 将 `.gitea/workflows/deploy.yml` 复制到你的仓库 `.gitea/workflows/` 目录
|
|
|
|
### 4. 添加部署密钥到仓库 Secrets
|
|
|
|
在仓库 → 设置 → Secrets:
|
|
- `SSH_PRIVATE_KEY`: (之前生成的私钥内容)
|
|
- `SERVER_HOST`: `49.235.172.252`
|
|
- `SERVER_PORT`: `11022`
|
|
- `SERVER_USER`: `nplx`
|
|
|
|
## 使用蓝绿部署
|
|
|
|
```bash
|
|
# 在服务器上执行
|
|
ssh nplx@49.235.172.252 -p 11022
|
|
cd ~/gch3n-infra
|
|
./deploy.sh blue # 部署到 blue 环境
|
|
./deploy.sh green # 部署到 green 环境(自动切换流量)
|
|
```
|
|
|
|
## 下一步:配置 HTTPS
|
|
|
|
当前是 HTTP,需要配置 SSL 证书:
|
|
|
|
1. 清理占用 80 端口的服务
|
|
2. 申请 Let's Encrypt 证书
|
|
3. 配置 Nginx 反向代理 + HTTPS
|
|
|
|
## 文件位置
|
|
|
|
- Gitea 数据: `~/gch3n-infra/data/gitea/`
|
|
- Git 仓库: `~/gch3n-infra/data/gitea/git/`
|
|
- CI/CD 配置: `~/gch3n-infra/.gitea/workflows/deploy.yml`
|
|
- 部署脚本: `~/gch3n-infra/deploy.sh`
|
|
|
|
---
|
|
|
|
**遇到问题?** 查看 Gitea 日志:
|
|
```bash
|
|
docker logs gitea -f
|
|
```
|