Gitea 是一种轻量级的自托管 Git 服务,允许团队和个人高效协作并管理其软件项目的版本控制。
在 Fedora 38 上安装 Gitea
第 1 步。在我们可以在 Fedora 38 上安装 Gitea 之前,重要的是要确保我们的系统是最新的软件包。这将确保我们可以访问最新功能和错误修复,并且我们可以毫无问题地安装 Gitea:
<span class="pln">sudo dnf update sudo dnf install git wget curl</span>
默认情况下,Gitea 在 Fedora 基础仓库中不可用。现在,让我们在 Fedora 38 系统上下载并设置 Gitea 二进制文件。
- 访问 Gitea 官方网站 https://gitea.io/ 并导航到下载页面。
- 找到 Linux x86-64 二进制版本,然后单击下载链接。
- 下载完成后,提取下载存档的内容。
第 3 步。配置系统服务。
通过执行以下命令创建系统用户和组以运行 Gitea 服务:
<span class="pln">sudo adduser </span><span class="pun">--</span><span class="pln">system </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 </span><span class="pun">--</span><span class="pln">comment </span><span class="str">'Git Version Control'</span> <span class="pun">--</span><span class="pln">user</span><span class="pun">-</span><span class="kwd">group</span> <span class="pun">--</span><span class="pln">home</span><span class="pun">-</span><span class="pln">dir </span><span class="pun">/</span><span class="pln">home</span><span class="pun">/</span><span class="pln">git git</span>
将提取的 Gitea 二进制文件移动到相应的目录并设置所需的权限:
<span class="pln">sudo mv gitea </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">gitea sudo chown root</span><span class="pun">:</span><span class="pln">root </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">gitea sudo chmod </span><span class="lit">755</span> <span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">gitea</span>
接下来,创建一个服务单元文件来管理 Gitea 服务:systemd
<span class="pln">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="typ">After</span><span class="pun">=</span><span class="pln">syslog</span><span class="pun">.</span><span class="pln">target </span><span class="typ">After</span><span class="pun">=</span><span class="pln">network</span><span class="pun">.</span><span class="pln">target </span><span class="typ">After</span><span class="pun">=</span><span class="pln">mysql</span><span class="pun">.</span><span class="pln">service </span><span class="typ">After</span><span class="pun">=</span><span class="pln">postgresql</span><span class="pun">.</span><span class="pln">service </span><span class="typ">After</span><span class="pun">=</span><span class="pln">memcached</span><span class="pun">.</span><span class="pln">service </span><span class="typ">After</span><span class="pun">=</span><span class="pln">redis</span><span class="pun">.</span><span class="pln">service </span><span class="pun">[</span><span class="typ">Service</span><span class="pun">]</span> <span class="typ">RestartSec</span><span class="pun">=</span><span class="lit">2s</span> <span class="typ">Type</span><span class="pun">=</span><span class="pln">simple </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">/home/</span><span class="pln">git </span><span class="typ">ExecStart</span><span class="pun">=</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">gitea web </span><span class="typ">Restart</span><span class="pun">=</span><span class="pln">always </span><span class="typ">Environment</span><span class="pun">=</span><span class="pln">USER</span><span class="pun">=</span><span class="pln">git HOME</span><span class="pun">=</span><span class="str">/home/</span><span class="pln">git GITEA_WORK_DIR</span><span class="pun">=</span><span class="str">/home/</span><span class="pln">git</span><span class="pun">/</span><span class="pln">gitea </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>
保存并关闭文件。
第 4 步。自定义 Gitea 配置。
现在创建一个目录来存储 Gitea 配置文件:
<span class="pln">sudo mkdir </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">gitea sudo chown git</span><span class="pun">:</span><span class="pln">git </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">gitea</span>
将示例配置文件复制到新创建的目录:
<span class="pln">sudo cp </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">gitea</span><span class="pun">/</span><span class="pln">sample</span><span class="pun">/</span><span class="pln">gitea</span><span class="pun">.</span><span class="pln">ini </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">gitea</span><span class="pun">/</span><span class="pln"> sudo chown git</span><span class="pun">:</span><span class="pln">git </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">gitea</span><span class="pun">/</span><span class="pln">gitea</span><span class="pun">.</span><span class="pln">ini</span>
之后,打开 Gitea 配置文件进行编辑:
<span class="pln">nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">gitea</span><span class="pun">/</span><span class="pln">gitea</span><span class="pun">.</span><span class="pln">ini</span>
根据您的首选项自定义配置,例如域设置、数据库后端和电子邮件配置。进行必要的更改后保存文件。
第5步。设置数据库后端。
Gitea需要一个数据库后端来存储其数据。在本节中,我们将介绍将MariaDB设置为数据库后端的步骤。现在我们安装和配置 MariaDB:
<span class="pln">sudo dnf install mariadb</span><span class="pun">-</span><span class="pln">server mariadb</span>
安装完成后,启动 MariaDB 服务并通过运行以下命令使其在启动时自动启动:
<span class="pln">sudo systemctl enable mariadb </span><span class="pun">--</span><span class="pln">now sudo systemctl start mariadb sudo systemctl status mariadb</span>
To check the version of MariaDB installed, run the command below:
<span class="pln">mariadb </span><span class="pun">--</span><span class="pln">version</span>
默认情况下,MariaDB 未强化。您可以使用脚本保护 MariaDB。您应该仔细阅读并在每个步骤下方仔细阅读,这将设置root密码,删除匿名用户,禁止远程root登录,并删除测试数据库和对安全MariaDB的访问权限:mysql_secure_installation
<span class="pln">mysql_secure_installation</span>
像这样配置它:
<span class="pun">-</span> <span class="typ">Set</span><span class="pln"> root password</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y </span><span class="pun">-</span> <span class="typ">Remove</span><span class="pln"> anonymous users</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y </span><span class="pun">-</span> <span class="typ">Disallow</span><span class="pln"> root login remotely</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y </span><span class="pun">-</span> <span class="typ">Remove</span><span class="pln"> test database </span><span class="kwd">and</span><span class="pln"> access to it</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y </span><span class="pun">-</span> <span class="typ">Reload</span><span class="pln"> privilege tables now</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y</span>
接下来,您需要为 Gitea 创建一个数据库和用户:
<span class="pln">mysql </span><span class="pun">-</span><span class="pln">u root </span><span class="pun">-</span><span class="pln">p</span>
登录后,使用以下命令创建数据库和用户:
<span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> CREATE DATABASE gitea</span><span class="pun">;</span> <span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</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_user'</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="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> FLUSH PRIVILEGES</span><span class="pun">;</span> <span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> EXIT</span><span class="pun">;</span>
有关安装 MariaDB 的其他资源,请阅读以下帖子:
- 如何在 Fedora Linux √ 上安装 MariaDB
第 6 步。配置 Web 服务器和反向代理。
要通过 Web 浏览器访问 Gitea,我们需要配置 Web 服务器并设置反向代理。在本节中,我们将使用 Nginx 作为 Web 服务器。现在我们安装并配置 Nginx:
<span class="pln">sudo dnf install nginx</span>
安装完成后,启动 Nginx 服务,并通过运行以下命令使其在启动时自动启动:
<span class="pln">sudo systemctl start nginx sudo systemctl enable nginx</span>
接下来,为 Gitea 创建一个 Nginx 服务器块配置文件:
<span class="pln">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">conf</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">gitea</span><span class="pun">.</span><span class="pln">conf</span>
将以下配置添加到文件中:
<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</span><span class="pun">-</span><span class="pln">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">//localhost:3000;</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="pln"> proxy_set_header X</span><span class="pun">-</span><span class="typ">Forwarded</span><span class="pun">-</span><span class="typ">For</span><span class="pln"> $proxy_add_x_forwarded_for</span><span class="pun">;</span><span class="pln"> proxy_set_header </span><span class="typ">Host</span><span class="pln"> $host</span><span class="pun">;</span> <span class="pun">}</span> <span class="pun">}</span>
步骤 7.配置 SSL 证书。
为了保护与Gitea的通信,我们将使用Let’s Encrypt和Certbot获取并配置SSL证书。现在我们安装 Certbot 和 Nginx 插件:
<span class="pln">sudo dnf install certbot python3</span><span class="pun">-</span><span class="pln">certbot</span><span class="pun">-</span><span class="pln">nginx</span>
使用 Certbot 获取 SSL 证书:
<span class="pln">sudo certbot </span><span class="pun">--</span><span class="pln">nginx </span><span class="pun">--</span><span class="pln">agree</span><span class="pun">-</span><span class="pln">tos </span><span class="pun">--</span><span class="pln">redirect </span><span class="pun">--</span><span class="pln">staple</span><span class="pun">-</span><span class="pln">ocsp </span><span class="pun">--</span><span class="pln">email your_email@example</span><span class="pun">.</span><span class="pln">com </span><span class="pun">-</span><span class="pln">d your</span><span class="pun">-</span><span class="pln">domain</span><span class="pun">.</span><span class="pln">com</span>
按照提示为您的域生成 SSL 证书。
安装和配置完成后,是时候启动 Gitea 服务并通过 Web 浏览器访问它了:
<span class="pln">sudo systemctl enable gitea sudo systemctl start gitea</span>
第8步。配置防火墙。
Fedora 默认启用防火墙,它将阻止来自其他尝试访问我们的 Gitea 服务的计算机的其他连接。我们必须打开适当的端口,以便可以从其他机器访问 Gitea 资源:
<span class="pln">sudo firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">permanent </span><span class="pun">--</span><span class="pln">zone</span><span class="pun">=</span><span class="kwd">public</span> <span class="pun">--</span><span class="kwd">add</span><span class="pun">-</span><span class="pln">service</span><span class="pun">=</span><span class="pln">http sudo firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">permanent </span><span class="pun">--</span><span class="pln">zone</span><span class="pun">=</span><span class="kwd">public</span> <span class="pun">--</span><span class="kwd">add</span><span class="pun">-</span><span class="pln">service</span><span class="pun">=</span><span class="pln">https sudo firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">reload</span>
您可以通过列出当前防火墙设置进行验证:
<span class="pln">sudo firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">permanent </span><span class="pun">--</span><span class="pln">list</span><span class="pun">-</span><span class="pln">all</span>
第9步。访问 Gitea 网页界面。
成功安装后,打开您的网络浏览器并使用 URL 访问 Gitea Web UI。您将被重定向到以下页面:https://your-domain.com
第10步。故障排除和其他资源。
- 如果您在安装过程中遇到任何问题,请参阅 Gitea 的官方文档和 Fedora 支持资源进行故障排除。
- 通过查看各自的网站和发行说明,随时了解最新版本的 Gitea 和 Fedora。
- 加入Gitea社区论坛和讨论板,与其他用户联系并寻求帮助。
- 探索 Gitea 的高级配置和功能,例如与其他开发工具和自定义选项的集成。
感谢您使用本教程在您的 Fedora 38 系统上安装 Gitea。如需其他帮助或有用信息,我们建议您查看 Gitea 官方网站。