在ubuntu20上配置开源Git服务Gitea

Gitea的首要目标是创建一个极易安装,运行非常快速,安装和使用体验良好的自建 Git 服务。我们采用Go作为后端语言,这使我们只要生成一个可执行程序即可。并且他还支持跨平台,支持 Linux, macOS 和 Windows 以及各种架构

1 概述|Overview

Gitea 的首要目标是创建一个极易安装,运行非常快速,安装和使用体验良好的自建 #Git 服务。

Gitea 采用 #Go 作为后端语言,这使我们只要生成一个可执行程序即可。并且他还支持跨平台,支持 Linux, macOS 和 #Windows 以及各种架构,除了x86,amd64,还包括 ARM 和 PowerPC

2 环境|Environment

名称 版本 备注
Ubuntu 20
Gitea 1.13.2

3 配置

3.1 防火墙配置

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# 查看是不是没有开放3000端口
firewall-cmd --zone=public --list-ports
# 如果没有就添加一个
firewall-cmd --zone=public --add-port=3000/tcp --permanent
# 重新载入配置文件
firewall-cmd --reload


ufw default deny
ufw allow 22/tcp
ufw allow 3000/tcp
ufw allow 80,443/tcp
ufw enable

3.2 Nginx 配置

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
server {
    listen       80;
    server_name  [域名]
}
location / {
    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_pass    http://127.0.0.1:3000;
}
location ~ .*\.(js|css|png)$ {
    proxy_pass  http://127.0.0.1:3000;
}

3.3 开机启动

3.3.1 基于 supervisor 的开机启动和自动重启

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
[program:gitea]
directory=/opt/gitea/
command=/opt/gitea/gitea web
autostart=true
autorestart=true
startsecs=10
stdout_logfile=/opt/gitea/log/stdout.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
stderr_logfile=/opt/gitea/log/stderr.log
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB
user = gitea
environment = HOME="/home/gitea", USER="gitea"

3.3.2 systemd

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
$ vim /etc/systemd/system/gitea.service

[Unit]
Description=Gitea
After=syslog.target
After=network.target

[Service]
RestartSec=2s
Type=simple
User=git
Group=git
ExecStart=/git/gitea web --config /git/custom/conf/app.ini
Restart=always

[Install]
WantedBy=multi-user.target

# 开机启动
$ systemctl enable gitea

4 运行

1
2
# 运行
systemctl start gitea

5 未来展望|Further

  1. 目前我厂 gitea 使用良好, 运行稳定
  2. 未来希望开启更多功能

6 参考|References

  1. gitea-with-debian
  2. https://docs.gitea.io/en-us/install-from-binary/
  3. SSH Server configuration in Gitea
Licensed under CC BY-NC-SA 4.0
使用 Hugo 构建
主题 StackJimmy 设计