others-Gitea安装

others-Gitea安装


前篇


这里安装的是 https://dl.gitea.com/gitea/1.22.1/gitea-1.22.1-linux-amd64

检查 git 版本, 要求 Git 版本 >= 2.0

1
2
$ git --version
git version 2.25.1

创建 git 用户

gitea 禁止使用 root 用户运行服务

1
2
3
4
5
6
7
8
$ adduser \
--system \
--shell /bin/bash \
--gecos 'Git Version Control' \
--group \
--disabled-password \
--home /home/git \
git

创建工作目录

1
2
3
4
// 数据存储目录
$ mkdir -p /var/lib/gitea/{custom,data,log,repositories,lfs}
$ chown -R git:git /var/lib/gitea/ // 递归授权给 git 用户
$ chmod -R 750 /var/lib/gitea/ // 设置权限

下载可执行文件

这里安装的是 https://dl.gitea.com/gitea/1.22.1/gitea-1.22.1-linux-amd64, 然后移到程序目录, 并授予可执行权限

1
2
$ mv gitea-1.22.1-linux-amd64 /usr/local/bin/gitea
$ chmod +x /usr/local/bin/gitea

创建配置文件 app.ini 文件

有两种方式创建这个配置文件

可以参考官方模板: https://github.com/go-gitea/gitea/blob/main/custom/conf/app.example.ini

  1. 创建目录

    1
    2
    3
    4
    // 临时为 /etc/gitea 路径授予了组外用户 git 写入权限
    $ mkdir /etc/gitea
    $ chown root:git /etc/gitea
    $ chmod 770 /etc/gitea
    1. 安装结束后设为只读权限

      1
      2
      $ chmod 750 /etc/gitea
      $ chmod 640 /etc/gitea/app.ini

手动创建配置安装

  1. 创建配置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    $ vim /etc/gitea/app.ini

    APP_NAME = Gitea: Git with a cup of tea
    RUN_USER = git
    RUN_MODE = prod
    WORK_PATH = /var/lib/gitea

    [database]
    DB_TYPE = sqlite3
    PASSWD =
    SSL_MODE = disable
    PATH = /var/lib/gitea/gitea.db
    LOG_SQL = false

    [repository]
    ROOT = /var/lib/gitea/repositories

    [server]
    SSH_DOMAIN = aaa.bbb.com
    DOMAIN = aaa.bbb.com
    HTTP_PORT = 3000
    ROOT_URL = http://aaa.bbb.com:3000/
    APP_DATA_PATH = /var/lib/gitea/data
    DISABLE_SSH = false
    SSH_PORT = 2234
    LFS_START_SERVER = true
    LFS_JWT_SECRET = YNJAAUKi1mA-G-yPfixA33WRwWO49bRioitoehOoI12
    OFFLINE_MODE = true

    [lfs]
    PATH = /var/lib/gitea/lfs

    [mailer]
    ENABLED = false

    [service]
    REGISTER_EMAIL_CONFIRM = false
    ENABLE_NOTIFY_MAIL = false
    DISABLE_REGISTRATION = false
    ALLOW_ONLY_EXTERNAL_REGISTRATION = false
    ENABLE_CAPTCHA = false
    REQUIRE_SIGNIN_VIEW = false
    DEFAULT_KEEP_EMAIL_PRIVATE = false
    DEFAULT_ALLOW_CREATE_ORGANIZATION = true
    DEFAULT_ENABLE_TIMETRACKING = true
    NO_REPLY_ADDRESS = noreply.localhost

    [openid]
    ENABLE_OPENID_SIGNIN = true
    ENABLE_OPENID_SIGNUP = true

    [cron.update_checker]
    ENABLED = false

    [session]
    PROVIDER = file

    [log]
    MODE = console
    LEVEL = info
    ROOT_PATH = /var/lib/gitea/repositories/log

    [repository.pull-request]
    DEFAULT_MERGE_STYLE = merge

    [repository.signing]
    DEFAULT_TRUST_MODEL = committer

    [security]
    INSTALL_LOCK = true
    INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE3MjMzMDYyNzR9.sWpDspU-V8YGAKs_tpQG2xqvyxywoGdRdNjCIZ1TYUk
    PASSWORD_HASH_ALGO = pbkdf2

    [oauth2]
    JWT_SECRET = -_NkvdBG4b7SA5hg0j4FVMQKLEAi22Awe88jZjT9gSw
    • 里面用的目录就是上面创建的几个工作目录, /var/lib/gitea/gitea.db 是数据库文件

web 界面配置安装

因为没有 /etc/gitea/app.ini 文件, 所有默认端口会是 3000

  • gui 配置参数

    image-20240811195219422


创建Systemd 服务

Gitea提供已配置的Systemd Unit文件。可以运行wget命令将Systemd Unit文件下载到/etc/systemd/system/目录。

完成后,重新加载Systemd,运行命令sudo systemctl daemon-reload。然后启用并启动Gitea服务。

验证Gitea服务的运行状态,运行命令sudo systemctl status gitea。你将会看到Gitea服务已成功启动。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ wget https://raw.githubusercontent.com/go-gitea/gitea/master/contrib/systemd/gitea.service -P /etc/systemd/system/

$ systemctl daemon-reload
$ systemctl start gitea
$ systemctl enable gitea
$ systemctl status gitea

● gitea.service - Gitea (Git with a cup of tea)
Loaded: loaded (/etc/systemd/system/gitea.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2024-08-11 19:56:13 CST; 1min 4s ago
Main PID: 1262090 (gitea)
Tasks: 9 (limit: 4482)
Memory: 101.4M
CGroup: /system.slice/gitea.service
└─1262090 /usr/local/bin/gitea web --config /etc/gitea/app.ini

done


关闭 注册 和 openId

  1. 修改配置 app.ini

    1
    2
    3
    4
    5
    6
    [service]
    DISABLE_REGISTRATION = true

    [openid]
    ENABLE_OPENID_SIGNIN = false
    ENABLE_OPENID_SIGNUP = false
  2. 重启服务

    1
    $ service gitea restart

升级 Gitea

要升级到最新的Gitea版本,只需下载并替换二进制文件。首先是停止Gitea服务。

下载最新的Gitea版本并将其移动到/usr/local/bin目录。运行chmod命令使Gitea二进制具有可执行权限。

最后重启Gitea服务,运行命令sudo systemctl restart gitea

1
2
3
4
sudo systemctl stop gitea
VERSION=<THE_LATEST_GITEA_VERSION>
sudo chmod +x /usr/local/bin/gitea
sudo systemctl restart gitea