From a3365e53a510e88cbb4890d62904856ca8a61288 Mon Sep 17 00:00:00 2001 From: Lbruh Date: Sat, 14 Nov 2026 19:32:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E6=B6=88Action=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=AE=89=E8=A3=85Gitea=E6=95=99=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 64 -------- content/posts/giteaInstall/安装gitea.md | 186 ++++++++++++++++++++++++ 2 files changed, 186 insertions(+), 64 deletions(-) delete mode 100644 .github/workflows/deploy.yml create mode 100644 content/posts/giteaInstall/安装gitea.md diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 6c588ec..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,64 +0,0 @@ -name: Deploy Hugo site to Pages - -on: - push: - branches: - - main - - master - workflow_dispatch: - -permissions: - contents: read - pages: write - id-token: write - -concurrency: - group: "pages" - cancel-in-progress: false - -defaults: - run: - shell: bash - -jobs: - build: - runs-on: ubuntu-latest - env: - HUGO_VERSION: 0.169.0 - steps: - - name: Install Hugo CLI - run: | - wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ - && sudo dpkg -i ${{ runner.temp }}/hugo.deb - - name: Checkout - uses: actions/checkout@v4 - with: - submodules: recursive - fetch-depth: 0 - - name: Setup Pages - id: pages - uses: actions/configure-pages@v5 - - name: Build with Hugo - env: - HUGO_CACHEDIR: ${{ runner.temp }}/hugo_cache - HUGO_ENVIRONMENT: production - run: | - hugo \ - --gc \ - --minify \ - --baseURL "https://hugo.blissxy.com/" - - name: Upload artifact - uses: actions/upload-pages-artifact@v3 - with: - path: ./public - - deploy: - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - runs-on: ubuntu-latest - needs: build - steps: - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v4 diff --git a/content/posts/giteaInstall/安装gitea.md b/content/posts/giteaInstall/安装gitea.md new file mode 100644 index 0000000..1b74532 --- /dev/null +++ b/content/posts/giteaInstall/安装gitea.md @@ -0,0 +1,186 @@ +# 服务器部署Gitea + +> 环境:Debian 12.0, 服务器:腾讯云 + +## 1. 安装基础依赖并创建专用 git 用户 + +```bash +apt update && apt install -y git curl wget +id git &>/dev/null || useradd -r -m -d /home/git -s /bin/bash git +``` + +`useradd -r` 创建一个系统用户,确保它的操作权限限制在专属目录中,既无法改动系统核心配置,也碰不到服务器上其他服务的数据。 + +## 2. 安装Gitea 文件 + +> [Gitea 文件下载](https://dl.gitea.com/gitea/) 查找最新稳定版; + +```bash +uname -r +``` + +查看框架之后,`x86_64` 选择 gitea-版本号-linux-amd64;`aarch64`选择 gitea-版本号-linux-arm64 + +下载之后,拖拽到`/usr/local/bin` 文件夹下,并重命名为 `gitea` + +```bash +chmod +x /usr/local/bin/gitea +/usr/local/bin/gitea --version +``` + +## 3. 创建工作目录并分配权限 + +```bash +mkdir -p /var/lib/gitea/{custom,data,log} +chown -R git:git /var/lib/gitea/ +chmod -R 750 /var/lib/gitea/ + +mkdir -p /etc/gitea +chown root:git /etc/gitea +chmod 770 /etc/gitea +``` + +| **目录 / 命令** | **类别** | **属主与权限** | **具体用途与作用说明** | +|:-----------------------------------------------------:|:--------:|:--------------------------:|:-----------------------------------------------------------------------------------------:| +| **`/var/lib/gitea/data`** | 核心业务数据目录 | `git:git` (`750`) | 存放所有 Git 代码仓库、SQLite3 数据库(`gitea.db`)、用户头像及附件(**备份优先级最高**,迁移服务器时必须完整保留)。 | +| **`/var/lib/gitea/custom`** | 个性化定制目录 | `git:git` (`750`) | 存放自定义网页主题、Logo 图标、自定义 HTML 模板等覆盖文件(默认安装初期为空)。 | +| **`/var/lib/gitea/log`** | 运行日志目录 | `git:git` (`750`) | 存放 Gitea 服务启动日志、HTTP 访问记录与报错信息,用于日常故障排查(可定期清理)。 | +| **`/etc/gitea`** | 系统配置目录 | `root:git` (`770` → `750`) | 存放主配置文件 `app.ini`(记录端口、公网 IP/域名、数据库及密钥设置)。 | +| **`chown -R git:git` & `chmod -R 750`** | 数据目录赋权命令 | 针对 `/var/lib/gitea/` | 将数据目录完全交给 `git` 系统账号管理(读写执行 `7`),同组用户只读(`5`),其他无关用户禁止访问(`0`),防止代码泄露。 | +| **`chown root:git` & `chmod 770`** | 配置目录赋权命令 | 针对 `/etc/gitea` | 属主设为 `root`、所属组设为 `git` 并临时赋予组写入权限(`770`),确保网页初始化点击“立即安装”时能自动写入 `app.ini`(安装后需收紧为 `750`)。 | + +## 4. 配置systemd系统服务实现后台常驻 + +### 4.1 写入配置文件 + +```bash +vim /etc/systemd/system/gitea.service +``` + +```bash +[Unit] +Description=Gitea (Git with a cup of tea) +After=syslog.target network.target + +[Service] +RestartSec=2s +Type=simple +User=git +Group=git +WorkingDirectory=/var/lib/gitea/ +ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini +Restart=always +Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea + +[Install] +WantedBy=multi-user.target +``` + +### 4.2 重新加载服务配置并设置开机自启 + +```bash +systemctl daemon-reload +systemctl enable --now gitea +``` + +### 4.3 确认 Gitea 已正常运行 + +```bash +systemctl status gitea +``` + +## 5. 开启公网访问 + +开启3000端口防火墙之后,然后访问 `http:公网IP:3000`进行配置 + +2ec1e0d1-dd64-403e-a1f2-1e8833afe97c + +## 6. 收紧配置文件权限 + +```bash +chmod 750 /etc/gitea +chmod 640 /etc/gitea/app.ini +``` + +这种情况下只能登录到服务器,使用root权限修改,并`systemctl restart gitea`重新启动 + +## 7. 配置域名 + +### 7.1 域名解析 + +将域名解析到服务器的公网IP + +### 7.2 放行 80/443 端口并安装Nginx与Certbot + +```bash +apt update && apt install -y nginx certbot python3-certbot-nginx +``` + +### 7.3 配置反向代理 + +```bash +vim /etc/nginx/sites-available/gitea +``` + +```bash +server { + listen 80; + server_name git.你的域名.com; + + # 调大请求体上限,防止推送较大提交时出现 413 报错 + client_max_body_size 512M; + + location / { + proxy_pass http://127.0.0.1:3000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} +``` + +创建快捷方式,并激活反向代理 + +```bash +ln -sf /etc/nginx/sites-available/gitea /etc/nginx/sites-enabled/gitea +nginx -t && systemctl reload nginx +``` + +出现以下提示信息时,表示配置成功! + +```bash +nginx: the configuration file /etc/nginx/nginx.conf syntax is ok +nginx: configuration file /etc/nginx/nginx.conf test is successful +``` + +### 7.4 申请免费 SSL 证书开启 HTTPS + +```bash +certbot --nginx -d git.你的域名.com +``` + +出现`Congratulations! You have successfully enabled HTTPS on https://git.你的域名.com`表示配置成功 + +### 7.5 修改Gitea配置文件并重启 + +```bash +vim /etc/gitea/app.ini +``` + +修改`server`段落 + +```toml +[server] +DOMAIN = git.你的域名.com +ROOT_URL = https://git.你的域名.com/ +HTTP_ADDR = 127.0.0.1 +``` + +重启生效 + +```bash +systemctl restart gitea +``` + +> ! 至此,配置完成