把 Orange Pi 打造成 git 服务器
目前主流的开源 git 服务器有 gitlab
和 gogs
,考虑到 gogs
相对轻量级,而 OrangePi 的性能普遍不高,因此这里选择 gogs
安装 golang
gogs 要求 Go 语言版本 >=1.6,Ubuntu 上的 golang 刚好是 1.6 版的,因此我们直接用 apt
安装
sudo apt install golang
安装 git
sudo apt install git
然后创建 git
用户
sudo adduser --disabled-login --gecos 'Gogs' git
设置环境变量
sudo su - git cd ~ echo 'export GOPATH=$HOME/go' >> $HOME/.bashrc source $HOME/.bashrc
安装 Gogs
由于我们只是自己使用,需求很低,因此让 Gogs 直接使用 SQLite3 数据库
go get -u -tags "sqlite" github.com/gogits/gogs # 注意,这一步要的时间超级长 cd $GOPATH/src/github.com/gogits/gogs go build -tags "sqlite"
安装好后,试试运行 ./gogs web
,当出现类似下面的内容时启动成功了
git@orangepipc2:~/go/src/github.com/gogits/gogs$ ./gogs web 2018/02/28 23:08:16 [ WARN] Custom config '/home/git/go/src/github.com/gogits/gogs/custom/conf/app.ini' not found, ignore this if you're running first time 2018/02/28 23:08:16 [TRACE] Custom path: /home/git/go/src/github.com/gogits/gogs/custom 2018/02/28 23:08:16 [TRACE] Log path: /home/git/go/src/github.com/gogits/gogs/log 2018/02/28 23:08:16 [TRACE] Log Mode: Console (Trace) 2018/02/28 23:08:16 [ INFO] Gogs 0.11.34.1122 2018/02/28 23:08:16 [ INFO] Cache Service Enabled 2018/02/28 23:08:16 [ INFO] Session Service Enabled 2018/02/28 23:08:16 [ INFO] SQLite3 Supported 2018/02/28 23:08:16 [ INFO] Run Mode: Development 2018/02/28 23:08:18 [ INFO] Listen: http://0.0.0.0:3000
从启动内容可以看出 gogs
监听了 3000 端口。
在第一次访问该 URL 后会出现安装配置页面,这里只需要注意我们要选择数据库类型为 sqlite3
,其他的按照需求自己填就好了。
自动运行 Gogs 服务器
Gogs 提供了一个默认的 service 文件供我们使用: ~/go/src/github.com/gogits/gogs/scripts/systemd/gogs.service
su - cp /home/git/go/src/github.com/gogits/gogs/scripts/systemd/gogs.service /etc/systemd/system
修改 gogs.service 配置文件,由于我们只用 sqlite,因此把 After=mariadb.service mysqld.service postgresql.service memcached.service redis.service
注释掉
然后创建一个软连接
cd ~/go/src/github.com/gogits/gogs ln -s $(pwd) /home/git/gogs
重载系统服务器
systemctl daemon-reload
设置 Gogs 服务器并设置为开机启动
systemctl start gogs systemctl enable gogs
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论