Gogs介绍
Gogs(Go Git Service) 是一款极易搭建的自助 Git 服务。
- 易安装
- 跨平台
任何 Go 语言 支持的平台都可以运行 Gogs,包括 Windows、Mac、Linux 以及 ARM。
- 轻量级
一个廉价的树莓派的配置足以满足 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