硬件设备
- 树莓派3B、128G内存卡
- 读卡器
树莓派系统安装和配置
- 使用SDCardFormatter对内存卡进行格式化。
- 下载树莓派ubuntu18.04服务器版系统,下载地址
- 使用
Win32DiskImager
或者balenaetcher将镜像写入到tf卡中。 - 系统安装完成后默认用户名密码均为
ubuntu
,系统ssh服务默认打开。 - 通过修改
/etc/netplan
目录中的类似命名为50-cloud-init.yaml
文件可已修改静态IP,修改完之后使用sudo netplan apply
。(可选)
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
eth0:
dhcp4: false
addresses: [172.16.1.118/24]
gateway4: 172.16.1.1
nameservers:
addresses: [8.8.8.8,9.9.9.9]
version: 2
- 使用
apt-get update
和apt-get upgrade
更新源以及系统,如果官方源比较慢可以换成中科大或者清华的源,网上有很多教程,这里不赘述。
配置Gogs
- 安装nginx
apt-get install nginx
- 安装git
apt-get install git
- 安装mysql
apt-get install mysql-server
- 下载树莓派版Gogs,通过二进制文件安装(这里我的树莓派3B选armv6的)下载地址
- 初始化mysql数据库
> cd gogs/scripts
> mysql -u root -p < mysql.sql
- 启动gogs配置页面
> ./gogs web
程序启动后,可通过http://ip:3000
来访问完成配置。二进制安装配置
- 开启后台运行,
nohup ./gogs web &
- 开机自动运行
编辑/home/ubuntu/gogs/scripts/systemd
里面的gogs.service
文件,将文件中的用户和目录参数修改为你自己的设置。cp /home/ubuntu/gogs/scripts/systemd/gogs.service /usr/lib/systemd/system/ #拷贝到系统服务目录 sudo systemctl enable xxxx.service #注册服务
- 重启,发现已经可以自动启动了。
部署HTTPS证书
生成证书,如下修改``文件,重启服务即可。
[server]
DOMAIN = your ip
HTTP_PORT = 3000
PROTOCOL = https
ROOT_URL = https://your ip :3000/
CERT_FILE = /path/server-cert.pem
KEY_FILE = /path/server-key.pem
DISABLE_SSH = false
SSH_PORT = 22
START_SSH_SERVER = false
OFFLINE_MODE = false
结束
(2020.02.16)
补充一(2020.02.16)
- 对于自签证书使用GitHubDesktop无法Clone的问题可以尝试在本地安装git。
- 安装完之后使用管理员运行
cmd
执行以下命令:git config --system http.sslbackend openssl git config --global http.sslVerify false