0%

(六)树莓派4B安装gitea

最近git项目多了一些比较大的文件(数据库),第三方服务器的lfs基本都要收费,所以考虑自己搭建一个git服务器存放代码,关于git服务器有giteagitlab,gitlab功能太多,个人使用很多用不到,而且内存占用高,而gitea相对简洁,功能够用,选择gitea

安装

1
2
3
4
5
# 下载gitea
wget -O gitea https://dl.gitea.io/gitea/1.17.2/gitea-1.17.2-linux-arm64

# 添加权限
chmod +x gitea

启动

指定端口为8899

1
./gitea web -p 8899

访问http://192.168.2.11:8899就能进入gitea

由于是自己用,我这里选择SQLite,配置完成后,会跳转到http://localhost:3000/user/login,由于服务在树莓派上,我们需要把localhost改为树莓派的地址,配置完成后会custom/conf/app.ini生成配置文件,我们需要吧localhost换成对应的地址,如果绑定了域名,可以换成域名

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
APP_NAME = Gitea: Git with a cup of tea
RUN_USER = ubuntu
RUN_MODE = prod

[server]
LOCAL_ROOT_URL = http://192.168.2.11:8899/
SSH_DOMAIN = 192.168.2.11
DOMAIN = 192.168.2.11
HTTP_PORT = 8899
ROOT_URL = http://192.168.2.11:8899/
DISABLE_SSH = false
SSH_PORT = 22222
LFS_START_SERVER = true
LFS_JWT_SECRET = JU6s1q1kgPVDIIKHRzsUkjJ5HgUSBknJGN7FyKf-hgY
OFFLINE_MODE = true

[database]
DB_TYPE = sqlite3
HOST = 127.0.0.1:3306
NAME = gitea
USER = gitea
PASSWD =
SCHEMA =
SSL_MODE = disable
CHARSET = utf8
PATH = /home/ubuntu/server/gitea/data/gitea.db
LOG_SQL = false

[repository]
ROOT = /home/ubuntu/server/gitea/data/gitea-repositories

[lfs]
PATH = /home/ubuntu/server/gitea/data

[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

[picture]
DISABLE_GRAVATAR = true
ENABLE_FEDERATED_AVATAR = false

[openid]
ENABLE_OPENID_SIGNIN = false
ENABLE_OPENID_SIGNUP = false

[session]
PROVIDER = file

[log]
MODE = console
LEVEL = info
ROOT_PATH = /home/ubuntu/server/gitea/log
ROUTER = console

[repository.pull-request]
DEFAULT_MERGE_STYLE = merge

[repository.signing]
DEFAULT_TRUST_MODEL = committer

[security]
INSTALL_LOCK = true
INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE2NjQ3NjIwMDR9.C0b_xPSiljfhuDChyKTnzKuVtvSMjZsFSr31RxRZYLA
PASSWORD_HASH_ALGO = pbkdf2

如果使用gitea内置的SSH服务器的话,需要添加START_SSH_SERVER开启服务

1
2
3
[server]
...
START_SSH_SERVER = true

开机启动

添加一个系统用户gitea用于执行gitea

1
2
3
4
5
# 创建用户gitea,用户组为watchdog
sudo adduser --system --ingroup watchdog --disabled-password --shell /bin/bash --no-create-home --gecos 'Git Version Control' gitea

# 给用户添加文件权限
sudo chown -R gitea:watchdog /home/ubuntu/server/gitea

添加开机启动脚本/etc/systemd/system/gitea.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
#After=mysqld.service

[Service]
RestartSec=2s
User=gitea
Group=watchdog
UMask=0002
WorkingDirectory=/home/ubuntu/server/gitea
ExecStart=/home/ubuntu/server/gitea/gitea -c /home/ubuntu/server/gitea/custom/conf/app.ini -p 8899

[Install]
WantedBy=multi-user.target

开机启动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 重新加载配置文件
sudo systemctl daemon-reload

# 开机启动
sudo systemctl enable gitea
# 关闭开机启动
sudo systemctl disable gitea

# 启动
sudo systemctl start gitea
# 停止
sudo systemctl stop gitea
# 重启
sudo systemctl restart gitea

# 查看状态
sudo systemctl status gitea

接下来就可以直接在web页面玩耍了