Gogs 是一个使用 Go 语言写的 Git 服务端,它是开源的,本文介绍如何使用它在 CentOS 操作系统上搭建 Git 服务。
装 Golang
1 | sudo yum install golang |
64位?32位?
执行下面的命令,看下自己的操作系统是64位还是32位的:
1 | getconf LONG_BIT |
添加 git 用户
Gogs 默认使用 git 用户,如果之前没有添加过,应添加:
1 2 | sudo adduser git su git |
确定安装位置
1 | cd /home/www |
下载并解压
如果服务器操作系统是64位的,可从 gogs 页面查找到最新的对应下载链接,然后执行下载:
1 | wget https://dl.gogs.io/0.11.19/linux_amd64.tar.gz |
gogs 的 CDN 下载链接貌似从阿里云下载有些问题,所以我用了直接下载地址。
完成下载后解压:
1 | tar -zxvf linux_amd64.tar.gz |
启动和安装
进入解压后得到的目录 gogs,并启动 Gogs:
1 2 3 | cd gogs ./gogs web |
启动后,在浏览器输入http://你的IP:3000
进行安装,安装过程中可选择数据库类型,个人或小团队使用的话,推荐使用 SQLite。
静默运行 Gogs
1 | nohup ./gogs web & |
停止
1 | pgrep gogs | xargs ps -u --pid |
1 | kill -9 [进程ID] |
可能需要进行一些配置
配置文件在 custom/conf/app.ini
可能需要的模板优化
比如把 templates/base/ 中的 head.tmpl 和 foot.tmpl 中的内部JS和CSS脚本链接,替换为 bootcdn 等站点的 CDN 链接的。
可能用得上的 Git 配置
下面列出的主要是一些减少 CLI 输入量的别名配置:
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 | git config --global core.autocrlf false git config --global alias.co checkout git config --global alias.cob "checkout -b" git config --global alias.br branch git config --global alias.cii "commit -m 'init'" git config --global alias.cim "commit -m" git config --global alias.p "push origin" git config --global alias.pm "push -u origin master" git config --global alias.pt "push origin --tags" git config --global alias.cg "config --global" git config --global alias.cgu "config --global --unset" git config --global alias.cgl "config -l --global" git config --global alias.lol "log --oneline" git config --global alias.lolg "log --oneline --graph" git config --global alias.lolga "log --oneline --decorate --graph --all" git config --global alias.mw "merge --no-ff -m" git config --global alias.rao "remote add origin" |
结论
Gogs 很快, 因为它是用 Go 语言写的,Gogs 的体验虽不如 GitHub ,但应该是目前最好的开源 Git 服务端了。