CentOS系统安装Gitea
Gitea 是一个自己托管的 Git 服务程序。它和 GitHub, Bitbucket or Gitlab 等比较类似。它是从 Gogs 发展而来,不过已经 Fork 并且命名为 Gitea。
这个项目的目标是提供最简单、最快速和最无痛苦的方法来设置自托管的 Git 服务。
更多详情信息可以前往官网进行了解,进入官网 (opens new window)。
# 更新Git版本
安装最新 Gitea,CentOS7.6 默认的 git 版本是 1.8,无法使用,需要安装 2.x 版本。
当使用低版本 Git 时,Gitea 在启动后直接报错。可以通过 journalctl -xe
命令,进行错误信息的查看。
Jun 24 12:41:55 ly-centos gitea[12235]: 2023/06/24 12:41:55 routers/init.go:69:mustInitCtx() [F] code.gitea.io/gitea/modules/git.InitFull(ctx) failed: installed git version "1.8.3.1" is not supported, Gitea requi
res git version >= "2.0.0", get git: https://git-scm.com/download/linux and https://ius.io
1
2
2
# 安装Git依赖
yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
1
# 卸载Git
rpm -e --nodeps git
1
# 下载Git源码并编译安装
注意:git 安装目录必须在 usr
下,当 Gitea 启动时才能找到。
默认安装到 /usr/bin
目录,执行命令 echo $PATH
确认当前路径包含 /usr/bin
。
cd /usr/src
wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.38.1.tar.gz
tar -xzvf git-2.38.1.tar.gz
cd git-2.38.1
./configure prefix=/usr/
make; make install
git --version
1
2
3
4
5
6
7
2
3
4
5
6
7
# 安装Gitea
Gitea 默认不允许使用 root 账户,需要先新建用户。
# 新建用户
adduser gitea
passwd gitea
vi /etc/sudoers
找到第 99 行,Allow root to run any commands anywhere 下面添加 gitea ALL=(ALL) ALL
1
2
3
4
2
3
4
# 下载Gitea安装包
此时,用户目录为 /home/gitea/
,此目录为 Gitea 主目录,执行 su gitea
切换至 gitea 用户。
wget -O gitea https://dl.gitea.io/gitea/1.20/gitea-1.20-linux-amd64
chmod +x gitea
./gitea web
1
2
3
2
3
此时访问 服务器IP:3000
即可访问 Gitea,确保 3000 默认端口开放,若可正常访问,先初始化系统设置,然后 Ctrl C 结束运行,将这个程序作为服务运行,要不然此窗口一关闭程序就停止了。
# 注册服务
为了程序可以方便的后台运行,需要将程序注册为服务来运行,执行:
sudo vim /etc/systemd/system/gitea.service
1
实例配置文件内容如下:
[Unit]
Description=Codes (GitHub of rumosky)
After=syslog.target
After=network.target
###
# Don't forget to add the database service dependencies
###
#
#Wants=mysql.service
#After=mysql.service
#
#Wants=mariadb.service
#After=mariadb.service
#
#Wants=postgresql.service
#After=postgresql.service
#
#Wants=memcached.service
#After=memcached.service
#
#Wants=redis.service
#After=redis.service
#
###
# If using socket activation for main http/s
###
#
#After=gitea.main.socket
#Requires=gitea.main.socket
#
###
# (You can also provide gitea an http fallback and/or ssh socket too)
#
# An example of /etc/systemd/system/gitea.main.socket
###
##
## [Unit]
## Description=Gitea Web Socket
## PartOf=gitea.service
##
## [Socket]
## Service=gitea.service
## ListenStream=<some_port>
## NoDelay=true
##
## [Install]
## WantedBy=sockets.target
##
###
[Service]
# Uncomment the next line if you have repos with lots of files and get a HTTP 500 error because of that
# LimitNOFILE=524288:524288
RestartSec=2s
Type=simple
User=gitea
Group=gitea
WorkingDirectory=/home/gitea/
# If using Unix socket: tells systemd to create the /run/gitea folder, which will contain the gitea.sock file
# (manually creating /run/gitea doesn't work, because it would not persist across reboots)
#RuntimeDirectory=gitea
ExecStart=/home/gitea/gitea web --config /home/gitea/custom/conf/app.ini
Restart=always
Environment=USER=gitea HOME=/home/gitea/ GITEA_WORK_DIR=/home/gitea/
# If you install Git to directory prefix other than default PATH (which happens
# for example if you install other versions of Git side-to-side with
# distribution version), uncomment below line and add that prefix to PATH
# Don't forget to place git-lfs binary on the PATH below if you want to enable
# Git LFS support
#Environment=PATH=/path/to/git/bin:/bin:/sbin:/usr/bin:/usr/sbin
# If you want to bind Gitea to a port below 1024, uncomment
# the two values below, or use socket activation to pass Gitea its ports as above
###
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
#AmbientCapabilities=CAP_NET_BIND_SERVICE
###
# In some cases, when using CapabilityBoundingSet and AmbientCapabilities option, you may want to
# set the following value to false to allow capabilities to be applied on gitea process. The following
# value if set to true sandboxes gitea service and prevent any processes from running with privileges
# in the host user namespace.
###
#PrivateUsers=false
###
[Install]
WantedBy=multi-user.target
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
76
77
78
79
80
81
82
83
84
85
86
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
76
77
78
79
80
81
82
83
84
85
86
# 验证服务
# 激活服务
[root@centos ~]# sudo systemctl enable gitea
# 启动服务
[root@centos ~]# sudo systemctl start gitea
# 查看状态
[root@centos ~]# systemctl status gitea
● gitea.service - Gitea (Git with a cup of tea)
Loaded: loaded (/etc/systemd/system/gitea.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2023-06-24 12:42:48 CST; 26min ago
Main PID: 15084 (gitea)
Status: "Starting Gitea"
Tasks: 6
Memory: 82.9M
CGroup: /system.slice/gitea.service
└─15084 /home/gitea/gitea web --config /home/gitea/custom/conf/app.ini
Jun 24 12:42:48 ly-centos gitea[15084]: 2023/06/24 12:42:48 cmd/web.go:296:listen() [I] LFS server enabled
Jun 24 12:42:48 ly-centos gitea[15084]: 2023/06/24 12:42:48 ...s/graceful/server.go:62:NewServer() [I] Starting new Web server: tcp:0.0.0.0:3000 on PID: 15084
......
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 常见问题
# 1. Gitea一直不断重启,gitea.service holdoff time over, scheduling restart
Jun 24 12:42:23 ly-centos gitea[14080]: 2023/06/24 12:42:23 routers/init.go:69:mustInitCtx() [F] code.gitea.io/gitea/modules/git.InitFull(ctx) failed: git not found: exec: "git": executable file not found in $PATH
1
问题原因:找不到 Git 的执行文件,Git 需要安装在 /usr 目录下。
上次更新: 2023/09/16, 02:28:15