Gogs 是一款极易搭建的自助 Git 服务。
Gogs官网:https://gogs.io/
以下内容为本次安装过程的一个记录
准备环境
按照官方文档指示的环境要求处理, https://gogs.io/docs/installation
一台虚拟机
选择你熟悉和中意的linux,不必在意我以下使用的发行版(留了模板)
此处选用
Rocky8.7
是因为本机VMware里躺着一个虚拟机模版,果断完整克隆一份(省时)传闻消耗资源少?,就分个2核1G内存的丐版(不够再加)
配置静态IP地址, 配置可连接互联网(基操)
虚拟机硬件资源配置
1
2
3
4
5
6
7
8
9
10
11
12
13[root@localhost /]# lscpu | grep -E 'CPU|Core'
CPU op-mode(s): 32-bit, 64-bit
CPU(s): 2
On-line CPU(s) list: 0,1
Core(s) per socket: 2
CPU family: 16
CPU MHz: 3013.536
NUMA node0 CPU(s): 0,1
[root@localhost /]# free -h
total used free shared buff/cache available
Mem: 777Mi 284Mi 78Mi 3.0Mi 413Mi 358Mi
Swap: 2.0Gi 8.0Mi 2.0Gi
[root@localhost /]#
数据库
跳过此项,使用sqlite
安装git
检查是否安装Git,如发现已安装,检查版本是否满足环境要求所需版本
1
2[root@localhost ~]# git
-bash: git: command not found安装git
1
2
3
4
5dnf update
dnf install git -y
……
[root@localhost ~]# git --version
git version 2.43.5
SSH服务器
该版本已安装ssh服务,可远程ssh登陆(不懂是之前手动安装的还是系统自带的,不重要)
安装必要工具和依赖
1 | [root@localhost ~]# tar --version |
经过检查,系统已安装tar和wget,如未安装,使用如下命令安装
1 | dnf install wget tar |
下载Gogs二进制源码
/opt
路径下创建Gogs目录,用于存放源码文件1
2
3
4
5
6
7cd /opt
mkdir Gogs_0.13.0
……
[root@localhost opt]# ll
total 0
drwxr-xr-x. 2 root root 6 Sep 17 05:14 Gogs_0.13.0
[root@localhost opt]#wget下载二进制源码(当前日期20240917最新github release 版本)
1
2
3
4
5
6
7
8
9
10wget https://github.com/gogs/gogs/releases/download/v0.13.0/gogs_0.13.0_linux_amd64.tar.gz
# 发现从github下载速度慢,从官网 https://dl.gogs.io/0.13.0/ 下载
wget https://dl.gogs.io/0.13.0/gogs_0.13.0_linux_amd64.tar.gz
[root@localhost Gogs_0.13.0]# ll
total 29352
-rw-r--r--. 1 root root 30054955 Feb 25 2023 gogs_0.13.0_linux_amd64.tar.gz
[root@localhost Gogs_0.13.0]#
解压下载的 tar 包
1 | [root@localhost Gogs_0.13.0]# tar -xzf gogs_0.13.0_linux_amd64.tar.gz |
运行Gogs
防火墙设置
1
2
3
4
5
6
7
8
9# 确保允许访问 Gogs 使用的端口(默认是 3000),主要使用物理机访问使用,且我这Rocky8.7没安装图形界面,所以……
firewall-cmd --permanent --add-port=3000/tcp
firewall-cmd --reload
# 修改实际使用的端口号,下一步骤中修改30000,当然使用3000也是可以的
firewall-cmd --permanent --add-port=30000/tcp
firewall-cmd --reload使用命令
cd
进入到解压后的目录。执行命令
./gogs web
。Gogs 默认会在端口
3000
启动 HTTP 服务,访问/install
以进行初始配置(例如 http://localhost:3000/install )。1
2
3
4
5
6
7
8
9
10
11
12
13[root@localhost gogs]# ./gogs web
2024/09/17 05:44:24 [ WARN] Custom config "/opt/Gogs_0.13.0/gogs/custom/conf/app.ini" not found. Ignore this warning if you're running for the first time
2024/09/17 05:44:24 [TRACE] Log mode: Console (Trace)
2024/09/17 05:44:24 [ INFO] Gogs 0.13.0
2024/09/17 05:44:24 [TRACE] Work directory: /opt/Gogs_0.13.0/gogs
2024/09/17 05:44:24 [TRACE] Custom path: /opt/Gogs_0.13.0/gogs/custom
2024/09/17 05:44:24 [TRACE] Custom config: /opt/Gogs_0.13.0/gogs/custom/conf/app.ini
2024/09/17 05:44:24 [TRACE] Log path: /opt/Gogs_0.13.0/gogs/log
2024/09/17 05:44:24 [TRACE] Build time: 2023-02-25 02:30:34 UTC
2024/09/17 05:44:24 [TRACE] Build commit: 8c21874c00b6100d46b662f65baeb40647442f42
2024/09/17 05:44:24 [ INFO] Run mode: Development
2024/09/17 05:44:24 [ INFO] Available on http://localhost:3000/
从外部访问虚拟机中Gogs
访问
/install
以进行初始配置(例如 http://172.31.100.xx:3000/install ),可以自由发挥(以下是我的配置)上面配置中邮件服务留空了,本地没有邮件服务器,也不想联网
上面配置中的创建管理员用户可以不设置,第一个注册的用户自动成为管理员,我在此处截胡了
没有邮件服务,引起的问题:用户不能通过邮箱找回密码,需要管理员用户重置
重启Gogs,进行登陆
中文显示
设置 Gogs 服务开机启动
将
/opt/Gogs_0.13.0/gogs/scripts/systemd
路径下的gogs.service
文件复制到/etc/systemd/system
1
[root@localhost systemd]# cp gogs.service /etc/systemd/system
修改
/etc/systemd/system
路径下的gogs.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[Unit]
Description=Gogs
After=syslog.target
After=network.target
# After=mariadb.service mysql.service mysqld.service postgresql.service memcached.service $
[Service]
# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
###
#LimitMEMLOCK=infinity
#LimitNOFILE=65535
Type=simple
User=root
Group=root
WorkingDirectory=/opt/Gogs_0.13.0/gogs
ExecStart=/opt/Gogs_0.13.0/gogs/gogs web
Restart=always
# Environment=USER=git HOME=/home/root
# Some distributions may not support these hardening directives. If you cannot start the s$
# to an unknown option, comment out the ones not supported by your version of systemd.
ProtectSystem=full
PrivateDevices=yes
PrivateTmp=yes
NoNewPrivileges=true
[Install]
WantedBy=multi-user.target重新加载 systemd 配置并启动 Gogs 服务
1
2
3systemctl daemon-reload
systemctl start gogs
systemctl enable gogs
外部仓库克隆测试
以https方式 git clone 一个仓库至本地,(github把https方式克隆仓库给ban了,现在都需要验证,去gitee克隆)
再次进行初始化
种种原因可能需要再次进行初始化(比如修改数据库,更改管理员等)
删除/root/gogs-repositories 目录
1
[root@localhost ~]# rm -rf gogs-repositories/
删除/opt/Gogs_0.13.0/gogs 目录
1
[root@localhost Gogs_0.13.0]# rm -rf gogs
再次解压,运行Gogs
1
2
3
4
5
6
7
8
9
10
11
12
13
14[root@localhost gogs]# ./gogs web
2024/09/17 12:12:01 [ WARN] Custom config "/opt/Gogs_0.13.0/gogs/custom/conf/app.ini" not found. Ignore this warning if you're running for the first time
2024/09/17 12:12:01 [TRACE] Log mode: Console (Trace)
2024/09/17 12:12:01 [ INFO] Gogs 0.13.0
2024/09/17 12:12:01 [TRACE] Work directory: /opt/Gogs_0.13.0/gogs
2024/09/17 12:12:01 [TRACE] Custom path: /opt/Gogs_0.13.0/gogs/custom
2024/09/17 12:12:01 [TRACE] Custom config: /opt/Gogs_0.13.0/gogs/custom/conf/app.ini
2024/09/17 12:12:01 [TRACE] Log path: /opt/Gogs_0.13.0/gogs/log
2024/09/17 12:12:01 [TRACE] Build time: 2023-02-25 02:30:34 UTC
2024/09/17 12:12:01 [TRACE] Build commit: 8c21874c00b6100d46b662f65baeb40647442f42
2024/09/17 12:12:01 [ INFO] Run mode: Development
2024/09/17 12:12:01 [ INFO] Available on http://localhost:3000/
2024/09/17 12:12:01 [FATAL] [gogs.io/gogs/internal/cmd/web.go:776 runWeb()] Failed to start server: listen tcp 0.0.0.0:3000: bind: address already in use
[root@localhost gogs]#提示端口已经在使用,关闭进程或重启系统解决
1
2
3
4
5
6
7# 查找进程ID,终止进程
[root@localhost gogs]# lsof -i :3000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
gogs 1543 root 10u IPv6 29519 0t0 TCP *:hbci (LISTEN)
[root@localhost gogs]# kill 1543
[root@localhost gogs]# lsof -i :3000
[root@localhost gogs]#