3

把Orange Pi打造成git服务器

 3 years ago
source link: https://www.lujun9972.win/blog/2018/02/28/%E6%8A%8Aorange-pi%E6%89%93%E9%80%A0%E6%88%90git%E6%9C%8D%E5%8A%A1%E5%99%A8/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

把Orange Pi打造成git服务器

目前主流的开源git服务器有 gitlabgogs ,考虑到 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

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK