这时候,自己搭建代码仓库的好处就体现出来了。下面我们就讲讲如何使用 Gogs 搭建自己的代码仓库。
https://gogs.io/docs/installation/install_from_binary.html
根据自己的平台下载压缩包,我的环境是 Linux amd64
[root@Box tmp]# tar xvf gogs_0.12.3_linux_amd64.tar.gz -C /opt/
[root@Box gogs]# ./gogs web
2021/08/20 15:30:36 [ WARN] Custom config "/opt/gogs/custom/conf/app.ini" not found. Ignore this warning if you're running for the first time
2021/08/20 15:30:36 [TRACE] Log mode: Console (Trace)
2021/08/20 15:30:36 [ INFO] Gogs 0.12.3
2021/08/20 15:30:36 [TRACE] Work directory: /opt/gogs
2021/08/20 15:30:36 [TRACE] Custom path: /opt/gogs/custom
2021/08/20 15:30:36 [TRACE] Custom config: /opt/gogs/custom/conf/app.ini
2021/08/20 15:30:36 [TRACE] Log path: /opt/gogs/log
2021/08/20 15:30:36 [TRACE] Build time: 2020-10-07 03:03:48 UTC
2021/08/20 15:30:36 [TRACE] Build commit: f0e3cd90f8d7695960eeef2e4e54b2e717302f6c
2021/08/20 15:30:36 [ INFO] Run mode: Development
2021/08/20 15:30:36 [ INFO] Listen on http://0.0.0.0:3000
http://<server_ip>:3000/install
可能出现的问题:浏览器无响应。
解决办法:关闭服务器防火墙。
ubuntu:iptables -X、iptables -Z、iptables -F
centos:systemctl stop firewalld.service,永久关闭 systemctl disable firewalld.service
为了部署简单,数据库选用 sqlite3,这样就不需要安装任何数据库了,甚至 sqlite3 命令都不需要安装。
这里着重讲一下开机自启,我尝试了好几种方式都不行,如下
最后发现,其实,
gogs 已经提供了相应开机启动服务脚本,不过需要根据自己的配置修改
/opt/gogs/scripts/systemd/gogs.service
[root@Box systemd]# cat gogs.service
[Unit]
Description=Gogs
After=syslog.target
After=network.target
After=mariadb.service mysqld.service postgresql.service memcached.service redis.service
[Service]
# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
###
#LimitMEMLOCK=infinity
#LimitNOFILE=65535
Type=simple
User=root
Group=root
WorkingDirectory=/opt/gogs
ExecStart=/opt/gogs/gogs web
Restart=always
Environment=USER=root HOME=/opt
# Some distributions may not support these hardening directives. If you cannot start the service due
# to an unknown option, comment out the ones not supported by your version of systemd.
ProtectSystem=full
PrivateDevices=yes
PrivateTmp=yes
NoNewPrivileges=true
[Install]
WantedBy=multi-user.target
拷贝到 /usr/lib/systemd/system,并使能服务,重启
[root@Box systemd]# cp gogs.service /usr/lib/systemd/system
[root@Box systemd]# systemctl enable gogs.service
Created symlink /etc/systemd/system/multi-user.target.wants/gogs.service → /usr/lib/systemd/system/gogs.service.
[root@Box systemd]# reboot
查看 gogs 是否启动
[root@Box ~]# ps -ef
...
root 916 1 1 17:45 ? 00:00:00 /opt/gogs/gogs web
...
看到 gogs 已经自启了,浏览器也可以正常访问。
这是我三年前在云服务器上搭建的,一直稳定运行到现在
希望你们也拥有自己的代码仓库。