Centos7 使用Gogs搭建Git代码仓库

本文介绍了如何在Centos7上使用Gogs搭建Git代码仓库。从Gogs的简介开始,逐步讲解了安装Git服务器仓库、创建Git用户、安装Gogs的步骤,并提供了问题及解决办法,例如SSH连接问题的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Gogs介绍

Gogs(Go Git Service) 是一款极易搭建的自助 Git 服务。

  1. 易安装

您除了可以根据操作系统平台下载 二进制运行,还可以通过 DockerVagrant,以及 包管理 安装。

  1. 跨平台

任何 Go 语言 支持的平台都可以运行 Gogs,包括 Windows、Mac、Linux 以及 ARM。

  1. 轻量级

一个廉价的树莓派的配置足以满足 Gogs 的最低系统硬件要求。有些用户甚至还将 Gogs 运行在 NAS 设备上。

安装Git服务器仓库

移除旧版本git

 git --version	## 查看自带的版本
 yum remove git	## 移除原来的版本

下载Git

wget https://github.com/git/git/archive/v2.26.0.tar.gz -O /home/download/git.tar.gz

解压

tar -zxvf /home/download/git.tar.gz

编译安装

cd /home/download/git-2.26.0
make prefix=/usr/local/git all
make prefix=/usr/local/git install

加入环境变量

echo "export PATH="/usr/local/git/bin:$PATH" >> /etc/profile	##加入环境变量
ln -s /usr/local/git/bin/git /usr/local/bin/git 				##加入环境变量

source /etc/profile	##使配置立即生效
git --version		##查看版本

到此Git安装完毕

创建Git用户

useradd git -g git
passwd git	##参数是用户名

安装Gogs

下载Gogs

wget https://dl.gogs.io/0.11.91/gogs_0.11.91_linux_amd64.tar.gz -O /home/download/gogs.tar.gz

解压 gogs默认的设置在/home/git/目录下的

tar -zxvf /home/downloadgogs.tar.gz -C /home/git/

将目录中所有权限修改为git用户

sudo chown -R git:git /home/git/gogs

复制systemd服务文件

sudo cp /home/git/gogs/scripts/systemd/gogs.service /etc/systemd/system/

启动gogs服务

sudo systemctl start gogs.service

开机启动gogs服务

sudo systemctl enable gogs.service

查看gogs服务状态

systemctl status gogs.service
● gogs.service - Gogs
   Loaded: loaded (/etc/systemd/system/gogs.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2019-05-01 10:33:40 CDT; 3s ago
 Main PID: 21269 (gogs)
   CGroup: /system.slice/gogs.service
           └─21269 /home/git/gogs/gogs web

May 01 10:33:40 vps gogs[21269]: 2019/05/01 10:33:40 [ WARN] Custom config '/home/git/gogs/custom/conf/app.ini' not found, ignore this if you're running first time
May 01 10:33:40 vps gogs[21269]: 2019/05/01 10:33:40 [TRACE] Custom path: /home/git/gogs/custom
May 01 10:33:40 vps gogs[21269]: 2019/05/01 10:33:40 [TRACE] Log path: /home/git/gogs/log
May 01 10:33:40 vps gogs[21269]: 2019/05/01 10:33:40 [TRACE] Log Mode: Console (Trace)
May 01 10:33:40 vps gogs[21269]: 2019/05/01 10:33:40 [ INFO] Gogs 0.11.86.0130
May 01 10:33:40 vps gogs[21269]: 2019/05/01 10:33:40 [ INFO] Cache Service Enabled
May 01 10:33:40 vps gogs[21269]: 2019/05/01 10:33:40 [ INFO] Session Service Enabled
May 01 10:33:40 vps gogs[21269]: 2019/05/01 10:33:40 [ INFO] SQLite3 Supported
May 01 10:33:40 vps gogs[21269]: 2019/05/01 10:33:40 [ INFO] Run Mode: Development
May 01 10:33:41 vps gogs[21269]: 2019/05/01 10:33:41 [ INFO] Listen: http://0.0.0.0:3000

至此gogs就安装完成了,访问gogs默认端口为3000

http://localhost:3000/

数据库我使用SQLite3不需要安装任何东西

问题及解决办法

问题1:通过ssh无法远程连接仓库

PTY allocation request failed on channel 0
Hi there, You've successfully authenticated, but Gogs does not provide shell access.
If this is unexpected, please log in with password and setup Gogs under another user.
Connection to YourHost closed.

解决办法:

  • 可以新建一个其它用户(如:gitssh)来和git用户区分,而不占用git用户中配置的authorized_keys

  • 也可以针对不同的域名或IP使用不同的id_rsa.pub公钥,参考内容:How to config SSH settings

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值