Gitea是一种开源的Git服务,为管理存储库和协作软件开发提供了强大而通用的解决方案。其轻巧的设计与用户友好的 Web 界面相结合,使其成为寻求完全控制其代码的个人和小型团队的绝佳选择。
在 Debian 12 书虫上安装 Gitea
第 1 步。在我们安装任何软件之前,通过在终端中运行以下命令来确保您的系统是最新的非常重要:apt
<span class="pln">sudo apt update sudo apt upgrade</span>
此命令更新软件包列表并将已安装的软件包升级到最新版本。
第 2 步。安装必要的依赖项。
要为 Gitea 奠定基础,您需要一些基本软件包。其中包括Git,MariaDB和Go。
- 吉特
通过执行以下命令安装 Git:
<span class="pln">sudo apt install git</span>
- 玛丽亚数据库
MariaDB充当Gitea的数据库后端。安装它并采取额外的步骤来保护数据库:
<span class="pln">sudo apt install mariadb</span><span class="pun">-</span><span class="pln">server sudo mysql_secure_installation</span>
- 去
构建 Gitea 需要 Go 编程语言。像这样安装它:
<span class="pln">sudo apt install golang</span><span class="pun">-</span><span class="pln">go</span>
第 3 步。为 Gitea 创建专用系统用户。
出于安全原因,明智的做法是为Gitea创建一个专用的系统用户。这会将其操作与系统的其余部分隔离开来:
<span class="pln">sudo adduser </span><span class="pun">--</span><span class="pln">system </span><span class="pun">--</span><span class="kwd">group</span> <span class="pun">--</span><span class="pln">disabled</span><span class="pun">-</span><span class="pln">password </span><span class="pun">--</span><span class="pln">shell </span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">bash git</span>
第 4 步。为 Gitea 设置 MySQL 数据库。
现在,让我们准备 MariaDB 来托管 Gitea 的数据库。首先,以根用户身份登录:
<span class="pln">sudo mysql </span><span class="pun">-</span><span class="pln">u root </span><span class="pun">-</span><span class="pln">p</span>
通过执行以下 SQL 命令为 Gitea 创建数据库和用户。替换为您选择的强密码:'your_strong_password'
<span class="pln">CREATE DATABASE gitea</span><span class="pun">;</span><span class="pln"> CREATE USER </span><span class="str">'gitea'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pln"> IDENTIFIED BY </span><span class="str">'your_strong_password'</span><span class="pun">;</span><span class="pln"> GRANT ALL PRIVILEGES ON gitea</span><span class="pun">.*</span><span class="pln"> TO </span><span class="str">'gitea'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pun">;</span><span class="pln"> FLUSH PRIVILEGES</span><span class="pun">;</span><span class="pln"> EXIT</span><span class="pun">;</span>
首先,使用以下命令克隆 Gitea 存储库:
<span class="pln">git clone https</span><span class="pun">:</span><span class="com">//github.com/go-gitea/gitea</span>
构建吉特:
<span class="pln">cd gitea make build</span>
这将从源代码编译 Gitea。生成的二进制文件将位于目录中。gitea
第 6 步。将 Gitea 作为服务运行
要将 Gitea 作为服务运行,您可以使用 .通过运行以下命令为 Gitea 创建一个服务单元文件:systemd
systemd
<span class="pln">sudo nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">systemd</span><span class="pun">/</span><span class="pln">system</span><span class="pun">/</span><span class="pln">gitea</span><span class="pun">.</span><span class="pln">service</span>
将以下内容粘贴到文件中,并相应地修改路径:
<span class="pun">[</span><span class="typ">Unit</span><span class="pun">]</span> <span class="typ">Description</span><span class="pun">=</span><span class="typ">Gitea</span> <span class="pun">(</span><span class="typ">Git</span> <span class="kwd">with</span><span class="pln"> a cup </span><span class="kwd">of</span><span class="pln"> tea</span><span class="pun">)</span> <span class="pun">[</span><span class="typ">Service</span><span class="pun">]</span> <span class="typ">ExecStart</span><span class="pun">=</span><span class="str">/path/</span><span class="pln">to</span><span class="pun">/</span><span class="pln">your</span><span class="pun">/</span><span class="pln">gitea executable web </span><span class="typ">Restart</span><span class="pun">=</span><span class="pln">always </span><span class="typ">User</span><span class="pun">=</span><span class="pln">git </span><span class="typ">Group</span><span class="pun">=</span><span class="pln">git </span><span class="typ">WorkingDirectory</span><span class="pun">=</span><span class="str">/path/</span><span class="pln">to</span><span class="pun">/</span><span class="pln">your</span><span class="pun">/</span><span class="pln">gitea directory </span><span class="pun">[</span><span class="typ">Install</span><span class="pun">]</span> <span class="typ">WantedBy</span><span class="pun">=</span><span class="pln">multi</span><span class="pun">-</span><span class="pln">user</span><span class="pun">.</span><span class="pln">target</span>
创建服务单元后,启用并启动 Gitea 服务:systemd
<span class="pln">sudo systemctl enable gitea sudo systemctl start gitea</span>
步骤 7.使用 nginx 将 Gitea 配置为反向代理。
如果您没有安装 Nginx,则可以使用以下方法:
<span class="pln">sudo apt install nginx</span>
接下来,您将创建一个 Nginx 配置文件来充当 Gitea 的反向代理。在 为 Gitea 创建一个新的 Nginx 站点配置文件。/etc/nginx/sites-available/gitea
<span class="pln">sudo nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">sites</span><span class="pun">-</span><span class="pln">available</span><span class="pun">/</span><span class="pln">gitea</span>
在此文件中,您将为 Gitea 定义服务器块。请务必替换为您的实际域或 IP 地址。此外,如果您将 Gitea 配置为在不同的端口上运行,请调整指令。your_domain.com
proxy_pass
<span class="pln">server </span><span class="pun">{</span><span class="pln"> listen </span><span class="lit">80</span><span class="pun">;</span><span class="pln"> server_name your_domain</span><span class="pun">.</span><span class="pln">com</span><span class="pun">;</span><span class="pln"> location </span><span class="pun">/</span> <span class="pun">{</span><span class="pln"> proxy_pass http</span><span class="pun">:</span><span class="com">//127.0.0.1:3000; # Assuming Gitea runs on port 3000</span><span class="pln"> proxy_set_header </span><span class="typ">Host</span><span class="pln"> $host</span><span class="pun">;</span><span class="pln"> proxy_set_header X</span><span class="pun">-</span><span class="typ">Real</span><span class="pun">-</span><span class="pln">IP $remote_addr</span><span class="pun">;</span> <span class="pun">}</span> <span class="pun">}</span>
创建 Nginx 配置后,创建一个符号链接以启用站点:
<span class="pln">sudo ln </span><span class="pun">-</span><span class="pln">s </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">sites</span><span class="pun">-</span><span class="pln">available</span><span class="pun">/</span><span class="pln">gitea </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">sites</span><span class="pun">-</span><span class="pln">enabled</span><span class="pun">/</span>
测试 Nginx 配置是否存在语法错误:
<span class="pln">nginx </span><span class="pun">-</span><span class="pln">t</span>
如果未报告任何错误,请重新加载 Nginx 以应用新配置:
<span class="pln">sudo systemctl reload nginx</span>
第8步。配置防火墙。
允许端口 80 上的传入流量,这是 Nginx 用于 HTTP 流量的默认端口:
<span class="pln">sudo ufw allow </span><span class="lit">80</span><span class="pun">/</span><span class="pln">tcp</span>
如果您将SSL / TLS与Nginx一起使用,请允许端口443上的传入流量,这是Nginx用于HTTPS流量的默认端口:
<span class="pln">sudo ufw allow </span><span class="lit">443</span><span class="pun">/</span><span class="pln">tcp</span>
启用防火墙:
<span class="pln">sudo ufw enable</span>
第9步。访问 Gitea 网页界面。
打开您的 Web 浏览器并导航到(替换为您的实际域或 IP 地址)以访问您的 Gitea 实例。您应该会看到Gitea网络界面。http://your_domain.com
your_domain.com
第10步。使用Let’s Encrypt SSL保护Gitea(可选)
为了增强安全性,您可以使用 Let’s Encrypt SSL 保护您的 Gitea 实例。此步骤是可选的,但强烈建议用于加密传输中的数据。以下是简要概述:
<span class="pln">sudo apt install certbot python3</span><span class="pun">-</span><span class="pln">certbot</span><span class="pun">-</span><span class="pln">nginx</span>
请求让我们加密证书:
<span class="pln">sudo certbot </span><span class="pun">--</span><span class="pln">nginx</span>
感谢您使用本教程在 Debian 12 书虫上安装最新版本的 Gitea。如需其他帮助或有用信息,我们建议您查看 Gitea 官方网站。