【linux】centos7部署gitea-1.21.7

简介:

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

前提:

安装 git >= 2.0mysql >= 5.7

Gitea 支持 PostgreSQL(>=10)、MySQL(>=5.7)、SQLite 和 MSSQL(>=2008R2 SP3)这几种数据库。我这里选择 MySQL

下载 gitea:

官方下载地址:https://dl.gitea.com/gitea

这里使用二进制文件安装,版本为:gitea-1.21.7

1
2
wget -O gitea https://dl.gitea.com/gitea/1.21.7/gitea-1.21.7-linux-amd64
chmod +x gitea

服务器配置

创建用户

Gitea 需要一个用户运行,不能使用 root 用户,推荐使用名称 git

1
2
3
4
5
6
7
8
9
groupadd --system git
adduser \
--system \
--shell /bin/bash \
--comment 'Git Version Control' \
--gid git \
--home-dir /home/git \
--create-home \
git

创建工作路径

1
2
3
4
5
6
7
8
9
# Gitea 工作目录
mkdir -p /var/lib/gitea/{custom,data,log}
chown -R git:git /var/lib/gitea/
chmod -R 750 /var/lib/gitea/

# Gitea 配置目录
mkdir /etc/gitea
chown git:git /etc/gitea
chmod 770 /etc/gitea

将二进制文件放到全局位置

1
mv gitea /usr/local/bin/gitea

systemd 服务管理

添加服务文件

官方提供的 gitea.service 文件:
https://github.com/go-gitea/gitea/blob/v1.21.7/contrib/systemd/gitea.service

1
vim /lib/systemd/system/gitea.service

将以下内容粘贴到 gitea.service 文件中

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
[Unit]
Description=Gitea (Git with a cup of tea)
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=git
Group=git
WorkingDirectory=/var/lib/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=/usr/local/bin/gitea web --config /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/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

添加完后重新加载 systemd 服务

1
systemctl daemon-reload

systemd 命令

1
2
3
4
5
6
7
8
9
10
# 启动
systemctl start gitea
# 停止
systemctl stop gitea
# 重启
systemctl restart gitea
# 开启开机自启
systemctl enable gitea
# 关闭开机自启
systemctl disable gitea

启动服务

按照以上命令启动服务

1
systemctl start gitea

访问 http://localhost:3000 即可进入安装界面,安装完成后即可。

配置域名

在 nginx 中设置反向代理:

1
2
3
4
5
6
7
8
server
{
listen 80;
server_name git.rocyuan.top;
location / {
proxy_pass http://localhost:3000;
}
}

文档参考

https://github.com/go-gitea/gitea/tree/v1.21.7

https://docs.gitea.com/zh-cn/