我的GitHub
0%

gitea的安装

Ubuntu 安装 gitea

二进制安装

1. 下载

1
2
3
4
mkdir gitea
cd gitea
wget -O gitea https://dl.gitea.com/gitea/main-nightly/gitea-main-nightly-linux-amd64
chmod +x gitea

2. 注册用户

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

3. 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
mkdir -p /var/lib/gitea/{custom,data,log}
chown -R git:git /var/lib/gitea/
chmod -R 750 /var/lib/gitea/
mkdir /etc/gitea
chown root:git /etc/gitea
chmod 770 /etc/gitea

vim ~/.bashrc
# 添加如下环境变量
export GITEA_WORK_DIR=/var/lib/gitea/
# 保存退出

source ~/.bashrc

# 复制二进制到全局位置
cp gitea /usr/local/bin/gitea

配置app.ini

1
2
mkdir /etc/gitea
vim /etc/gitea/app.ini

配置如下

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
APP_NAME = Gitea
RUN_USER = git
WORK_PATH = /var/lib/gitea
RUN_MODE = prod

[database]
DB_TYPE = sqlite3
HOST = 127.0.0.1:3306
NAME = gitea
USER = gitea
PASSWD =
SCHEMA =
SSL_MODE = disable
PATH = /var/lib/gitea/data/gitea.db
LOG_SQL = false

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

[server]
SSH_DOMAIN = xxx.xxx.xxx.xxx
DOMAIN = xxx.xxx.xxx.xxx
HTTP_PORT = 3000
ROOT_URL = http://xxx.xxx.xxx.xxx:3000/
APP_DATA_PATH = /var/lib/gitea/data
DISABLE_SSH = false
SSH_PORT = 22
LFS_START_SERVER = true
LFS_JWT_SECRET =
OFFLINE_MODE = false

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

[mailer]
ENABLED = false

[service]
REGISTER_EMAIL_CONFIRM = false
ENABLE_NOTIFY_MAIL = false
DISABLE_REGISTRATION = true
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/log

[repository.pull-request]
DEFAULT_MERGE_STYLE = merge

[repository.signing]
DEFAULT_TRUST_MODEL = committer

[security]
INSTALL_LOCK = true
INTERNAL_TOKEN =
PASSWORD_HASH_ALGO =

[oauth2]
JWT_SECRET =

4.配置service

1
vim /etc/systemd/system/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=network.target
After=syslog.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

5.启动服务

1
systemctl restart gitea

6.开放服务器端口3000

7.访问

ip:3000

总结

1
2
3
4
5
6
7
8
9
10
11
# 用户
git

# 配置地址
/etc/gitea/app.ini

# gitea的安装目录
/var/lib/gitea

# service启动配置
/etc/systemd/system/gitea.service

迁移

1.备份

登录老机器

1
2
3
cd /etc/gitea/

gitea dump -c app.ini

会生成一个gitea-dump-417443001.zip的文件

2.拷贝

拷贝到新机器

什么手段不管,只要拷贝到新机器

需要拷贝的数据如下

1
2
3
4
5
6
# gitea的二进制程序
./gitea/gitea
# 备份文件
gitea-dump-417443001.zip
# gitea.service
gitea.service

假设拷贝过来以后,放在/root/temp文件夹下

1
2
3
4
5
6
7
8
cd /root/temp

mkdir giteabk
# 解压缩
unzip gitea-dump-417443001.zip -d giteabk

# 解压以后的文件
# app.ini data gitea-db.sql repos

3.安装

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
5
6
7
8
9
10
11
12
13
14
15
16
mkdir -p /var/lib/gitea/{custom,data,log}
chown -R git:git /var/lib/gitea/
chmod -R 750 /var/lib/gitea/
mkdir /etc/gitea
chown root:git /etc/gitea
chmod 770 /etc/gitea

vim ~/.bashrc
# 添加如下环境变量
export GITEA_WORK_DIR=/var/lib/gitea/
# 保存退出

source ~/.bashrc

# 复制二进制到全局位置
cp gitea /usr/local/bin/gitea
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
mkdir /etc/gitea
cp ./giteabk/app.ini /etc/gitea/app.ini
cp gitea.service /etc/systemd/system/gitea.service

vim /etc/gitea/app.ini
# 自行修改其中的ip之类的数据保存

# 拷贝数据到对应位置
cp -r giteabk/data/* /var/lib/gitea/data/
cp -r giteabk/custom/* /var/lib/gitea/custom/
cp -r giteabk/log/* /var/lib/gitea/log/
cp -r giteabk/repos/* /var/lib/gitea/data/repositories/

# sqlite3 数据库
sqlite3 $DATABASE_PATH <gitea-db.sql

service gitea restart

中间如果报错,文件没有权限,该给权限就给权限,其他都好了

我是阿星,阿星的阿,阿星的星!